// Cr�ation des globales
var slideIndic = 0;
var slideMax;
var sliderSeted;
var clientSeted = 0;
$(document).ready(function() {

	$("body").css("overflow-x", "hidden");
		
	// Mise en place du carrousel
	setUpSlider();

	// Ecouteur sur le redimensionnement de l'ecran
	$(window).resize(setUpSlider);
	
	// Ajout des �couteurs sur le menu
	$("nav div ul li").click(changePageAJAX);
	$("nav a").click(changePageAJAX);
	
	// Ajouts des �couteur sur le footer
	$("footer div ul li").mouseover(decaleFooterOn);
	$("footer div ul li").mouseout(decaleFooterOff);
		
	// Modification des transitions du slider
	jQuery.easing.def = "easeOutQuint";
	
	if($("#slider_nav").length != 0){
		if($("#slider #vimeo_player").length == 0){
			$("#slider").everyTime(4000, nextSlider);
		}
		// Ajout des �couteurs sur les fl�ches
		$(".previous_slide").live("mouseenter", overFlecheGauche);
		$(".previous_slide").live("mouseleave", outFlecheGauche);
		$(".next_slide").live("mouseenter", overFlecheDroite);
		$(".next_slide").live("mouseleave", outFlecheDroite);
		
		// Ajout des �couteurs sur les fl�ches
		$(".previous_slide").live("click", prevSlider);
		$(".next_slide").live("click", nextSlider);
		
		// Ajout des �couteurs sur les bulles
		$("#slider_nav .bulle li").click(clickSlider);
		
		// Ajouts des �couteurs sur le nom du client
		$("#slider_nav .client").live("click", voirClientAJAX);
		$("#slider_nav .projet").live("click", voirProjetAJAX);
	}
	
	if($("#creations").length != 0){

		// Ajout des �couteurs sur le cr�ations
		$("#creations article").mouseenter(changeColorOn);
		$("#creations article").mouseleave(changeColorOff);

		// Ajouts d'un �couteur de clic sur les article
		$("#creations article").click(voirProjetAJAX);
	}
	
	if($("#clients").length != 0){
		// Ajout des �couteurs sur le cr�ations
 	        $("#clients article").mouseenter(changeClientOn);
		$("#clients article").mouseleave(changeClientOff);
		
		// Ajout d'un �couteur de click sur les clients / AJAX
		$("#clients article").live("click",changeClientAJAX);
		
		// Ajout d'un �couteur de click sur le lien pour voir le projet / AJAX
		$(".lien").live("click", voirProjetAJAX);
		$(".projet").live("click",voirProjetAJAX);
		$("#clients article").children("a").children("img").next().animate({ opacity: "0", borderColor: "#fff" }, 0); 
		if($(".single_client").length != 0){
			// Surbrillance du premier client
			
			$(".active_client").children("a").children("img").next().stop(true).animate({ opacity: "1", borderColor: "#c4d0d4" }, 1000);
			$(".active_client").unbind("mouseleave", changeClientOff);
			$(".active_client").unbind("mouseenter", changeClientOn);
			
		}else{
			$("#clients article:first-child").children("a").children("img").next().stop(true).animate({ opacity: "1", borderColor: "#c4d0d4" }, 1000);
			$("#clients article:first-child").unbind("mouseleave", changeClientOff);
			$("#clients article:first-child").unbind("mouseenter", changeClientOn);	
		}
		
	$(".lien").live("click", voirProjetAJAX);
	$(".projet").live("click", voirProjetAJAX);	

	}
	
	if($("#video").length != 0){
		redimVideo();
		$(window).resize(redimVideo);
		
		// On met en noir le background
		$("body").css("background-color", "#000000");
	}
	
	if($("#work").length != 0){
	
		if($("#work div:first-child article div p:first-child").height() < $("#work div:first-child article p").height())
		{
			$("#work div:first-child article div p:first-child").css("height", $("#work div:first-child article p").height());	
		}
	}
	
	if($("#contact").length != 0){
		$("#slider div").css("margin-left", "0");
		$(window).resize(function(){
				//$("#slider div").css("margin-left", "0");
		});
	}
	
	// Gestion de la pagination
	if($(".next").children("a").length == 0)
	{
		$(".next").css("display" , "none");
	}
	if($(".prev").children("a").length == 0)
	{	
		$(".prev").css("display" , "none");
		$(".next").css("margin-right" , "0px");
	}
		
	// Ajout des �couteurs sur les boutons suivante / pr�cedent
	$("#pagination span").live("mouseenter",paginationOver);
	$("#pagination span").live("mouseleave", paginationOut);
	
});

