$(window).load(function(){ 
	/*(document).pngFix();*/ 
	diapoTimeLine();
	imgLoad();
	imgClick();

	
		var accordionMenu = jQuery('#News');
		if(typeof(accordionMenu.accordion) == 'function'){
			accordionMenu.accordion({ 
				active		: false,
				alwaysOpen	: false,
				autoheight  : false,
				
			});
		}
			
		var NewsHeight = $("#News").outerHeight();
		 $("#News").css('height',NewsHeight);
		 
		if ($('#ScrollingContainer')!=undefined && typeof($('#ScrollingContainer').jScrollPane) == 'function') 
		{
			$('#content2 .metierDesc').jScrollPane({showArrows:true,  arrowSize:15, scrollbarWidth:14});
					$('.chocolaterieTxt').jScrollPane({showArrows:true,  arrowSize:15, scrollbarWidth:14});
			$('#SideChocos').jScrollPane({showArrows:true,  arrowSize:15, scrollbarWidth:14});
			$('.NewInspiration').jScrollPane({showArrows:true,  arrowSize:15, scrollbarWidth:14});
		}
}); 

/* Fonction de chargement d'images - bloc de droite */
var imgLoad = function() {
	var initHeight = eval($("#blocVignettes ul li:first-child a img").outerHeight()) + eval($("#SliderPhotos").outerHeight());
	var grandHeight = imgHeight() + eval($("#SliderPhotos").outerHeight());	
	$("#blocVignettes").css('height',initHeight);
	var nbr = $("#blocVignettes ul li").length;
	if ($("#SliderPhotos")!=undefined && typeof($("#SliderPhotos").hover) == 'function') {
		$("#SliderPhotos").hover( function() {	
			if (($("#blocVignettes").height()==initHeight) && ($(this).children("img").attr('src')=='../images/photos_up.jpg')) {
				if($.browser.msie) {grandHeight = grandHeight + (4*nbr);}
				$("#blocVignettes").animate({'height':grandHeight+"px"},1000,function() {
					$("#SliderPhotos").children("img").attr('src','../images/photos_down.jpg');
				});
				
			}
			else if(($(this).children("img").attr('src')=='../images/photos_down.jpg') && ($("#blocVignettes").height()==grandHeight)) {
				$("#blocVignettes").animate({'height':initHeight+"px"},1000,function() {
					$("#SliderPhotos").children("img").attr('src','../images/photos_up.jpg');
				});
				
			}	
		
	});
	}
}


var imgClick = function() {
	$("#blocVignettes ul li a").each( function () {
	$(this).bind("click", function() {						   
		$("#mainImg").attr('src',$(this).attr("href"));
		return false;
		});
	});	
}

var imgHeight = function() {
	var imgHeight = 0;
	$("#blocVignettes ul li a img").each(function() {imgHeight = imgHeight + eval($(this).height());});	
	return imgHeight;
}

var changerVisuel = function(imgSrc) {
	$('#googleMapsPlan').fadeOut('def',function() {
		$('#googleMapsPlan').attr('src',imgSrc);
		$('#googleMapsPlan').fadeIn();
	});
}

var changerVille = function(ville) {
	if($('.planBg')) {
		$('.planBg').fadeOut();
		$('.planBg').remove();
		$('.ScrollingContainer').css('display','block');
		$('.ScrollingContainer').load('villes/' + ville, function() {
			$('.ScrollingContainer').jScrollPane({showArrows:true,  arrowSize:15, scrollbarWidth:14});
			$('.ScrollingContainer').fadeIn('def');
		}); }
	
	else {
		$('#dynLayer').fadeOut('def', function() {
			$('.ScrollingContainer').empty();								   
			$('.ScrollingContainer').load('villes/' + ville, reinitialiseScrollPane);
			$('#dynLayer').fadeIn('def');											   
		});	
		
	}
	
	
	


	
}

