// JavaScript Document
$(document).ready(function() {


	
    /*
	* Affichage du DEBUG
	* On déplace stat par 
	* rapport à l'affichage
	*/		
    $('#stat').css({
        "top": ($(window).height())-20
    });
	
        
    /* 
	* Affichage en plein ecran
	* de la screenstat
	*/
    $("#btn_details").click(function() {
		
        if($('#btn_details').html() == 'details'){
            $('#btn_details').html('Fermer');
        }else{
            $('#stat').fadeOut('slow');
        }
		
        $('#stat').animate({
            top: '0',
            overflow: 'auto'
        }, 500, function() {
            // Animation complete.
            });
        $('#stat').css({
            "position": "absolute"
        });
		
        return false;																	  
    });

	
	
    //fonction pour le module actu de la page d'accueil
    $('.actu_wrapper').css('height', '38px');
    $('.actuItem').css('display', 'none');
    var totalHeight = (140 * $('.actuItem').length)+19;

    $('.actu_wrapper').mouseenter(function() {
        $('.actu_wrapper').stop().animate({
            height: totalHeight
        }, 500).end();
        $('.actu_title_link').addClass('arrow_down').removeClass('arrow_up');
        $('.actuItem').stop().show().end();


        return false;
    });

    $('.actu_wrapper').mouseleave(function() {
        $('.actu_wrapper').stop().animate({
            height: '38px'
        }, 500).end();
        $('.actu_title_link').addClass('arrow_up').removeClass('arrow_down');
        $('.actuItem').stop().hide().end();
        return false;
    }); 
	
	
	
    /**
	 * Gestion du zoom sur image pour les images de la library
	 */
    $('.zoomImage').colorbox();
    $('.zoomImageParag').colorbox();
	
    /*
	* Colorbox sur la pag d'accuil (Affichage d'une vidéo)
	*/
    $('.videoAccueil').colorbox();
		
    /**
	 * Demarage de la validation du formulaire en jquery sur les formulaire de module 
	 */
    $(".frm_module").validationEngine();
	
	
	
	
    /**
	 * Gallery
	 * gestion du rollover pour la legende si elle est presente et sur afficher
	 */
	
    $('.link_thumbs_gal').mouseenter(function() {
        $(this).find('.show_txt_leg').css('display', 'block');
        $(this).find('.show_txt_leg').stop().animate({
            height: '70px',
            opacity:'0.7'
        }, 100, function() {
            // Animation complete.
            }).end();
                
    });
	
    $('.link_thumbs_gal').mouseleave(function() {
		
        $(this).find('.show_txt_leg').stop().animate({
            height: '0',
            opacity:'0'
        }, 100, function() {
            // Animation complete.
            }).end();
        $(this).find('.show_txt_leg').css('display', 'none');														  
    });
	
	
    /**
	 * Colorbox pour les reponses du formulaire de recrutement (soit en reponse a une offre soit en candidature spontanee)
	 */

    $('.respond').colorbox({
        width:800, 
        height:600, 
        iframe:true, 
        scrolling:false
    });
	
    /**
	 * pour l'affichage des information suplementaires sur chaque poste
	 */
    $(".more_info").click(function() {
        $('.job_info').hide('fast');
        $(this).parent().find('.job_info').show('fast');
        $('.more_info_close').remove();
        $('.more_info').css('display', 'block');
        $(this).hide('fast');
        $(this).parent().append('<a href="#" title="Fermer" class="more_info_close">Fermer</a><div class="clear"></div>');
        return false;
    });
	
    $(".more_info_close").live('click', function() {
        $('.job_info').hide('fast');
        $(this).parent().find('.more_info').show('fast');
        $(this).remove();
        return false;
    });
        
        
        
    //gestion du main menu des programmes
        
    $('.ProgBloc').css('display', 'none');
    $('#prog_presentation').css('display', 'block');
        
    $('.BlocLink').click(function() {
            
        var currentTab = $(this).attr('href');
        $('.ProgBloc').css('display', 'none');
        $('#prog_'+currentTab).css('display', 'block');
        $('.BlocLink').removeClass('btn_on');
        $(this).addClass('btn_on');
            
            
        return false;
    });
        
        
    //gestion de popin programme
    $('.ProgPopin').colorbox({
        inline:true, 
        width:"950px", 
        height:"611px"
    });
        
    $('.ProgPopinVid').colorbox({
        inline:true
    });
        
    $('.ProgPopinPlan').colorbox({
        iframe:true, 
        width:"630", 
        height:"450", 
        scrolling:false
    });
    
    $('.ProgPopinBoiteAOutils').colorbox({
        inline:true, 
        width:"630", 
        height:"600", 
        scrolling:false
    });
        
    //lavalamp
    $(".lavaLamp").lavaLamp({
        fx: "easeOutBack", 
        speed: 700
    });
        
    //login box
    $(".loginProSlideMe").click( function() {
        
        if ($("#openCloseIdentifier").is(":hidden")) {
            $("#loginProSlider").animate({ 
                marginTop: "-135px"
            }, 200 );
           
            $("#openCloseIdentifier").show();
        } else {
            $("#loginProSlider").animate({ 
                marginTop: "0px"
            }, 300 );
            
            $("#openCloseIdentifier").hide();
        }
        return false;
    });  
    
    if(document.location.search){
        
            var arraySplit = document.location.search.split('=');
            
            if(arraySplit[0] == '?ep' && arraySplit[1] == 1 || arraySplit[0] == '?ep' && arraySplit[1] == 2 ){
                $("#loginProSlider").css('margin-top', '0px');
                if(arraySplit[1] == 2 ){
                  //$("#loginProSlider").delay(2000).animate({ marginTop: "-135px" }, 200 );
                  $("#loginProSlider").css('margin-top', '-135px');
                }
                
            }else if(arraySplit[0] == '?ev' && arraySplit[1] == 1 ){
                
                //with animation
                //$('html, body').animate({scrollTop:$(document).height()}, 'slow');
                
                //without anim
                $('html, body').scrollTop($(document).height()) ;
                
            }
    }
    
    
    
    
    //**** NIVO SLIDER **** /
    
    $('#slider').nivoSlider(       
    {
        effect: 'fade', // Specify sets like: 'fold,fade,sliceDown'
        slices: 15, // For slice animations
        boxCols: 8, // For box animations
        boxRows: 4, // For box animations
        animSpeed: 300, // Slide transition speed
        pauseTime: 10000, // How long each slide will show
        startSlide: 0, // Set starting Slide (0 index)
        directionNav: true, // Next & Prev navigation
        directionNavHide: true, // Only show on hover
        controlNav: true, // 1,2,3... navigation
        controlNavThumbs: false, // Use thumbnails for Control Nav
        controlNavThumbsFromRel: false, // Use image rel for thumbs
        controlNavThumbsSearch: '.jpg', // Replace this with...
        controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
        keyboardNav: true, // Use left & right arrows
        pauseOnHover: true, // Stop animation while hovering
        manualAdvance: false, // Force manual transitions
        captionOpacity: 0.8, // Universal caption opacity
        prevText: 'Prev', // Prev directionNav text
        nextText: 'Next', // Next directionNav text
        randomStart: false, // Start on a random slide
        beforeChange: function(){}, // Triggers before a slide transition
        afterChange: function(){}, // Triggers after a slide transition
        slideshowEnd: function(){}, // Triggers after all slides have been shown
        lastSlide: function(){}, // Triggers when last slide is shown
        afterLoad: function(){} // Triggers when slider has loaded);
    });
    
    
    //popin video pour l'a homepage
   /*$('.popInVidSlide').colorbox({
        iframe:true,
        width:"630", 
        height:"450", 
        scrolling:false,
        href:$(this).attr('href')
    });*/
    
    $('.popInVidSlide').live('click',  function() {
        $.colorbox({
        inline:true,
        scrolling:false,
        href:$(this).attr('href')
        });
    });
 
});