function changePage(){
	location.href = $(this).children("a").attr("href");	
}

function setUpSlider(){
	//alert("toto");
	if($("#map_gmap").length == 0){
		// Positionnement des �l�ments du carrousel
		var taille_ecran = $(window).width();
		var taille_image = $("#slider img").width();
		var difference = (taille_image - taille_ecran) / 2;
		
		//$("#slider div").animate({"margin-left": - (difference + 2600*slideIndic)+"px"}, "fast");
		$("#slider div").css("margin-left", - (difference + 2600*slideIndic));
		sliderSeted = - (difference + 2600*slideIndic);
		
		// Calcul de la taille du carroussel
		slideMax = $("#slider div").children().length;
		$("#slider div").css("width", slideMax * 2620);
		
		if(slideMax < 10){
			// On efface les puces en trop
			$("#slider_nav ul:first-child li:gt("+(slideMax-1)+")").addClass("puce_hide");
			$("#slider_nav ul:first-child li:gt("+(slideMax-1)+")").removeClass("puce_off");
		}else{
			$("#slider_nav ul:first-child li").addClass("puce_hide");		
		}
		
		if(slideMax == 1){
			// stop le timer
			$("#slider").stopTime();
		}else{
			$("#slider").everyTime(4000, nextSlider);
		}
	}else{
		// Positionnement des �l�ments du carrousel
		var taille_ecran = $(window).width();
		var taille_image = $("#slider img").width();
		var difference = (taille_image - taille_ecran) / 2;
		
		$("#slider div").css("margin-left", 0);
		$("#slider div").css("width", taille_ecran);
		$("#map_gmap").attr("width", taille_ecran);
		
	}
}

function prevSlider(){

	// Suppression des �couteur
	$(".previous_slide").die("click", prevSlider);
	$(".next_slide").die("click", nextSlider);
		
	if(slideIndic > 0){
		// R�cup�ration de la position actuelle
		//$("#slider div").animate({"margin-left": "+=2600px"}, "slow");
	
		$("#slider div").animate({"opacity": "0"}, "500", function(){
			$("#slider div").css("margin-left", (sliderSeted - ((slideIndic)*2600))+"px");
			$("#slider div").animate({"opacity": "1"}, "500");
			$(".previous_slide").live("click", prevSlider);
			$(".next_slide").live("click", nextSlider);
		});
			
		$(".puce_on").prev().addClass("puce_on");
		$(".puce_on").removeClass("puce_off");

		$(".puce_on").next().removeClass("puce_on");
		$(".puce_on").next().addClass("puce_off");

		if($("#work").length == 0){
			$("#projets").animate({"margin-top": "+=58px"}, "slow");
		}
		slideIndic--;
	}
	
	if($("#slider #vimeo_player").length == 0){
		// relance le timer
		$("#slider").stopTime();
		$("#slider").everyTime(4000, nextSlider);
	}
}