/* Diapo timeline - saga  favrger */
var diapoTimeLine = function() {
	
	$(".timeLineLinks li a").hover (function() {
		var ImgSrc = $(this).children("img").attr('src');	
		ImgSrc = ImgSrc.replace("_off","_on");
		$(this).children("img").attr('src',ImgSrc);
	});
	
	$(".timeLineLinks li a").mouseout(function() {
		if($(this).parent('li').attr('class')!='on') {
			var ImgSrc = $(this).children("img").attr('src');	
			ImgSrc = ImgSrc.replace("_on","_off");
			$(this).children("img").attr('src',ImgSrc);	
		}
	});
		
$(".timeLineLinks li a").click(function() {
	var index = parseInt($(".timeLineLinks li.on").attr('id'));	
	var pas = parseInt($(this).parent('li').attr('id')) - index;
	if (pas > 0) {
		var maxi = -3000;
		var ssLeft = $(".sagaSliderContainer").css('left');
		ssLeft = ssLeft.substring(0, ssLeft.length-2);
		var cLeft = ssLeft - (745*pas);
		$(".sagaSliderContainer").animate({"left":cLeft+"px"},1000);	
		//var ssLeftRedArrow = $("#redArrow").css('left');
		//ssLeftRedArrow = parseInt(ssLeftRedArrow.substring(0, ssLeftRedArrow.length-2));
		//ssLeftRedArrow = ssLeftRedArrow + (96*pas);
		//$("#redArrow").animate({"left":ssLeftRedArrow+"px"},1000);	
		var imgSrc = $(".timeLineLinks li.on a img").attr('src');		
		var newSrc = imgSrc.replace('_on','_off');
		$(".timeLineLinks li.on a img").attr('src',newSrc);	
		var index = parseInt($(".timeLineLinks li.on").attr('id'));	
		index = index + pas;
		imgSrc = $(".timeLineLinks li:nth-child("+index+") a img").attr('src');		
		newSrc = imgSrc.replace('_off','_on');	
		$(".timeLineLinks li:nth-child("+index+") a img").attr('src',newSrc);
		$(".timeLineLinks li.on").removeClass('on');
		$(".timeLineLinks li:nth-child("+index+")").addClass('on');
	}
	else {
		pas = parseInt(Math.abs(pas));
		var maxi = -3000;
		var ssLeft = $(".sagaSliderContainer").css('left');
		ssLeft = ssLeft.substring(0, ssLeft.length-2);
		var cLeft = parseInt(ssLeft) + (745*pas);
		$(".sagaSliderContainer").animate({"left":cLeft+"px"},1000);	
		//var ssLeftRedArrow = $("#redArrow").css('left');
		//ssLeftRedArrow = parseInt(ssLeftRedArrow.substring(0, ssLeftRedArrow.length-2));
		//ssLeftRedArrow = ssLeftRedArrow - (96*pas);
		//$("#redArrow").animate({"left":ssLeftRedArrow+"px"},1000);	
		var imgSrc = $(".timeLineLinks li.on a img").attr('src');		
		var newSrc = imgSrc.replace('_on','_off');
		$(".timeLineLinks li.on a img").attr('src',newSrc);	
		var index = parseInt($(".timeLineLinks li.on").attr('id'));	
		index = index - pas;
		imgSrc = $(".timeLineLinks li:nth-child("+index+") a img").attr('src');		
		newSrc = imgSrc.replace('_off','_on');	
		$(".timeLineLinks li:nth-child("+index+") a img").attr('src',newSrc);
		$(".timeLineLinks li.on").removeClass('on');
		$(".timeLineLinks li:nth-child("+index+")").addClass('on');
	}	
});

$("#arrowRight").click(function() {
	var maxi = ($(".sagaSliderContainer").children("div.sagaSlider").length - 2) * (-1) * 754;
	var ssLeft = $(".sagaSliderContainer").css('left');
	ssLeft = ssLeft.substring(0, ssLeft.length-2);
	var cLeft = ssLeft - 745;
	if((ssLeft > maxi) && ((cLeft+745) == ssLeft))	{
		$(".sagaSliderContainer").animate({"left":cLeft+"px"},1000);	
		//var ssLeftRedArrow = $("#redArrow").css('left');
		//ssLeftRedArrow = parseInt(ssLeftRedArrow.substring(0, ssLeftRedArrow.length-2));
		//ssLeftRedArrow = ssLeftRedArrow + 96;
		//$("#redArrow").animate({"left":ssLeftRedArrow+"px"},1000);	
		var imgSrc = $(".timeLineLinks li.on a img").attr('src');		
		var newSrc = imgSrc.replace('_on','_off');
		$(".timeLineLinks li.on a img").attr('src',newSrc);	
		var index = parseInt($(".timeLineLinks li.on").attr('id'));	
		index = index + 1;
		imgSrc = $(".timeLineLinks li:nth-child("+index+") a img").attr('src');		
		newSrc = imgSrc.replace('_off','_on');	
		$(".timeLineLinks li:nth-child("+index+") a img").attr('src',newSrc);
		$(".timeLineLinks li.on").removeClass('on');
		$(".timeLineLinks li:nth-child("+index+")").addClass('on');
		}
});

$("#arrowLeft").click(function() {
	var maxi = 0;
	var ssLeft = $(".sagaSliderContainer").css('left');
	ssLeft = ssLeft.substring(0, ssLeft.length-2);
	var cLeft = parseInt(ssLeft) + 745;
	if((ssLeft < maxi) && ((cLeft-745) == ssLeft))	{
	$(".sagaSliderContainer").animate({"left":cLeft+"px"},1000);	
	//var ssLeftRedArrow = $("#redArrow").css('left');
	//ssLeftRedArrow = parseInt(ssLeftRedArrow.substring(0, ssLeftRedArrow.length-2));
	//ssLeftRedArrow = ssLeftRedArrow - 96;
	//$("#redArrow").animate({"left":ssLeftRedArrow+"px"},1000);	
	var imgSrc = $(".timeLineLinks li.on a img").attr('src');		
	var newSrc = imgSrc.replace('_on','_off');
	$(".timeLineLinks li.on a img").attr('src',newSrc);	
	var index = parseInt($(".timeLineLinks li.on").attr('id'));	
	index = index - 1;
	imgSrc = $(".timeLineLinks li:nth-child("+index+") a img").attr('src');		
	newSrc = imgSrc.replace('_off','_on');	
	$(".timeLineLinks li:nth-child("+index+") a img").attr('src',newSrc);
	$(".timeLineLinks li.on").removeClass('on');
	$(".timeLineLinks li:nth-child("+index+")").addClass('on');
	}
});
}

