
$(document).ready(function(){
	/** Fancybox **/
	$("a.fancybox").fancybox();
	
	/** Liens externes **/
	$("a.external-link").click(function(event){
		event.preventDefault();
		window.open($(this).attr("href"));
	});
	
	
	/** Menu déroulant Header **/
	$('ul.menu-hzt > li:not(.sep)').hover(function(){
		$(this).find("a:first").addClass("hover_menu");
		$(this).find("ul").show();
	},function(){
		$(this).find("ul").hide();
		$(this).first("a").css("background","transparent");
		$(this).find("a:first").removeClass("hover_menu");
	});
	
	/** Références sur la Home **/
	/**
	 * @var nbchild -> Nombre de références totales
	 * @var widthContainer -> width de la div qui va contenir tous les logos des références
	 * @var nbSlide -> nombre de slide total (ex : 3 ref = 1 effet slide)
	 */
	var nbChild = $("div.logos_content").children().length;
	var WidthContainer = nbChild * 145;
	var nbSlide = (Math.ceil(nbChild / 2) - 1);
	
	/** On ajoute le width au container des logos **/
	$("div.logos_content").css("width", WidthContainer+"px");
	
	setTimeout("slideRef("+nbSlide+","+nbSlide+")",5000);
	
	/*****************************/
	/** Gros Slider sur la Home **/
	/*****************************/
	/** Gestion des hover sur les liens **/
	$("a.btn_thermographie, a.btn_ingenierie, a.btn_hqe").hover(function(){
		$(this).animate({top:'-70px'}, 200);
	},function(){
		$(this).stop().animate({top:'-60px'}, 200);
	});
	/** Gestion des clics **/
	
	
	$("a.btn_thermographie").mouseover(function(){
		$("div.content_slide").stop().animate({left:"0px"},1000);
	});
	$("a.btn_hqe").mouseover(function(){
		$("div.content_slide").stop().animate({left:"-960px"},1000);
	});
	$("a.btn_ingenierie").mouseover(function(){
		$("div.content_slide").stop().animate({left:"-1920px"},1000);
	});
	
	
	/** Gestion du slider des vignettes dans une page dynamique **/
	var nbVign = $("div.content_vignettes").children().length;
	if(nbVign<=3)
	{
		$("a.slider_left_img,a.slider_right_img").css("visibility","hidden");
	}
	else
	{
		var nbCL = 0;
		var nbCR = (nbVign-3);
		var WidthC = nbVign * 215;
		$("div.content_vignettes").css("width",WidthC+"px");
		$("a.slider_left_img").css("visibility","hidden"); // on cache le slider Left par défaut au chargement de la page
		
		
		$("a.slider_left_img").click(function(e){
			e.preventDefault();
			var LinkCliq = $(this);
			LinkCliq.css("visibility","hidden");
			$("a.slider_right_img").css("visibility","visible");
			if(nbCL > 0)
			{
				$("div.content_vignettes").animate({right: "-=210px"},400,'easeOutBack',function(){
					if(nbCL == 0)
						LinkCliq.css("visibility", "hidden");
					else
						LinkCliq.css("visibility", "visible");
				});
				nbCL--;
				nbCR++;
			}
			
		});
		$("a.slider_right_img").click(function(e){
			e.preventDefault();
			$("a.slider_left_img").css("visibility","visible");
			var LinkCliq = $(this);
			LinkCliq.css("visibility","hidden");
			if(nbCR > 0)
			{
				$("div.content_vignettes").animate({right: "+=210px"},400,'easeOutBack',function(){
					if(nbCR == 0)
						LinkCliq.css("visibility", "hidden");
					else
						LinkCliq.css("visibility", "visible");
				});
				nbCL++;
				nbCR--;
			}
		});
	}
	
});


function slideRef(nbSlide,nbTotal,where)
{
	
	if(nbSlide==0){
		$("div.logos_content").animate({left:"0px"},2000,function(){
			setTimeout("slideRef("+nbTotal+","+nbTotal+")",5000);
		});
		
	}
	else
	{
		nbSlide--;
		$("div.logos_content").animate({left:"-=288px"},2000);
		setTimeout("slideRef("+nbSlide+","+nbTotal+")",5000);
	}
}