function nextSlider(){
	
	$(".previous_slide").die("click", prevSlider);
	$(".next_slide").die("click", nextSlider);
		
	if(slideIndic < slideMax-1){
		$("#slider div").animate({"opacity": "0"}, "500", function(){
			//$("#slider div").animate({"margin-left": (sliderSeted - ((slideIndic+1)*2600))+"px"}, "slow");
			$("#slider div").css("margin-left", (sliderSeted - ((slideIndic)*2600))+"px");
			$("#slider div").animate({"opacity": "1"}, "500");
			$(".previous_slide").live("click", prevSlider);
			$(".next_slide").live("click", nextSlider);
		});
		
		$(".puce_on").next().addClass("puce_on");
		$(".puce_on").removeClass("puce_off");

		$(".puce_on").prev().removeClass("puce_on");
		$(".puce_on").prev().addClass("puce_off"); 

		if($("#work").length == 0){
			$("#projets").animate({"margin-top": "-=58px"}, "slow");
		}
		slideIndic++;
	} else {
		//if(slideMax > 4){
			// Calcul de la taille pour retourner au d�but
			//$("#slider div").animate({"margin-left": ""+sliderSeted+"px"}, "10000");
				$("#slider div").animate({"opacity": "0"}, "500", function(){
					$("#slider div").css("margin-left", sliderSeted+"px");
					$("#slider div").animate({"opacity": "1"}, "500");
					$(".previous_slide").live("click", prevSlider);
					$(".next_slide").live("click", nextSlider);
				});
				
				$("#projets").animate({"opacity": "0"}, "500", function(){
					$("#projets").css("margin-top", "20px");
					$("#projets").animate({"opacity": "1"}, "500");
				});
		/*} else{
			$("#slider div").animate({"margin-left": ""+sliderSeted+"px"}, "slow");

			if($("#work").length == 0){
				$("#projets").animate({"margin-top": "20px"}, "slow");
			}
		}*/

		// On d�sactive la derni�re puce
		$(".puce_on").addClass("puce_off");
		$(".puce_on").removeClass("puce_on");
		
		// On remet le compteur � zero
		slideIndic = 0;
		
		// On colore la premi�re puce
		$("#slider_nav ul:first-child li:first-child").addClass("puce_on");
		$("#slider_nav ul:first-child li:first-child").removeClass("puce_off");
	}
	
	if($("#slider #vimeo_player").length == 0){
		// relance le timer
		$("#slider").stopTime();
		$("#slider").everyTime(4000, nextSlider);
	}
}

function clickSlider(){
		puce_clicked = 0;
		// On d�sactive la puce actuellement activ�e
		$(".puce_on").addClass("puce_off");
		$(".puce_on").removeClass("puce_on");
		
		// On active la puce
		$(this).removeClass("puce_off");
		puce_clicked = $(this).attr("class");
		$(this).addClass("puce_on");
		
		if((puce_clicked == 0 && slideIndic == slideMax-1) && slideMax > 4){
			$("#slider div").animate({"opacity": "0"}, "500", function(){
				$("#slider div").css("margin-left", (sliderSeted - (puce_clicked*2600))+"px");
				$("#slider div").animate({"opacity": "1"}, "500");
			});
			
			$("#projets").animate({"opacity": "0"}, "500", function(){
				$("#projets").css("margin-top", (20 - (puce_clicked*58))+"px");
				$("#projets").animate({"opacity": "1"}, "500");
			});
		}else{			
	
			$("#slider div").animate({"opacity": "0"}, "500", function(){
				$("#slider div").animate({"margin-left": ""+(sliderSeted - (puce_clicked*2600))+"px"}, "1000");
				$("#slider div").animate({"opacity": "1"}, "500");
			});
			$("#projets").animate({"margin-top": ""+(20 - (puce_clicked*58))+"px"}, "slow");


		}

		// On change le timer
		slideIndic = puce_clicked;

		// On relance le timer
		$("#slider").stopTime();
		$("#slider").everyTime(4000, nextSlider);
}

function changeColorOn(){
	
		// Modification de la couleur du fond
		$(this).stop(true).animate({ backgroundColor: "#000" }, 1000);
		
		// Modification de la couleur des textes
		$(this).children("h1").stop(true).animate({ color: "#077f95" }, 1000);
		$(this).children("h1").children("span").stop(true).animate({ color: "#077f95" }, 1000);
		$(this).children("p").stop(true).animate({ color: "#FFF" }, 1000);

}