//validation formulaire de contact - FR
var validateFormFr = function() {
	
	function trim (myString) {return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');}
	
	var sujet = trim($('select[name="object"]').val());
	var verif = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var errorMsg ="Merci de compl\351ter les champs du formulaire.";
	
	if($('input[name="firstName"]').val()=="") {errorMsg = errorMsg + "\n\t- Nom.";}
	if($('input[name="lastName"]').val()=="") {errorMsg = errorMsg + "\n\t- Pr\351nom.";}
	if($('input[name="email"]').val()=="" || verif.exec($('input[name="email"]').val()) == null) {errorMsg = errorMsg + "\n\t- Adresse \351lectronique.";}
	if(sujet=="S\351lectionner un sujet") {errorMsg = errorMsg + "\n\t- Informations sur.";}
	if($('textarea[name="message"]').val()=="") {errorMsg = errorMsg + "\n\t- Votre message.";}
	if(errorMsg!="Merci de compl\351ter les champs du formulaire.") {alert(errorMsg);}
	else {alert('Merci pour votre message.');$('form.contactForm').submit();}
}

//validation formulaire de contact - EN
var validateFormEn = function() {
	
	function trim (myString) {return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');}
	
	var sujet = trim($('select[name="object"]').val());
	var verif = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var errorMsg ="Please fill in all the fields on the form.";
	
	if($('input[name="firstName"]').val()=="") 			{errorMsg = errorMsg + "\n\t- Surname.";}
	if($('input[name="lastName"]').val()=="") 			{errorMsg = errorMsg + "\n\t- First name.";}
	if($('input[name="email"]').val()=="" || verif.exec($('input[name="email"]').val()) == null) 
														{errorMsg = errorMsg + "\n\t- E-mail address.";}
	if(sujet=="Select a subject") 						{errorMsg = errorMsg + "\n\t- Information about.";}
	if($('textarea[name="message"]').val()=="") 		{errorMsg = errorMsg + "\n\t- Your message.";}
	if(errorMsg!="Please fill in all the fields on the form.") {alert(errorMsg);}
	else {alert('Thank you for your message.');$('form.contactForm').submit();}
}

//validation formulaire de contact - DE
var validateFormDe = function() {
	
	function trim (myString) {return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');}
	
	var sujet = trim($('select[name="object"]').val());
	var verif = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var errorMsg ="Bitte alle Felder dieses Formulars ausf\u00FCllen.";
	
	if($('input[name="firstName"]').val()=="") {errorMsg = errorMsg + "\n\t- Name.";}
	if($('input[name="lastName"]').val()=="")  {errorMsg = errorMsg + "\n\t- Vorname.";}
	if($('input[name="email"]').val()=="" || verif.exec($('input[name="email"]').val()) == null) {errorMsg = errorMsg + "\n\t- E-Mail-Adresse.";}
	if(sujet=="Thema ausw\u00E4hlen") {errorMsg = errorMsg + "\n\t- Informationen \u00FCber.";}
	if($('textarea[name="message"]').val()=="") {errorMsg = errorMsg + "\n\t- Ihre Nachricht.";}
	if(errorMsg!="Bitte alle Felder dieses Formulars ausf\u00FCllen.") {alert(errorMsg);}
	else {alert('Merci pour votre message.');$('form.contactForm').submit();}
}

// centrage de popup
function popupcentree(page,largeur,hauteur) 
{     
var top=(screen.height-hauteur)/2;     
var left=(screen.width-largeur)/2;     
var Configuration="'toolbar=no, menubar=no, location=no, directories=no, status=no, resizeable=no, scrollbars=yes" ; 
window.open(page,'',"top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+Configuration); 
} 


//validation formulaire de newsletter - FR
var validateFormNewsletterFr = function() {
	
	function trim (myString) {return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');}	
	var sujet = trim($('select[name="civilite"]').val());
	var verif = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var errorMsg ="Afin de recevoir notre Newsletter, merci de compl\351ter les champs du formulaire.";
	var toTest = errorMsg;
	if(sujet=="S\351lectionner votre civilit\351") {errorMsg = errorMsg + "\n\t- Merci de choisir votre civilit\351.";}
	if($('input[name="nom"]').val()=="") {errorMsg = errorMsg + "\n\t- Merci de saisir votre nom.";}
	if($('input[name="prenom"]').val()=="") {errorMsg = errorMsg + "\n\t- Merci de saisir votre pr\351nom.";}
	if($('input[name="email"]').val()=="" || verif.exec($('input[name="email"]').val()) == null) {errorMsg = errorMsg + "\n\t- Merci de saisir votre adresse \351lectronique.";}	
	if($('input[name="receivnewsletter"]:checked').length!=1) {errorMsg = errorMsg + "\n\t- Afin de recevoir notre Newsletter, merci de cocher la case d'abonnement.";}
	if(errorMsg!=toTest) {alert(errorMsg);}
	else {alert('Merci pour votre message.');$('form.newsletterForm').submit();}
}

//validation formulaire de newsletter - EN
var validateFormNewsletterEn = function() {
	function trim (myString) {return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');}	
	var sujet = trim($('select[name="civilite"]').val());
	var verif = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var errorMsg ="Please fill in all the fields on the form.";
	var toTest = errorMsg;
	if(sujet=="Selection your title") 			   {errorMsg = errorMsg + "\n\t- Title.";}
	if($('input[name="nom"]').val()=="")           {errorMsg = errorMsg + "\n\t- Surname.";}
	if($('input[name="prenom"]').val()=="")        {errorMsg = errorMsg + "\n\t- First name.";}
	if($('input[name="email"]').val()=="" || verif.exec($('input[name="email"]').val()) == null) 
												   {errorMsg = errorMsg + "\n\t- E-mail address.";}	
	if($('input[name="receivnewsletter"]:checked').length!=1) 
												   {errorMsg = errorMsg + "\n\t- Subscribe checkbox.";}
	if(errorMsg!=toTest) {alert(errorMsg);}
	else {alert('Thank you for subscribing.');$('form.newsletterForm').submit();}
}

//validation formulaire de newsletter - DE
var validateFormNewsletterDe = function() {
	function trim (myString) {return myString.replace(/^\s+/g,'').replace(/\s+$/g,'');}	
	var sujet = trim($('select[name="civilite"]').val());
	var verif = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	var errorMsg ="Bitte alle Felder dieses Formulars ausf\u00FCllen.";
	var toTest = errorMsg;
	if(sujet=="Selection your title") 			   {errorMsg = errorMsg + "\n\t- Anrede.";}
	if($('input[name="nom"]').val()=="")           {errorMsg = errorMsg + "\n\t- Name.";}
	if($('input[name="prenom"]').val()=="")        {errorMsg = errorMsg + "\n\t- Vorname.";}
	if($('input[name="email"]').val()=="" || verif.exec($('input[name="email"]').val()) == null) 
												   {errorMsg = errorMsg + "\n\t- E-Mail-Adresse.";}	
	if($('input[name="receivnewsletter"]:checked').length!=1) 
												   {errorMsg = errorMsg + "\n\t- Subscribe checkbox.";}
	if(errorMsg!=toTest) {alert(errorMsg);}
	else {alert('Thank you for subscribing.');$('form.newsletterForm').submit();}
}


