// Fonction Affiche content pages
	function showReferences(){
		$("#references").fadeIn(500,function(){
			var position= ((jQuery("#references").offset().top)-10);
			$('html,body').animate({scrollTop:position},1000,'swing');		
		});		
	}

// Fonction Affiche content pages
	function showContentPage(page,menu,curs){
		$(page).fadeIn(500,function(){
			$(menu).slideDown(200,function(){
				var position = ((jQuery(page).offset().top)-10);
				$('html,body').animate({scrollTop:position},1000,'swing');		
			});	
		});		
	}

// Fonction Affiche content intro
	function showContent(page,menu,curs,home){
		//Désactiver le menu1
		
		/*
		if($("#menu1 a").attr("disabled") == undefined){
			$("#menu1 a").attr('disabled', 'disabled'); //Désactiver le menu1
			$('#content > *').hide();
			$("#hautPage").show();
			$(page).slideDown(1000);
			var position = ((jQuery(page).offset().top)-190);
			$('html,body').animate({scrollTop:position},1000,'swing',function(){	
				if(menu != false){
					$(menu).slideDown(1000,function(){
						if(home==undefined)
							cursor(50,curs);
						else
							cursor(50,curs,home);
					});
				}
				setTimeout("$(\"#menu1 a\").removeAttr('disabled')",1000);//Réactiver le menu
			});
		}
		*/
		
	
			$('#content > *').hide();
			$("#hautPage").show();
			$(page).slideDown(1000);
			var position = ((jQuery(page).offset().top)-190);
			$('html,body').animate({scrollTop:position},1000,'swing',function(){	
				if(menu != false){
					$(menu).slideDown(1000,function(){
						if(home==undefined)
							cursor(50,curs);
						else
							cursor(50,curs,home);
					});
				}
			
			});
	
	}
	
// Fonction Cursor1
	function cursor(position,cursor,home){
		$(cursor).show();	
		position = (home!=undefined) ? home : position;
		$(cursor).animate({marginLeft:position}, 200);
	}	

	
	function showRea(slideshow){
		document.body.style.overflow = "hidden"; 			
		$("#masque1").fadeIn(500,function(){
			$("#ecran").show();
			$("#ecran").animate({marginTop:-274}, 1000);
			
			var content = document.getElementById('visuGrand');
				
			if(slideshow=='lastrea'){
				contentRea1="content/"+ slideshow  +"/rea_1.jpg";
				contentRea2="content/"+ slideshow  +"/rea_2.jpg";
				contentRea3="content/"+ slideshow  +"/rea_3.png";
				content.innerHTML = "<img src=" + contentRea1 + " /><img src=" + contentRea2 + " /><img src=" + contentRea3 + " />";	
				$("#nav").empty();
				$("#visuGrand").cycle({
					fx:     'fade', 
					speed:   1000, 
					timeout: 3000, 
					next:   '#visuGrand', 
					pager:  '#nav',
					pause:   1  
				});	
			}
		});
		return false;
	}


	function showReaDefault(image){
		document.body.style.overflow = "hidden"; 
		$("#ecran").show();
		$("#visuGrand").hide();
		
		$("#masque1").fadeIn(500,function(){
			$("#ecran").animate({marginTop:-274}, 1000,function(){
				var content = document.getElementById('visuGrand');
				contentRea1="content/references/"+image ;
				content.innerHTML = "<img src=" + contentRea1 + " />";
				$("#visuGrand").fadeIn(500);
							
			});			
		});
		return false;
	}
	