function changeColorOff(){
		
	// Modification de la couleur du fond
	$(this).stop(true).animate({ backgroundColor: "#FFF" }, 1000);
	
	// Modification de la couleur des textes
	$(this).children("h1").stop(true).animate({ color: "#0e2830" }, 1000);
	$(this).children("h1").children("span").stop(true).animate({ color: "#0e2830" }, 1000);

	$(this).children("p").stop(true).animate({ color: "#0e2830" }, 1000);
	
}

function changeClientOn(){
	// Modification de l'opacity
	$(this).children("a").children("img").next().stop(true, true).animate({ opacity: "1", borderColor: "#c4d0d4" }, 1000);

}

function changeClientOff(){
	// Modification de l'opacity
	$(this).children("a").children("img").next().stop(true, true).animate({ opacity: "0", borderColor: "#FFF" }, 1000);
}

function redimVideo(){
	$("#video video").attr("width",  $(window).width()-926);
	$("#video video").css("margin-left",  (($(window).width() - ($(window).width()-926)) /2));	
	
	$("#video div div").css("width",  $(window).width()-928);
	$("#video div div").css("margin-left",  (($(window).width() - ($(window).width()-926)) /2));	
	
}

function decaleFooterOn(){
		$(this).children("a").stop(true).animate({ "margin-left": "5px" }, 500);
}

function decaleFooterOff(){
		$(this).children("a").stop(true).animate({ "margin-left": "0px" }, 500);
}

function paginationOver(){
	if($(this).hasClass("next")){
		$(this).stop(true).animate({ "background-position": "0px 0px" }, 500);
	} else{
		$(this).stop(true).animate({ "background-position": "80px 0px" }, 500);
	}
		
}

function paginationOut(){
if($(this).hasClass("next")){
		$(this).stop(true).animate({ "background-position": "5px 0px" }, 500);
	} else{
		$(this).stop(true).animate({ "background-position": "75px 0px" }, 500);
	}
}

function overFlecheGauche(){
	$(this).attr("src", "http://www.walter-ego.fr/wp-content/themes/we-v3/images/slider_fleche_gauche_on.jpg");
}
function outFlecheGauche(){
	$(this).attr("src", "http://www.walter-ego.fr/wp-content/themes/we-v3/images/slider_fleche_gauche.jpg");
}
function overFlecheDroite(){
	$(this).attr("src", "http://www.walter-ego.fr/wp-content/themes/we-v3/images/slider_fleche_droite_on.jpg");
}
function outFlecheDroite(){
	$(this).attr("src", "http://www.walter-ego.fr/wp-content/themes/we-v3/images/slider_fleche_droite.jpg");
}

///////////////////////////////////////////////// AJAX ///////////////////////////:::
function changeClientAJAX(){
	// Lecture de l'url � charger
	url_to_load = $(this).children("a").attr("href");
	
	// On efface le contenu actuel
	$("#slider div").animate({ opacity: "0"}, 1000);

	// Chargement
	$.ajax({
	  url: url_to_load,
	  success: function(data) {
		var page = $(data);
		$("#slider").html(page.filter("#slider").children("div"));
		$("#slider_nav").html(page.filter("#slider_nav").children("div"));
		$("#slider div").css("opacity", 0);
		
		// On repositionne le slider
		setUpSlider();
		
		// On r�affiche le contenu
		$("#slider div").animate({ opacity: "1"}, 1000);
	  }
	});
	
	// On met en off les autres client
	$("#clients article").children("a").children("img").next().stop(true, true).animate({ opacity: "0", borderColor: "#fff" }, 1000);

	// Ajout des �couteurs sur les icones client
	$("#clients article").mouseenter(changeClientOn);
	$("#clients article").mouseleave(changeClientOff);
	
	// On met en over le client cliqu�
	$(this).children("a").children("img").next().stop(true, true).css({ opacity: "1", borderColor: "#c4d0d4" }, 1);
	
	$(this).unbind("mouseleave", changeClientOff);
	$(this).unbind("mouseenter", changeClientOn);

	return false;
}

function voirProjetAJAX(){
	
	// On change l'onglet
	$("nav .active").removeClass("active");
	$("nav ul li:first-child").addClass("active");
	
	// Si on est sur la page cr�ations
	if($("#creations").length != 0){
		$("#slider div").animate({ opacity: "0"}, 1000);
		$("#creations").animate({ opacity: "0"}, 1000);	
		
		// Lecture de l'url � charger
		url_to_load = $(this).children("p").children("a").attr("href");	
		
		if(url_to_load == null){
			url_to_load = $(this).attr("href");		
		}
		
	}
	
	// On efface les clients actuels si on est sur la page client
	if($("#clients").length != 0){
		$("#clients").animate({ opacity: "0"}, 1000);	
		// Lecture de l'url � charger
		url_to_load = $(this).attr("href");	
	}

	// Si c'est pas internet explorer 9
	if(BrowserDetect.version < 9 && BrowserDetect.browser == "Explorer")
	{
		location.href(url_to_load);	
	}
	// Si c'est pas Firefox 4
	if(BrowserDetect.version == 3.6)
	{
		location.href = url_to_load;	
	}
		
	// Changement de l'URL de la page
	var stateObj = { foo: "bar" };
	history.pushState(stateObj, "page 2", url_to_load);
	
	// On fait la requete AJAX
	$.ajax({
	  url: url_to_load,
	  success: function(data) {
		var page = $(data);
		$("#slider").html(page.filter("#slider").children("div"));
		$("#slider_nav").html(page.filter("#slider_nav").children("div"));

		if($("#creations").length != 0){
				$("#slider div").css("opacity", 0);
				$("#creations").html(page.filter("#work").children("div"));	
				$("#creations").attr('id', 'work');
				$("#slider div").css("opacity", 0);
				$("#slider div").animate({ opacity: "1"}, 1000);
			}
				
		if($("#clients").length != 0){
			$("#clients").html(page.filter("#work").children("div"));	
			$("#clients").attr('id', 'work');
		}
		
		if($("#work div:last-child").hasClass("pagination") == false){
			//$("#work").append(page.filter("#work").children("div:last-child"));
		}
		
		// On repositionne le slider
		slideIndic = 0;
		setUpSlider();
				
		// Bloquage du slider si besoin
		if($("#slider #vimeo_player").length > 0){
			$("#slider").stopTime();
		}else{
			$("#slider").everyTime(4000, nextSlider);
		}
		
		// Affichage du contenu
		$("#work").animate({ opacity: "1"}, 1000);
		
		// Gestion de la pagination
		if($(".next").children("a").length == 0)
		{
			$(".next").css("display" , "none");
		}
		if($(".prev").children("a").length == 0)
		{	
			$(".prev").css("display" , "none");
			$(".next").css("margin-right" , "0px");
		}

	  }
	});
		
	
	// On empeche le lien de fonctionner
	return false;
}