$(document).ready(function(){

	$(".texte2ColBloc.shop").each(function(){
		$(this).find("p").after("<p><a href=\""+$(this).find("h2 a").attr("href")+"\">En savoir plus</a></p>");
	});
	
	$("#news").cycle({ 
		fx:     'fade', 
		speed:   1000, 
		timeout: 3000, 
		next:   '#news', 
		pager:  '#nav2',
		pause:   1  
	});	
	
	// Initialisation de la page
	$(".blocRefDescription").hide();
	$("#content").css({display:'block'});
	$("#ecran").hide();
	$("#content > *").hide();
	$("#cursor1").hide();
	$("#menu2").hide();
	$("#contenu").hide();
	$('html,body').animate({scrollTop:jQuery('body').offset().top},1000,'swing');
	$("#hautPage").hide();
	$('#footer').show();
	
	$("ul li h1").click(function(){
		document.location.href="http://www.pixigo.ch/";
	});
	
	$(".texte2ColBlocRef").hover(
		function(){
			$(this).find(".blocRefDescription").slideToggle(100);
		},
		function(){
				$(this).find(".blocRefDescription").slideToggle(100);
		}
	);
		
	
	// Action boutons
		$("#menu1 > #bt1").mouseover(function(){
			cursor(420,"#cursor1");
		});
			
		$("#menu1 > #bt2").mouseover(function(){
			cursor(130,"#cursor1");
		});	
			
		$("#menu1 > #bt3").mouseover(function(){
			cursor(720,"#cursor1");
		});
					
		$("#menu1").mouseout(function(){
			//$("#cursor1").hide();
		});
		
		$("#hautPage").click(function(){
			$('html,body').animate({scrollTop:jQuery('body').offset().top},1000,'swing');
		});	
		
		
	/*ACTIONS MENU GLOBALE*/	
		
	$("#menuGlobale #bt1").toggle(
		function(){
			$("#menuGlobaleContenu").animate({width:900},500,function(){
				$("#menuGlobaleContenu2").fadeIn(200);
				});
			$("#masque1").fadeIn(500);
			document.body.style.overflow = "hidden"; 
		},function(){
			$("#menuGlobaleContenu2").fadeOut(100,function(){
				$("#menuGlobaleContenu").animate({width:0},200);
			});
			$("#masque1").fadeOut(500,function(){document.body.style.overflowY = "auto";});
		}
	);	
	
	$("#masque1").click(function(){
		$("#menuGlobaleContenu2").fadeOut(100,function(){
			$("#menuGlobaleContenu").animate({width:0},200);
		});
		$("#ecran").fadeOut();
		$("#ecran").animate({marginTop:-1200}, 1000);
		$("#masque1").fadeOut(500,function(){document.body.style.overflowY = "auto";});
	});			
			
	$("#menu2  li  a").mouseover(function(){
		var left = "";
		switch($(this).parent("li").index()){
			case 0:
				left = 50;
				break;
			case 1:
				left = 190;
				break;
			case 2:
				left = 340;
				break;
			case 3:
				left = 480;
				break;
			case 4:
				left = 630;
				break;
			case 5:
				left = 770;
				break;				
		}
		cursor(left,"#cursor2");
	});	
		
	$("#menu3  li  a").mouseover(function(){
		var left = "";
		switch($(this).parent("li").index()){
			case 0:
				left = 50;
				break;
			case 1:
				left = 190;
				break;
			
			case 2:
				left = 340;
				break;
			case 3:
				left = 480;
				break;
			case 4:
				left = 630;
				break;
			case 5:
				left = 770;
				break;				
		}
		cursor(left,"#cursor3");
	});	
	
	$("#menu4  li  a").mouseover(function(){
		var left = "";
		switch($(this).parent("li").index()){
			case 0:
				left = 50;
				break;
			case 1:
				left = 190;
				break;
			case 2:
				left = 340;
				break;
			case 3:
				left = 480;
				break;
			case 4:
				left = 630;
				break;
			case 5:
				left = 770;
				break;				
		}
		cursor(left,"#cursor4");
	});	

	
	if($("#contentStrat").size()>0){
		showContentPage("#contentStrat","#menu2","#cursor2");
		cursor(420,'#cursor1');
	}
	else if($("#contentWeb").size()>0){
		showContentPage("#contentWeb","#menu3","#cursor2");
		cursor(130,'#cursor1');
	}
	else if($("#references").size()>0){
		showReferences();
		cursor(130,'#cursor1');
	}
	else
		cursor(130,'#cursor1');			
		
	$("#menu1 > .bloc2 > a[class]").each(function(){
		($(this).attr("href",$(this).attr("href")+"?tab="+$(this).attr("class")));
	});
	
	/* Creation des liens tab si nous sommes dans autre que la home */
		var location = document.location.href;
		location = location.split("tab=");
		if(location.length>1){
			switch(location[1]){
				case "vague":
					showContent('#introWeb','#menu3','#cursor1',130);
					break;
				case "pointe":
					showContent('#introStrat','#menu2','#cursor1',420);
					break;
				case "prestations":
					showContent('#pageIntroBesoins','#menu4','#cursor1',720);
					break;
				default:
					break;
			}
		}
	
	/* Ajout du onclick si autre que ie7 */
		if(!$.browser.msie && $.browser.version != "7.0"){
			$("#realisation img").wrap("<a href=\"\" onclick=\"return showRea('lastrea');\"></a>");
			$(".texte2ColBlocRef").each(function(){
				$(this).find("img").wrap("<a href=\"\" onclick=\"return showReaDefault('"+$(this).find("img").attr("class")+".jpg');\"></a>");
				$(this).find("p").wrap("<a href=\"http://"+$(this).find("p").text()+"\" title=\"Consulter notre référence\"></a>");
			});
		}
		else{
			$("#realisation img").wrap("<a></a>");
			$(".texte2ColBlocRef").each(function(){
				$(this).find("img").wrap("<a></a>");
				$(this).find("p").wrap("<a href=\"http://"+$(this).find("p").text()+"\" title=\"Consulter notre référence\"></a>");
			});
		
		}
		
	/*Ajout mailto*/
		//$("#coordonnee ul li:eq(1) img, p.email img").wrap("<a href=\"mailto:info@pixigo.ch\"></a>");
		$("#email").wrap("<a href=\"mailto:info@pixigo.ch\"></a>");
		

});