function voirClientAJAX(){
	// On change l'onglet
	$("nav .active").removeClass("active");
	$("nav .client").addClass("active");
	
	// Si on est sur la page cr�ations
	if($("#creations").length != 0){
		$("#slider div").animate({ opacity: "0"}, 1000);
		$("#creations").animate({ opacity: "0"}, 1000);	
		// Lecture de l'url � charger
		url_to_load = $(this).attr("href");
	}

	// Si on est sur la page cr�ations
	if($("#work").length != 0){
		$("#slider div").animate({ opacity: "0"}, 1000);
		$("#work").animate({ opacity: "0"}, 1000);	
		// Lecture de l'url � charger
		url_to_load = $(this).attr("href");
	}
	
	$.ajax({
	  url: url_to_load,
	  success: function(data) {
		var page = $(data);
		$("#slider").html(page.filter("#slider").children("div"));
		$("#slider_nav").html(page.filter("#slider_nav").children("div"));
		
		if($("#creations").length != 0){
				$("#slider div").css("opacity", 0);
				$("#creations").html(page.filter("#clients").children("div"));	
				$("#creations").attr('id', 'clients');
				$("#slider div").css("opacity", 0);
				$("#slider div").animate({ opacity: "1"}, 1000);
		}	
		
		if($("#work").length != 0){
				$("#work").html(page.filter("#clients").children("div"));	
				$("#work").attr('id', 'clients');
				$("#slider div").css("opacity", 0);
				$("#slider div").animate({ opacity: "1"}, 1000);
			}
				
		// On repositionne le slider
		slideIndic = 0;
		setUpSlider();

		// Bloquage du slider si besoin
		if($("#slider #vimeo_player").length > 0){
			$("#slider").stopTime();
		}else{
			$("#slider").everyTime(4000, nextSlider);
		}
		
		$("#clients").animate({ opacity: "1"}, 1000);

			// Ajout des �couteurs sur le cr�ations
			$("#clients article").mouseenter(changeClientOn);
			$("#clients article").mouseleave(changeClientOff);
					
		if(clientSeted == 0){
			// Ajout des �couteurs sur le cr�ations
			$("#clients article").mouseenter(changeClientOn);
			$("#clients article").mouseleave(changeClientOff);
			
			// Ajout d'un �couteur de click sur les clients / AJAX
			$("#clients article").live("click",changeClientAJAX);
			
			// Ajout d'un �couteur de click sur le lien pour voir le projet / AJAX	
			$(".lien").live("click", voirProjetAJAX);
			$(".projet").live("click", voirProjetAJAX);	
			
			clientSeted = 1;
		}
		
		if($(".active_client").length != 0){
			// Surbrillance du premier client
			$(".active_client").children("a").children("img").next().stop(true).animate({ opacity: "1", borderColor: "#c4d0d4" }, 1000);
			$(".active_client").unbind("mouseleave", changeClientOff);
			$(".active_client").unbind("mouseenter", changeClientOn);
		}else{
			$("#clients article:first-child").children("a").children("img").next().stop(true).animate({ opacity: "1", borderColor: "#c4d0d4" }, 1000);
			$("#clients article:first-child").unbind("mouseleave", changeClientOff);
			$("#clients article:first-child").unbind("mouseenter", changeClientOn);	
		}
		
	  }
	});
	
	
	return false;
}

function changePageAJAX(){
	
	// On change le hover sur l'onglet
	$(".active").removeClass("active");
	$(this).addClass("active");
	
	// R�cup�ration de l'url � charger
	url_to_load =  $(this).children("a").attr("href");	

	if(url_to_load == null){
		url_to_load =  $(this).attr("href");
	}

	// On efface le slider
	$("#slider div").animate({ opacity: "0"}, 1000);

	// On efface le contenu des pages
	if($("#work").length != 0){
		$("#work").animate({ opacity: "0"}, 1000);
		old_div = "#work";
	}
	
	if($("#creations").length != 0){
		$("#creations").animate({ opacity: "0"}, 1000);	
		old_div = "#creations";
	}
	
	if($("#clients").length != 0){
		$("#clients").animate({ opacity: "0"}, 1000);
		old_div = "#clients";	
	}
	
	if($("#contact").length != 0){
		$("#contact").animate({ opacity: "0"}, 1000);
		old_div = "#contact";		
	}
	
	if($("#carriere").length != 0){
		$("#carriere").animate({ opacity: "0"}, 1000);
		old_div = "#carriere";			
	}
	
	if($("#agence").length != 0){
		$("#agence").animate({ opacity: "0"}, 1000);
		old_div = "#agence";			
	}
	
	if(url_to_load == "../"){
		ajax_div = "creations";
		$("nav ul li:first-child").addClass("active");
	}
	
	if(url_to_load == "/"){
		ajax_div = "creations";
		$("nav ul li:first-child").addClass("active");
	}
		
	if(url_to_load == "/clients"){
		ajax_div = "clients";
		$("nav .client").addClass("active");
	}
	
	if(url_to_load == "/agence"){
		ajax_div = "agence";
		$("nav .agence").addClass("active");
	}

	if(url_to_load == "/contact"){
		ajax_div = "contact";
		$("nav .contact").addClass("active");
	}
	
	if(url_to_load == "/carriere"){
		ajax_div = "carriere";
		$("nav .carriere").addClass("active");
	}
	
	// Si c'est pas internet explorer 9
	if(BrowserDetect.version < 9 && BrowserDetect.browser == "Explorer")
	{}else{
		// Changement de l'URL de la page
		var stateObj = { foo: "bar" };
		history.pushState(stateObj, "page 2", url_to_load);		
	}

	// Chargement en AJAX
	$.ajax({
	  url: url_to_load,
	  success: function(data) {
		var page = $(data);
		// On rempli le nouveau slider
		$("#slider").html(page.filter("#slider").children("div"));
		
		if($("#slider_nav").length != 0){
			if(page.filter("#slider_agence").length != "0"){
				$("#slider_nav").html(page.filter("#slider_agence").children("div"));
				$("#slider_nav").attr('id', "slider_agence");
			}else{
				$("#slider_nav").html(page.filter("#slider_nav").children("div"));
			}
		}
		else{
			if(page.filter("#slider_agence").length == "0"){
				$("#slider_agence").html(page.filter("#slider_nav").children("div"));
				$("#slider_agence").attr('id', "slider_nav");
			}else{
				$("#slider_agence").html(page.filter("#slider_agence").children("div"));
			}	
		}

		slideIndic = 0;
	
		if(url_to_load != "/contact"){
			setUpSlider();
		}
		else{
			$("#slider").stopTime();
			$("#slider div").css("width", "100%");
			$("#slider div").css("margin-left", "0px");
		}

		$("#slider div").animate({ opacity: "1"}, 1000);	
			
		// On rempli la nouvelle page
		setHtmlPage(page, ajax_div, old_div);
	
		if(ajax_div == "clients"){

		  // Ajout des �couteurs sur le cr�ations
		  $("#clients article").mouseenter(changeClientOn);
		  $("#clients article").mouseleave(changeClientOff);
		  
		  // Ajout d'un �couteur de click sur les clients / AJAX
		  $("#clients article").live("click",changeClientAJAX);
		  
		  // Ajout d'un �couteur de click sur le lien pour voir le projet / AJAX
		  $(".lien").live("click", voirProjetAJAX);
		  $(".projet").live("click", voirProjetAJAX);	
		  
		  if($(".active_client").length != 0){
		    // Surbrillance du premier client
		    $(".active_client").children("a").children("img").next().stop(true).animate({ opacity: "1", borderColor: "#c4d0d4" }, 1000);
		    $(".active_client").unbind("mouseleave", changeClientOff);
		    $(".active_client").unbind("mouseenter", changeClientOn);
		  }else{
		    $("#clients article:first-child").children("a").children("img").next().stop(true).animate({ opacity: "1", borderColor: "#c4d0d4" }, 1000);
		    $("#clients article:first-child").unbind("mouseleave", changeClientOff);
		    $("#clients article:first-child").unbind("mouseenter", changeClientOn);	
		  }	

		
		
		}
		
		if(ajax_div == "creations"){
			// Ajout des �couteurs sur le cr�ations
			$("#creations article").mouseenter(changeColorOn);
			$("#creations article").mouseleave(changeColorOff);
	
			// Ajouts d'un �couteur de clic sur les article
			$("#creations article").click(voirProjetAJAX);	

			if($(".next").children("a").length == 0)
			{
				$(".next").css("display" , "none");
			}
			if($(".prev").children("a").length == 0)
			{	
				$(".prev").css("display" , "none");
				$(".next").css("margin-right" , "0px");
			}	
		}
	  }
	});




	return false;
}


function setHtmlPage(page, div_ajax, div_old){
	
	$(div_old).html(page.filter("#"+div_ajax).children("div"));	
	$(div_old).attr('id', div_ajax);
	$("#"+div_ajax).animate({ opacity: "1"}, 1000);
		
	// Bloquage du slider si besoin
	if($("#slider #vimeo_player").length > 0){
		$("#slider").stopTime();
	}else{
		if($("#slider iframe").length == 0){
			$("#slider").everyTime(4000, nextSlider);
		}
	}
}



// Detection de navigateur
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

