/*--FUNCTIONS.JS--*/
/*Développements spécifique au site*/

/*-----------  GREYBOX  -----------*/
//Config générale récurente
var greyBoxDefaultConfig = {
	/*--Valeurs ci-dessous requises--*/
	top: 50,						//=> Décalage en PX du haut du document
	duration: 0.6,					//=> Durée totale de l'affichage
	opacity: 0.8					//=> Opacité du fond Overlay
};
//Variable définissant la durée de la transition
var greyBoxEffectDuration = Math.round((greyBoxDefaultConfig.duration*1000)/2);
//Fonctions GREYBOX
function greyBoxShow(b,c,d,a){if(!$("#overlay").length){$("body").append('<div id="overlay" onclick="greyBoxHide();"></div>');if(jQuery.browser.msie&&jQuery.browser.version=="6.0"){$(window).scroll(function(){$("#overlay").css("top",$(window).scrollTop()+"px")})}}if(!$("#greyBox").length){$("body").append('<div id="greyBox"><div class="content" id="greyBoxContent"></div><div onclick="greyBoxHide();" class="close"></div></div>')}if(typeof(a)!="undefined"){if(typeof(a.duration)=="undefined"){greyBoxEffectDuration=Math.round((greyBoxDefaultConfig.duration*1000)/2)}else{greyBoxEffectDuration=Math.round((a.duration*1000)/2)}if(typeof(a.top)=="undefined"){a.top=greyBoxDefaultConfig.top}if(typeof(a.opacity)=="undefined"){a.opacity=greyBoxDefaultConfig.opacity}if(typeof(a.height)=="undefined"&&typeof(greyBoxDefaultConfig.height)!="undefined"){a.height=greyBoxDefaultConfig.height}if(typeof(a.closeText)=="undefined"&&typeof(greyBoxDefaultConfig.closeText)!="undefined"){a.closeText=greyBoxDefaultConfig.closeText}if(typeof(a.title)=="undefined"&&typeof(greyBoxDefaultConfig.title)!="undefined"){a.title='<h1 class="title greybox">'+greyBoxDefaultConfig.title+"</h1>"}else{if(typeof(a.title)=="undefined"&&typeof(greyBoxDefaultConfig.title)=="undefined"){a.title=""}else{a.title='<h1 class="title greybox">'+a.title+"</h1>"}}if(typeof(a.error)=="undefined"&&typeof(greyBoxDefaultConfig.error)!="undefined"){a.error=greyBoxDefaultConfig.error}if(typeof(a.background)=="undefined"&&typeof(greyBoxDefaultConfig.background)!="undefined"){a.background=greyBoxDefaultConfig.background}if(typeof(a.style)=="undefined"&&typeof(greyBoxDefaultConfig.style)!="undefined"){a.style=greyBoxDefaultConfig.style}if(typeof(a.className)=="undefined"&&typeof(greyBoxDefaultConfig.className)!="undefined"){a.className=greyBoxDefaultConfig.className}if(typeof(a.loading)=="undefined"&&typeof(greyBoxDefaultConfig.loading)!="undefined"){a.loading=greyBoxDefaultConfig.loading}if(typeof(a.data)=="undefined"&&typeof(greyBoxDefaultConfig.data)!="undefined"){a.data=greyBoxDefaultConfig.data}if(typeof(a.customFunction)=="undefined"&&typeof(greyBoxDefaultConfig.customFunction)!="undefined"){a.customFunction=greyBoxDefaultConfig.customFunction}}else{greyBoxEffectDuration=Math.round((greyBoxDefaultConfig.duration*1000)/2);a=greyBoxDefaultConfig;a.title=""}$("#overlay").removeAttr("style");$("#greyBox .close").html("");$("#greyBox").removeAttr("class");$("#greyBoxContent").removeAttr("style");if(typeof(a.height)!="undefined"&&d!="iframe"&&d!="youtube"&&d!="dailymotion"){$("#greyBoxContent").css("overflow","auto").css("height",a.height+"px")}if(typeof(a.closeText)!="undefined"){$("#greyBox .close").html(a.closeText)}if(typeof(a.background)!="undefined"){$("#overlay").css("background",a.background)}if(typeof(a.style)!="undefined"){$("#greyBoxContent").attr("style",a.style)}if(typeof(a.className)!="undefined"){$("#greyBox").addClass(a.className)}if(typeof(a.onComplete)=="undefined"){a.onComplete=function(){}}$("#greyBoxContent").html('<div id="greyBoxLoader"></div>');if(typeof(a.loading)!="undefined"){$("#greyBoxLoader").html(a.loading)}$("#greyBox").css("width",c+"px").css("left","-"+(Math.ceil(c/2))+"px");if(typeof(a.customFunction)=="undefined"){switch(d){case"html":var e=function(){$("#greyBoxContent").html(a.title+b)};greyBoxDisplay(e,a.opacity,a.top,a.onComplete);break;case"get":var e=function(){$.ajax({type:"GET",url:b,success:function(f){$("#greyBoxContent").html(a.title+f)},error:function(){$("#greyBoxContent").html(a.title+a.error)}})};greyBoxDisplay(e,a.opacity,a.top,a.onComplete);break;case"post":var e=function(){$.ajax({type:"POST",url:b,data:a.data,success:function(f){$("#greyBoxContent").html(a.title+f)},error:function(){$("#greyBoxContent").html(a.title+a.error)}})};greyBoxDisplay(e,a.opacity,a.top,a.onComplete);break;case"iframe":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("#greyBoxContent").html(a.title+'<iframe src="'+b+'" border="0" frameborder="0" width="100%" height="'+f+'" allowTransparency="true"></iframe>')};greyBoxDisplay(e,a.opacity,a.top,a.onComplete);break;case"youtube":var e=function(){var f="";if(typeof(a.height)!="undefined"){f=' height="'+a.height+'"'}$("#greyBoxContent").html(a.title+'<iframe class="youtube" title="YouTube video player" style="width:100%;display:block;"'+f+' src="http://www.youtube.com/embed/'+b+'?wmode=transparent" frameborder="0" allowfullscreen></iframe>')};greyBoxDisplay(e,a.opacity,a.top,a.onComplete);break;case"dailymotion":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("#greyBoxContent").html(a.title+'<object width="100%" height="'+f+'" style="display:block;"><param name="movie" value="http://www.dailymotion.com/swf/video/'+b+'"></param><param name="allowFullScreen" value="true"></param><param name="allowScriptAccess" value="always"></param><embed type="application/x-shockwave-flash" src="http://www.dailymotion.com/swf/video/'+b+'" width="100%" height="'+f+'" allowfullscreen="true" allowscriptaccess="always"></embed></object>')};greyBoxDisplay(e,a.opacity,a.top,a.onComplete);break;case"image":var e=function(){$("#greyBoxContent").html($("#greyBoxContent").html()+'<img src="'+b+'" alt="" style="display:none;" id="greyBoxImage" />');$("#greyBoxImage").load(function(){$("#greyBoxImage").fadeOut(0);$("#greyBoxLoader").remove();$("#greyBoxContent").prepend(a.title);$("#greyBoxImage").fadeIn("medium");$("#greyBoxContent").css("width",Math.floor($("#greyBoxImage").outerWidth())+"px");$("#greyBox").css("width","auto").css("left","-"+(Math.ceil($("#greyBoxContent").outerWidth()/2))+"px")})};greyBoxDisplay(e,a.opacity,a.top,a.onComplete);break;default:break}}else{greyBoxDisplay(a.customFunction,a.opacity,a.top,a.onComplete)}return false}function greyBoxDisplay(d,b,c,a){if($("#greyBox").attr("status")!="running"){$("#greyBox").attr("status","running");$("#greyBox").css("top",($(window).scrollTop()+c)+"px");if(jQuery.browser.msie&&jQuery.browser.version=="6.0"){$("#overlay").css("position","absolute").css("height",$(window).height()+"px").css("top",$(window).scrollTop()+"px");$("#greyBoxLoader").css("height","200px")}$("object:not(.keep-visible), embed").css("visibility","hidden");if(jQuery.browser.msie&&jQuery.browser.version=="6.0"){$("select").css("visibility","hidden")}$("#overlay").fadeTo(greyBoxEffectDuration,b,function(){$("#greyBox").fadeIn(greyBoxEffectDuration,function(){$("#greyBox").attr("status","done");d();a()})})}}function greyBoxHide(){if($("#greyBox").attr("status")!="running"){$("#greyBox").attr("status","running");$("#greyBox").fadeOut(greyBoxEffectDuration,function(){$("#greyBox").hide();$("#overlay").fadeOut(greyBoxEffectDuration,function(){$("object:not(.keep-visible), embed").css("visibility","visible");if(jQuery.browser.msie&&jQuery.browser.version=="6.0"){$("select").css("visibility","visible")}$("#greyBox").attr("status","done");$("#greyBox").remove()})})}};

/*-----------  UNIVERSAL CAROUSEL  -----------*/
function makeCarousel(d,c){if(typeof(c.direction)!="undefined"&&c.direction=="vertical"){var h=0;$("#"+d+" > li").each(function(){$(this).attr("offset",h);h+=$(this).outerHeight(true)})}else{c.direction="horizontal";var e=0;$("#"+d+" > li").each(function(){$(this).attr("offset",e);e+=$(this).outerWidth(true)})}var b="";var j="";if(typeof(c.viewport)!="undefined"){if(typeof(c.viewport.width)!="undefined"){b="width:"+c.viewport.width+"px;"}if(typeof(c.viewport.height)!="undefined"){j="height:"+c.viewport.height+"px;"}}if(typeof(c.range)!="undefined"){$("#"+d).attr("range",c.range)}else{c.range=1;$("#"+d).attr("range",1)}if(typeof(c.mode)=="undefined"){c.mode="fade"}var g="left";if(typeof($("#"+d).css("float"))!="undefined"){g=$("#"+d).css("float")}switch(c.mode){case"fade":$("#"+d+" > li").hide();$("#"+d+" > li:eq(0)").show();var f=parseInt($("#"+d).css("padding-top"));var i=parseInt($("#"+d).css("padding-left"));var l=parseInt($("#"+d).css("padding-top"));var k=parseInt($("#"+d).css("padding-left"));$("#"+d).css("width",(c.viewport.width-i-l)+"px").css("height",(c.viewport.height-f-k)+"px");$("#"+d).css("height",$("#"+d+" > li:eq(0)").outerHeight()+"px");$("#"+d+" > li").css("position","absolute").css("left",i+"px").css("top",f+"px");break;case"slide":if(typeof(c.direction)!="undefined"&&c.direction=="vertical"){$("#"+d).css("float","left").css("position","relative").css("left","0").css("height",h+"px");$("#"+d+" > li").css("float","left")}else{$("#"+d).css("float","left").css("position","relative").css("left","0").css("width",e+"px");$("#"+d+" > li").css("float","left")}break}if($("#"+d+" > li").length>1){if(typeof(c.pagination)!="undefined"&&c.pagination){$("#"+d).after(makeCarouselPagination("full",c.range,c.mode,d,c.lang,c.duration,c.direction))}else{$("#"+d).after(makeCarouselPagination("simple",c.range,c.mode,d,c.lang,c.duration,c.direction))}$("#"+d).wrap('<div class="carouselWindow" style="float:'+g+";position:relative;overflow:hidden;"+b+j+'" />');$("#"+d).attr("length",$("#"+d+" > li").length).attr("current",0).attr("status","ok");$("#"+d).attr("mode","manual");if(typeof(c.autoDefil)!="undefined"){$("#"+d).attr("mode","auto");var a=c.autoDefil*1000;setTimeout(function(){carouselRecursiveNext(c.mode,d,c.duration,a,c.direction)},a)}}}function makeCarouselPagination(k,f,g,c,b,e,i){var h="";if($("#"+c+" > li").length<=f){h=" off"}var j='<ul id="'+c+'Pagination" class="pagination'+h+'">';j+='<li class="prev" onclick="carouselPrev(\''+g+"', '"+c+"', '"+e+"', '"+i+"');\">"+b.prev+"</li>";if(k=="full"){var d=0;var a=0;$("#"+c+" > li").each(function(){if((d%f)==0){var l="";if(d==0){l=' class="current"'}j+="<li"+l+" onclick=\"carouselAccess('"+g+"', '"+c+"', "+e+", "+(a*f)+", '"+i+"');\">"+(a+1)+"</li>";a++}d++})}j+='<li class="next" onclick="carouselNext(\''+g+"', '"+c+"', '"+e+"', false, '"+i+"');\">"+b.next+"</li>";j+="</ul>";return j}function carouselRecursiveNext(d,a,c,e,b){if($("#"+a).attr("mode")=="auto"){carouselNext(d,a,c,true,b);setTimeout(function(){carouselRecursiveNext(d,a,c,e,b)},e)}}function carouselAccess(e,a,d,f,c){$("#"+a).attr("mode","manual");if($("#"+a).attr("status")!="running"){$("#"+a).attr("status","running");var b=$("#"+a).attr("current");$("#"+a).attr("current",f);carouselReachItem(b,f,a,e,d,c)}}function carouselPrev(f,b,c,i){$("#"+b).attr("mode","manual");if($("#"+b).attr("status")!="running"){$("#"+b).attr("status","running");var h=parseInt($("#"+b).attr("current"));var a=parseInt($("#"+b).attr("length"));var e=parseInt($("#"+b).attr("range"));var g=h;h-=e;if(h<0&&g==0){h=$("#"+b+" > li").length-e}else{if(h<0&&g>0){h=0}}$("#"+b).attr("current",h);var d=h;carouselReachItem(g,d,b,f,c,i)}}function carouselNext(g,b,c,h,j){if(!h){$("#"+b).attr("mode","manual")}if($("#"+b).attr("status")!="running"){$("#"+b).attr("status","running");var i=parseInt($("#"+b).attr("current"));var a=parseInt($("#"+b).attr("length"));var e=parseInt($("#"+b).attr("range"));var f=i;i+=e;if(i>($("#"+b+" > li").length-e)&&i<$("#"+b+" > li").length){i=$("#"+b+" > li").length-e}if(i>=$("#"+b+" > li").length){i=0}$("#"+b).attr("current",i);var d=i;carouselReachItem(f,d,b,g,c,j);if(i>($("#"+b+" > li").length-e)){$("#"+b).attr("current",($("#"+b+" > li").length))}}}function carouselReachItem(c,b,a,g,e,d){if($("#"+a+"Pagination li:not(.prev, .next):eq("+b+")").length){$("#"+a+"Pagination li:not(.prev, .next)").removeClass("current");$("#"+a+"Pagination li:not(.prev, .next):eq("+b+")").addClass("current")}switch(g){case"fade":e=Math.floor((e*1000)/2);$("#"+a+" > li:eq("+c+")").fadeOut(e,function(){$("#"+a).css("height",$("#"+a+" > li:eq("+b+")").outerHeight()+"px");$("#"+a+" > li:eq("+b+")").fadeIn(e,function(){$("#"+a).attr("status","ok")})});break;case"slide":e=e*1000;var f=$("#"+a+" > li:eq("+b+")").attr("offset");if(d=="vertical"){$("#"+a).animate({top:"-"+f+"px"},e,function(){$("#"+a).attr("status","ok")})}else{$("#"+a).animate({left:"-"+f+"px"},e,function(){$("#"+a).attr("status","ok")})}break}};

/*-----------  CHECK FORM  -----------*/
/*--Fieldfocus Fielblur--*/
function fieldFocus(a){if(a.value==a.defaultValue){a.value=""}}
function fieldBlur(a){if(a.value==""){a.value=a.defaultValue}};
/*--Function check Form--*/
function checkForm(a,d){if(typeof(d.offset)=="undefined"){d.offset={left:0,top:10}}else{if(typeof(d.offset.left)=="undefined"){d.offset.left=0}if(typeof(d.offset.top)=="undefined"){d.offset.top=10}}if(typeof($(a).attr("status"))=="undefined"&&$(a).attr("status")!="initialized"){$(a).attr("status","initialized");var b=new Array();if(typeof(d.required)!="undefined"){for(var g=0;g<d.required.elements.length;g++){if(jQuery.inArray(d.required.elements[g],b)==-1){b.push(d.required.elements[g])}}}if(typeof(d.compare)!="undefined"){for(var g=0;g<d.compare.elements.length;g++){if(jQuery.inArray(d.compare.elements[g][1],b)==-1){b.push(d.compare.elements[g][1])}}}if(typeof(d.radio)!="undefined"){for(var g=0;g<d.radio.elements.length;g++){if(jQuery.inArray(d.radio.elements[g],b)==-1){b.push(d.radio.elements[g])}}}if(typeof(d.email)!="undefined"){for(var g=0;g<d.email.elements.length;g++){if(jQuery.inArray(d.email.elements[g],b)==-1){b.push(d.email.elements[g])}}}if(typeof(d.date)!="undefined"){for(var g=0;g<d.date.elements.length;g++){if(jQuery.inArray(d.date.elements[g],b)==-1){b.push(d.date.elements[g])}}}if(typeof(d.custom)!="undefined"){for(var g=0;g<d.custom.length;g++){if(jQuery.inArray(d.custom[g].element,b)==-1){b.push(d.custom[g].element)}}}for(var g=0;g<b.length;g++){var j=$("#"+b[g]);checkFormFeedback(j,{id:g,offset:d.offset,message:"",position:j.offset()})}}var l=0;if(typeof(d.email)!="undefined"){for(var g=0;g<d.email.elements.length;g++){var j=$("#"+d.email.elements[g]);updateFeedback(j,d.offset,d.email.message);var c=/^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/;if(c.exec(j.val())==null){$(j).parent().addClass("error");l++}}}if(typeof(d.date)!="undefined"){for(var g=0;g<d.date.elements.length;g++){var j=$("#"+d.date.elements[g]);updateFeedback(j,d.offset,d.date.message);var c=/^[0-9]{2}[/]{1}[0-9]{2}[/]{1}[0-9]{4}$/;if(c.exec(j.val())==null){$(j).parent().addClass("error");l++}}}if(typeof(d.compare)!="undefined"){for(var g=0;g<d.compare.elements.length;g++){var h=$("#"+d.compare.elements[g][0]);var f=$("#"+d.compare.elements[g][1]);updateFeedback(f,d.offset.top,d.compare.message);if(f.val()!=h.val()){$(f).addClass("error");l++}}}if(typeof(d.radio)!="undefined"){for(var g=0;g<d.radio.elements.length;g++){var j=$("#"+d.radio.elements[g]);var e=0;$('input[name="'+(j.attr("name"))+'"]').each(function(){if($(this).is(":checked")){e++}});if(!e){j.parent().addClass("error");updateFeedback(j,d.offset,d.radio.message);l++}}}if(typeof(d.custom)!="undefined"){for(var g=0;g<d.custom.length;g++){var j=$("#"+d.custom[g].element);updateFeedback(j,d.offset,d.custom[g].message);if(d.custom[g].reg.exec(j.val())==null){$(j).parent().addClass("error");l++}}}if(typeof(d.required)!="undefined"){for(var g=0;g<d.required.elements.length;g++){var j=$("#"+d.required.elements[g]);var k=document.getElementById(d.required.elements[g]).defaultValue;if(typeof(d.defaultValue)!="undefined"&&!d.defaultValue){k=""}if(j.is("input")){if(j.attr("type")=="text"||j.attr("type")=="password"){if(j.val()==""||j.val()==k){j.parent().addClass("error");updateFeedback(j,d.offset,d.required.message);l++}}else{if(j.attr("type")=="checkbox"||j.attr("type")=="radio"){if(!j.is(":checked")){j.parent().addClass("error");updateFeedback(j,d.offset,d.required.message);l++}}}}else{if(j.is("select")){if($("option:selected",j).val()==""){j.parent().addClass("error");updateFeedback(j,d.offset,d.required.message);l++}}else{if(j.is("textarea")){if(j.val()==""||j.val()==k){j.parent().addClass("error");updateFeedback(j,d.offset,d.required.message);l++}}}}}}if(!l){if(typeof(d.onSuccess)!="undefined"){d.onSuccess();return false}else{return true}}else{if(typeof(d.onError)!="undefined"){d.onError()}return false}}function updateFeedback(e,f,b){$("#"+e.attr("related_to")+" .message").html(b);if(e.attr("type")!="checkbox"&&e.attr("type")!="radio"){if($("#"+e.attr("related_to")).outerWidth()>e.outerWidth()){var a=e.outerWidth()-parseFloat($("#"+e.attr("related_to")).css("paddingLeft"))-parseFloat($("#"+e.attr("related_to")).css("paddingRight"));$("#"+e.attr("related_to")).css("width",a+"px")}else{$("#"+e.attr("related_to")).css("width","auto")}}var d=Math.round(e.offset().top)-$("#"+e.attr("related_to")).outerHeight()+f.top;$("#"+e.attr("related_to")).css("top",d+"px");var c=Math.round(e.offset().left)+f.left;$("#"+e.attr("related_to")).css("left",c+"px")}function checkFormFeedback(d,a){d.attr("related_to","checkFormFeedback_"+a.id);$('#checkFormFeedback_'+a.id).remove();$("body").append('<div class="errorFeedback" id="checkFormFeedback_'+a.id+'" style="display:none;"><span class="message">'+a.message+'</span><span class="appendice"></span></div>');$("#checkFormFeedback_"+a.id).attr("form_element",d.attr("id"));var c=Math.round(a.position.top)-$("#checkFormFeedback_"+a.id).outerHeight()+a.offset.top;$("#checkFormFeedback_"+a.id).css("top",c+"px");var b=Math.round(a.position.left)+a.offset.left;$("#checkFormFeedback_"+a.id).css("left",b+"px");if(d.is("input")&&(d.attr("type")=="checkbox"||d.attr("type")=="radio")){d.parent().find("label").hover(function(){if($(this).parent().hasClass("error")){$("#checkFormFeedback_"+a.id).fadeIn("fast")}},function(){if($(this).parent().hasClass("error")){$("#checkFormFeedback_"+a.id).fadeOut("fast")}})}else{d.focus(function(){if($(this).parent().hasClass("error")){$("#checkFormFeedback_"+a.id).fadeIn("fast")}});d.blur(function(){if($(this).parent().hasClass("error")){$("#checkFormFeedback_"+a.id).fadeOut("fast")}})}if(d.is("input")&&d.attr("type")=="radio"){$('input[name="'+d.attr("name")+'"]').change(function(){if($(this).parent().hasClass("error")){$("#checkFormFeedback_"+a.id).fadeOut("fast",function(){var e=$(this).attr("form_element");$("#"+e).parent().removeClass("error")})}})}else{d.change(function(){if($(this).parent().hasClass("error")){$("#checkFormFeedback_"+a.id).fadeOut("fast",function(){var e=$(this).attr("form_element");$("#"+e).parent().removeClass("error")})}})}};

/*-----------  BUILD SITE  -----------*/
//INITIALISATION DU SITE
function buildSite(){
	
	if(typeof(mobile) == 'undefined'){
		
		/** LOADING **/
		$('body').attr('status', 'loading');
		
		//ON MASQUE LE SCROLL DU BODY
		$('body').css('overflow', 'hidden');
		
		/** FORMATTAGE HTML **/
		//On vie de contenu de la page
		$('#viewportContainer').html('');
		//Calage du VIEWPORT
		$('#viewport').css({
			'margin-top': site.header,
			'height': (site.viewport.height - site.header)
		});
		//Calage de la largeur du VIEWPORT CONTAINER
		$('#viewportContainer').css('width', (site.viewport.width * site.nav.length)+'px');
		//Calage générique
		$(window).resize(function(){
			adjustSite();
		});
		
		/** FONCTION A EXECUTER APRES CHARGEMENT GREYBOX **/
		var complete = function(){
		
			/** GREYBOX TIPS **/
			//On empèche la fermeture par le fond
			$('#overlay').attr('onclick', '');
			
			/** COMPTEUR GLOBAL **/
			var ctp = 0;
			
			/** LECTURE DE L'ARBO **/
			//On parcours la NAV
			$.each(site.nav, function(i, nav){
				
				//NIVEAU #1
				setTimeout(function(){
					ctp++;
					$.ajax(nav.url, {
						async: false,
						type: 'POST',
						data: {mode:'ajax'},
						complete: function(data){
						
							/** CONSTRUCTION DU NIVEAU #1 **/
							buildLevel1((i+1), nav, data.responseText);
							/** PROGRESSION **/
							displayProgress(ctp);
							
						}
					});
					
					/** NIVEAU #2 **/
					if(typeof(nav.children) != 'undefined'){
						$.each(nav.children, function(j, nav){
							setTimeout(function(){
								ctp++;
								$.ajax(nav.url, {
									async: false,
									type: 'POST',
									data: {mode:'ajax'},
									complete: function(data){
										if($('#'+site.nav[i].id).length){
										
											/** CONSTRUCTION DU NIVEAU #2 **/
											buildLevel2(i, j, nav, data.responseText);
											
											/** PROGRESSION **/
											displayProgress(ctp);
											
										}
									}
								});
							}, 1);
						});
					}
				}, 1);
				
			});
		}
		
		/** AFFICHAGE GREYBOX **/
		//Affichage d'une greybox de chargement
		if(jQuery.browser.msie && parseInt(jQuery.browser.version) < 10){
			//Repositionnement de la Greybox de chargement en hauteur
			var posTop = Math.floor(site.viewport.height / 2) - 75;
			greyBoxShow(site.loadingIE, 300, 'html', {top:posTop, onComplete:complete, className:'loading'});
		}
		else{
			//Repositionnement de la Greybox de chargement en hauteur
			var posTop = Math.floor(site.viewport.height / 2) - 200;
			greyBoxShow(site.loading, 253, 'html', {top:posTop, onComplete:complete, className:'loadingCanvas', opacity:0.9, background:'#1d1d1b'});
		}
	
	}
}

//DISPLAY PROGRESS
function displayProgress(ctp){
	//Calcul du pourcentage
	var percent = (Math.ceil((ctp*100)/site.pages));
	if(jQuery.browser.msie && parseInt(jQuery.browser.version) < 10){
		//Pourcentage
		$('#num').html(percent+'%');
		//Barre
		$('#progress').css({'width':percent+'%'});
	}
	else{
		displayCanvasProgress(percent);
	}
	
	//Si on est sur le dernier chargement
	if(ctp == site.pages){
		
		//On mémorise le padding initial des lignes
		$('#lines > li').each(function(){
			$(this).attr('init', parseInt($(this).css('padding-right')));
		});
	
		//Si on est directement sur la HOMEPAGE, on anime les LIGNES AGENCE
		if(site.currentPage == 'home'){
			setTimeout(function(){
				linesAnim();
			}, 600);
		}
		var ctp = 0;
		//On regarde si on a une ancre dans l'URL
		var anchor = '';
		var split = document.location.href.split('#');
		if(typeof(split[1]) != 'undefined' && split[1] != '') anchor = ", '#"+split[1]+"'";
		//On teste si un lien avec ONCLICK est égal à DISPLAY SECTION ou si commence par DISPLAY CONTENT
		$('#mainMenu > ul > li > a[onclick*="return displaySection(this, \''+site.currentPage+'\');"], .level_1 .subMenu > li > a[onclick*="return displayContent(this, \''+site.currentPage+'\''+anchor+'"]').each(function(){
			if(!ctp){
				//On "déroute" la page en cours pour "autoriser" l'animation
				site.currentPage = 'home';
				//On déclenche le click
				var target = $(this);
				setTimeout(function(){
					$(target).click();
				}, 600);
			}
			ctp++;
		});

		if(jQuery.browser.msie && parseInt(jQuery.browser.version) < 10){
			//On masque la GREYBOX
			greyBoxHide();
			//On spécifie que le chargement est FINI
			$('body').attr('status', 'ok');
		}
		else{
			//Animation de fin de chargement
			$('#progressCanvasP').animate({
				opacity:0,
				left:'50px'
			}, {
				duration:400
			});
			$('#progressCanvasLogo').animate({
				opacity:0,
				left:'-50px'
			}, {
				duration:400,
				complete: function(){
					//On masque la GREYBOX
					greyBoxHide();
					//On spécifie que le chargement est FINI
					$('body').attr('status', 'ok');
				}
			});
		}
	}
}

//DISPLAY PROGRESS CANVAS
function displayCanvasProgress(percentage){
		
	var canvas = document.getElementById('progressCanvas');
	if(canvas.getContext){
			
		ctx = canvas.getContext('2d');
	
		ctx.clearRect(0, 0, canvas.width, canvas.height);
		
		var start = 0 + Math.PI*1.5;
		var end = (2*Math.PI*percentage)/100 + Math.PI*1.5;
		
		var offset = 1.033;
		
		var posCenter = canvas.width / 2;
		var widthArc_1 = canvas.width / 2 - 50;
		var widthArc_2 = (canvas.width / 2) - 60;
		var widthArc_3 = (canvas.width / 2) - 70;
		
		ctx.beginPath();
		ctx.arc(posCenter,posCenter,widthArc_1,start,end,false);
		ctx.arc(posCenter,posCenter,widthArc_2,end*offset,start*offset,true);
		ctx.arc(posCenter,posCenter,widthArc_2,start*offset,end*offset,false);
		ctx.arc(posCenter,posCenter,widthArc_3,end,start,true);
		ctx.lineTo(posCenter+6, posCenter - widthArc_2);
		ctx.lineTo(posCenter, posCenter - widthArc_1);
		ctx.fillStyle = "white";
		ctx.fill();
		
		var data = percentage+'%';
		if(percentage == 100) data = 'Terminé';
		
		ctx.font = "14px Arial";  
		ctx.fillStyle = "white";
		ctx.textAlign = "center";
		ctx.fillText(data, posCenter, posCenter+5);
		
		ctx.shadowOffsetX = 0;
		ctx.shadowOffsetY = 0;
		ctx.shadowBlur = 10;
		ctx.shadowColor = "rgba(0, 0, 0, 0.5)";
	}
	
}

//CONSTRUCTION DU NIVEAU #1
function buildLevel1(i, nav, data){
	data = '<div class="section" style="width:'+site.viewport.width+'px;">'+data+'</div>';
	$('#viewportContainer').append(data);
	$('#'+nav.id).css({
		'width': site.viewport.width+'px',
		'height': (site.viewport.height - site.header)+'px'
	});
	$('#'+nav.id).attr({
		'x': (site.viewport.width * (i-1)),
		'y': 0
	});
}

//CONSTRUCTION DU NIVEAU #2
function buildLevel2(i, j, nav, data){
	$('#'+site.nav[i].id).parent().append(data);
	$('#'+nav.id).css({
		'height': (site.viewport.height - site.header)
	});
	$('#'+nav.id).scrollTop(0);
	$('#'+nav.id).attr({
		'x': $('#'+site.nav[i].id).attr('x'),
		'y': ((site.viewport.height * (j+1)) - (site.header * (j+1)))
	});
}

//GESTION DU REDIMENSIONNEMENT DU SITE
function adjustSite(){
	
	//On re-spécifie les variables du VIEWPORT
	site.viewport.height = $(window).height();
	site.viewport.width = $(window).width();
	
	//Calage des lignes d'animation
	if(site.viewport.width > 975){
		var offset = Math.floor((site.viewport.width - 975)/2) - 8;
		$('#lines').css({
			'right': '-'+offset+'px',
			'width': (960 + offset)+'px'
		});
		$('#lines > li').each(function(){
			$(this).css('padding-right', (parseInt($(this).attr('init')) + offset)+'px');
		});
	}
	
	//Calage du VIEWPORT
	$('#viewport, #level3').css({
		'width': site.viewport.width+'px',
		'height': (site.viewport.height - site.header)+'px'
	});
	$('#viewportContainer').css({
		'width': (site.viewport.width * site.nav.length)+'px'
	});
	$('#viewportContainer > .section').css({
		'width': site.viewport.width+'px'
	});
	//Calage des NIVEAU #1 & #2
	var ctp = 0;
	$('#viewportContainer > .section').each(function(){
		var x = site.viewport.width * ctp;
		$(this).find('> .level_1, > .level_2').each(function(){
			$(this).css({
				'width': site.viewport.width+'px',
				'height': (site.viewport.height - site.header)+'px'
			});
			$(this).attr('x', x);
		});
		var j = 1;
		$(this).find('> .level_2').each(function(){
			$(this).attr('y', ((site.viewport.height * j) - (site.header * j)));
			j++;
		});
		ctp++;
	});
	//On replace VIEWPORT CONTAINER
	if($('#'+site.currentPage).length){
		$('#viewportContainer').css({
			'left': '-'+$('#'+site.currentPage).attr('x')+'px',
			'top': '-'+$('#'+site.currentPage).attr('y')+'px'
		});
	}
	
}

//AFFICHAGE D'UN NIVEAU #1
function displaySection(trigger, target){
	if(typeof(mobile) == 'undefined'){
		//Si on est pas en cours d'animation et que le DIV ciblé existe et que ce n'est pas la page en cours
		if($('body').attr('status') != 'running' && $('#'+target).length && target != site.currentPage){
			
			//On supprime l'ombre au HEADER
			$('#header').removeClass('shadow');
			
			borderAnim(trigger, target);
			
			/** ANIMATION DE LA PAGE **/
			pageSlide(trigger, target);
		}
		return false;
	}
	else{
		return true;
	}
}

//ANIMATION DES LIGNES
function linesAnim(){
	if($('#lines:not(.loaded) > li').length){
	
		//VIDEO POPUP
		if(typeof(pushVideo) != 'undefined'){
			setTimeout(function(){
				greyBoxShow(pushVideo, 930, 'get', {duration:0.3, className:'video', background:'#000000'});
			}, 2000);
		}
	
		var ctp = 0;
		var offset = Math.floor((site.viewport.width - 975)/2) - 8;
		$('#lines').css({
			'right': '-'+offset+'px',
			'width': (960 + offset)+'px'
		});
		$('#lines > li').each(function(){
			$(this).css('padding-right', (parseInt($(this).css('padding-right')) + offset)+'px');
		});
		$('#lines:not(.loaded) > li').each(function(){
			$(this).css({
				'right': '-'+($(this).outerWidth() + 1)+'px',
				'display': 'block'
			});
			$(this).delay(750*ctp).animate({
				'right': '0px'
			}, {
				duration: 500,
				easing: 'swing',
				complete: function(){
					if(ctp == $('#lines > li').length){
						$('#lines').addClass('loaded');
					}
				}
			});
			ctp++;
		});
	}
}

//ANIMATION DE LA BORDURE
function borderAnim(trigger, target){
	/** ANIMATION DE LA BORDURE **/
	//Si on apelle la HOME
	if(target == 'home'){
		//Retrait de la classe ACTIVE
		$('#mainMenu > ul > li').removeClass('active');
		//Si BORDER existe
		if($('#border').length){
			//On la masque tout à gauche
			$('#border').animate({
				width: 0,
				left: 0,
				opacity: 0
			}, {
				duration: (site.transition * 1000),
				//Display NONE
				complete: function(){
					$('#border').hide();
				}
			});
		}
	}
	//Sinon
	else{
		//Ajout de la classe ACTIVE
		$(trigger).parent().siblings().removeClass('active');
		$(trigger).parent().addClass('active');
		//Si BORDER n'éxiste pas
		if(!$('#border').length) $('#header > .container').append('<div id="border" />');
		//Si BORDER n'est pas visible
		if($('#border').css('display') != 'block'){
			//Opacité 0 et display BLOCK
			$('#border').css({
				'opacity':0,
				'display':'block'
			});
		}
		//On cale BORDER sur le LI concerné
		$('#border').animate({
			width: $(trigger).parent().outerWidth()+'px',
			left: $(trigger).parent().position().left+'px',
			opacity: 1
		}, {
			duration: (site.transition * 1000)
		});
	}
}

//AFFICHAGE D'UN NIVEAU #2
function displayContent(trigger, target, anchor){
	if(typeof(mobile) == 'undefined'){
		//Si on est pas en cours d'animation et que le DIV ciblé existe et que ce n'est pas la page en cours
		if($('body').attr('status') != 'running' && $('#'+target).length && target != site.currentPage){
			
			//On ajoute l'ombre au HEADER
			$('#header').addClass('shadow');
			
			/** ANIMATION DE LA PAGE **/
			pageSlide(trigger, target);
			reachContent(trigger, anchor);
			
		}
		return false;
	}
	else{
		return true;
	}
}

//PAGE SLIDE
function pageSlide(trigger, target){

	if($('#'+target).hasClass('level_2')){
		var targetName = $('#'+target).prevAll('.level_1').attr('id')
		var menuLi = $('#mainMenu > ul > li > a[onclick*="return displaySection(this, \''+targetName+'\');"]')[0];
		borderAnim(menuLi, targetName);
	}

	var slide = function(){
		//On spécifie le commencement de l'anim
		$('body').attr('status', 'running');
		
		//On indique la page en cours
		site.currentPage = target;
	
		//On récupère les coordonnées du BLOC
		var x = $('#'+target).attr('x');
		var y = $('#'+target).attr('y');
		//On anime l'affichage
		$('#viewportContainer').animate({
			left: '-'+x+'px',
			top: '-'+y+'px'
		},{
			duration: (site.transition * 1000),
			complete: function(){
				if(target == 'home'){
					//On anime les LIGNES AGENCE
					linesAnim();
				}
				//On spécifie que l'animation est finie
				$('body').attr('status', 'ok');
			}
		});
	}
	
	if($('#level3').length && $('#level3').css('display') != 'none'){
		closeLevel3(slide);
	}
	else{
		slide();
	}
}

//REACH CONTENT
function reachContent(trigger, anchor){
	if(typeof(mobile) == 'undefined'){
		if(typeof(anchor) == 'undefined') anchor = $(trigger).attr('href');
		//Si un DIV correspondant existe
		if($(anchor).length){
			$(anchor).parents('.section').find('> .level_2').animate({
				scrollTop: $(anchor).position().top
			},{
				duration: (site.transition * 1000)
			});
		}
		return false;
	}
	else{
		return true;
	}
}

//CHARGEMENT D'UNE PAGE DE NIVEAU #3
function loadPage(url){
	if(typeof(mobile) == 'undefined'){
		$('body').attr('status', 'running');
		//NIVEAU #3
		//Si aucun NIVEAU #3 n'a encore été apellé
		if(!$('#level3').length){
			$('body').append('<div id="level3"><div id="level3Close" onclick="return closeLevel3();"></div></div>');
		}
		$('#level3').addClass('loading');
		
		//On calcule l'origine de l'expansion du block
		var origin = originMath();
		//On dimensionne le NIVEAU#3 en fonction
		$('#level3').css({
			'width': origin.width+'px',
			'height': origin.height+'px',
			'top': origin.top+'px',
			'left': origin.left+'px',
			'opacity': '0',
			'display':'block'
		});
		//On l'anime jusqu'aux dimensions maximales possibles
		$('#level3').animate({
			'width': site.viewport.width+'px',
			'height': (site.viewport.height - site.header)+'px',
			'top': site.header+'px',
			'left': '0px',
			'opacity': '1'
		}, {
			duration: (site.transition * 1000),
			complete: function(){
				$.ajax(url, {
					async: true,
					type: 'POST',
					data: {mode:'ajax'},
					complete: function(data){
						$('#level3').prepend(data.responseText);
						$('#level3').removeClass('loading');
					}
				});
				$('body').attr('status', 'ok');
			}
		});
		return false;
	}
	else{
		return true;
	}
}

//CALCUL DE LA POSITION D'ORIGINE DE L'ANIMATION
function originMath(){
	var output = new Object();
	//On dimentionne à 17% du VIEWPORT
	output.width = Math.round(site.viewport.width * 0.17);
	output.height = Math.round(site.viewport.height * 0.17);
	output.top = Math.floor((site.viewport.height - site.header) / 2) + site.header - Math.floor(output.height / 2);
	output.left = Math.floor(site.viewport.width / 2) - Math.ceil(output.width / 2);
	
	return output;
}

//FERMER LE NIVEAU #3
function closeLevel3(callback){
	$('body').attr('status', 'running');
	//On calcule l'origine de l'expansion du block
	var origin = originMath();
	//On dimensionne le NIVEAU#3 en fonction
	$('#level3').animate({
		'width': origin.width+'px',
		'height': origin.height+'px',
		'top': origin.top+'px',
		'left': origin.left+'px',
		'opacity': '0'
	}, {
		duration: (site.transition * 1000),
		complete: function(){
			$('#level3').remove();
			if(typeof(callback) == 'function') callback();
			$('body').attr('status', 'ok');
		}
	});
	return false;
}

//PORTFOLIO LISTE
function makePortfolioList(){
	if(typeof(mobile) == 'undefined'){
		$('#portfolioList').css({
			'height': '38px',
			'overflow': 'hidden'
		});
		var cumulateWidth = 0;
		$('#portfolioList > ul > li').each(function(){
			$(this).attr('offset', cumulateWidth);
			cumulateWidth += $(this).outerWidth();
		});
		if(cumulateWidth > slideWidth){
			$('#portfolioList').append('<div class="shadow left" /><div class="shadow right" />');
		}
		else{
			$('#portfolioList .shadow').remove();
		}
		$('#portfolioList > ul').css('width', cumulateWidth+'px');
		//Quand on sort de la zone
		$('#portfolioList').mouseout(function(data){
			slideAuth = false;
		});
		//Quand on rentre dans la zone
		$('#portfolioList').mouseover(function(data){
			//On regarde la position de PORTFOLIOLIST
			var offset = $(this).offset();
			//On calcule la position X de la souris par rapport à l'offset
			var offsetX = data.pageX - offset.left;
			//var offsetY = data.pageY - offset.top;
			var width = slideWidth;
			var widthArea = Math.round(width*slideAreaRatio)
			var areaLeft = widthArea;
			var areaRight = width - widthArea;
			//Si on est dans la zone LEFT
			if(offsetX < areaLeft){
				slideAuth = true;
				slideWay = 1;
				slideSpeed = Math.round((((areaLeft - offsetX) * slideMaxSpeed) / widthArea) * 100) / 100;
			}
			//Si on est dans la zone RIGHT
			else if(offsetX > areaRight){
				slideAuth = true;
				slideWay = -1;
				slideSpeed = Math.round((((offsetX - areaRight) * slideMaxSpeed) / widthArea) * 100) / 100;
			}
			else{
				slideAuth = false;
			}
		});
		slideTimeout = setTimeout(function(){
			slidePortfolioList();
		}, 20);
	}
}

//RECURSIVE CALL
function slidePortfolioList(){
	if(slideAuth && $('#portfolioList').length && $('#portfolioList').attr('status') != 'loading'){
		var left = parseInt($('#portfolioList > ul').css('left'));
		var width = $('#portfolioList > ul').outerWidth();
		if((slideWay == 1 && left < 0) || (slideWay == -1 && (width + left) > slideWidth)){
			$('#portfolioList > ul').css('left', (left + (slideWay * slideSpeed))+'px');
		}
	}
	slideTimeout = setTimeout(function(){
		slidePortfolioList();
	}, 20);
}

//VARIABLES DU SLIDE
var slideAuth = false;
var slideWay = 1;
var slideSpeed = 1;
var slideMaxSpeed = 6;
var slideAreaRatio = 0.2;
var slideWidth = 945;
var slideTimeout = setTimeout(function(){
	slidePortfolioList();
}, 20);

//FILTRAGE DES TYPES DE PROJETS
function portfolioFilter(trigger, url){
		
	if(!$(trigger).parent().hasClass('active') && $('#portfolioList').attr('status') != 'loading'){
		//On spécifie le rechargement AJAX
		$('#portfolioList').attr('status', 'loading');
		
		if($(trigger).attr('id') != 'resetPortfolioFilter'){
			//On ajoute la classe ACTIVE et la retir à tous les autres LI
			var parent = $(trigger).parent();
			parent.addClass('active').fadeTo(500, 1).siblings().removeClass('active').fadeTo(500, 0.2);
			$('#resetPortfolioFilter').css({
				'display': 'block',
				'left': (parent.position().left + parent.outerWidth() - 22)+'px'
			});
		}
		else{
			$(trigger).hide();
			$(trigger).prev().find('> li').removeClass('active').fadeTo(500, 1);
		}
		
		//On ajoute un DIV pour signifier le rechargement
		$('#portfolioList').append('<div class="loadingOverlay" />');
		//OPACITY 0 et DISPLAY Block
		$('#portfolioList .loadingOverlay').css({
			'opacity': '0',
			'display': 'block'
		});
		//On affiche en fondu
		$('#portfolioList .loadingOverlay').fadeTo(500, 0.8, function(){
			$.ajax(url, {
				//Une fois FADE effectué
				complete: function(data){
					//On supprime l'ancienne liste
					$('#portfolioList > ul').remove();
					//On ajoute la liste filtrée
					$('#portfolioList').prepend(data.responseText);
					//On FADE OUT sur le DIV spécifiant le rechargement AJAX
					$('#portfolioList .loadingOverlay').fadeOut(500, function(){
						//On spécifie que le chargement AJAX est terminé
						$('#portfolioList').attr('status', 'ok');
						//On supprime le DIV de spécification AJAX
						$(this).remove();
					});
				}
			});
		});
	}
	
	return false;
}

//CHARGEMENT D'UN PROJET
function portfolioProject(trigger, url){
	if(!$(trigger).parent().hasClass('active') && $('#portfolioContent').attr('status') != 'loading'){
		//On spécifie le rechargement AJAX
		$('#portfolioContent').attr('status', 'loading');
		
		//On ajoute la classe ACTIVE et la retir à tous les autres LI
		var parent = $(trigger).parent();
		parent.addClass('current').siblings().removeClass('current');
		
		//On ajoute un DIV pour signifier le rechargement
		$('#portfolioContent').append('<div class="loadingOverlay" />');
		//OPACITY 0 et DISPLAY Block et on fixe à la hauteur du block parent
		$('#portfolioContent .loadingOverlay').css({
			'opacity': '0',
			'height': $('#portfolioContent').innerHeight()+'px',
			'display': 'block'
		});
		//On affiche en fondu
		$('#portfolioContent .loadingOverlay').fadeTo(500, 0.8, function(){
			$.ajax(url, {
				//Une fois FADE effectué
				complete: function(data){
					//On supprime l'ancienne liste
					$('#portfolioContent > div:not(.loadingOverlay)').remove();
					//On ajoute la liste filtrée
					$('#portfolioContent').prepend(data.responseText);
					//On FADE OUT sur le DIV spécifiant le rechargement AJAX
					$('#portfolioContent .loadingOverlay').fadeOut(500, function(){
						//On spécifie que le chargement AJAX est terminé
						$('#portfolioContent').attr('status', 'ok');
						//On supprime le DIV de spécification AJAX
						$(this).remove();
					});
				}
			});
		});
	}
	
	return false;
}

//NAVIGATION AU CLAVIER
function keyboardNav(keyCode){
	switch(keyCode){
		//Flèche LEFT
		case 37:
			if($('#mainMenu > ul > li.active').prev('li').length){
				$('#footer').addClass('focus');
				$('#keyLeft').addClass('signify');
				setTimeout(function(){
					$('#keyLeft').removeClass('signify');
					$('#footer').removeClass('focus');
				}, 1000);
				$('#mainMenu > ul > li.active').prev('li').find('> a:first').click();
				if($('#level3').length && $('#level3').css('display') != 'none') closeLevel3();
			}
			else{
				if(site.currentPage != 'home'){
					$('#footer').addClass('focus');
					$('#keyLeft').addClass('signify');
					setTimeout(function(){
						$('#keyLeft').removeClass('signify');
						$('#footer').removeClass('focus');
					}, 1000);
					$('#logo > a').click();
					if($('#level3').length && $('#level3').css('display') != 'none') closeLevel3();
				}
			}
			break;
		//Flèche UP
		case 38:
			if($('#mainMenu > ul > li.active').length && $('#header').hasClass('shadow')){
				// var escape = false;
				var ctp = 0;
				var id = null;
				$('#'+site.currentPage).find('> .container > .subLevel_2').each(function(){
					if($(this).position().top < $('#'+site.currentPage).scrollTop()){
						id = ctp;
					}
					ctp++;
				});
				if(id != null){
					$('#footer').addClass('focus');
					$('#keyUp').addClass('signify');
					setTimeout(function(){
						$('#keyUp').removeClass('signify');
						$('#footer').removeClass('focus');
					}, 1000);
					$('#'+site.currentPage).find('> .container > .subLevel_2:first > .subMenu:first > li:eq('+id+') > a').click();
				}
				else{
					$('#footer').addClass('focus');
					$('#keyUp').addClass('signify');
					setTimeout(function(){
						$('#keyUp').removeClass('signify');
						$('#footer').removeClass('focus');
					}, 1000);
					$('#mainMenu > ul > li.active > a').click();
				}
			}
			break;
		//Flèche RIGHT
		case 39:
			if(!$('#mainMenu > ul > li.active').length){
				$('#footer').addClass('focus');
				$('#keyRight').addClass('signify');
				setTimeout(function(){
					$('#keyRight').removeClass('signify');
					$('#footer').removeClass('focus');
				}, 1000);
				$('#mainMenu > ul > li:first a').click();
				if($('#level3').length && $('#level3').css('display') != 'none') closeLevel3();
			}
			else{
				if($('#mainMenu > ul > li.active').next('li').length){
					$('#footer').addClass('focus');
					$('#keyRight').addClass('signify');
					setTimeout(function(){
						$('#keyRight').removeClass('signify');
						$('#footer').removeClass('focus');
					}, 1000);
					$('#mainMenu > ul > li.active').next('li').find('> a:first').click();
					if($('#level3').length && $('#level3').css('display') != 'none') closeLevel3();
				}
			}
			break;
		//Flèche DOWN
		case 40:
			var target = null;
			$.each(site.nav, function(i, nav){
				if(nav.id == site.currentPage && typeof(nav.children) != 'undefined'){
					target = nav.children[0].id;
				}
			});
			if(target != null && $('#'+target).length){
				$('#footer').addClass('focus');
				$('#keyDown').addClass('signify');
				setTimeout(function(){
					$('#keyDown').removeClass('signify');
					$('#footer').removeClass('focus');
				}, 1000);
				$('.subMenu > li > a[onclick*="return displayContent(this, \''+target+'\'"]:first').click();
				if($('#level3').length && $('#level3').css('display') != 'none') closeLevel3();
			}
			else{
				var escape = false;
				var ctp = -1;
				$('#'+site.currentPage).find('> .container > .subLevel_2').each(function(){
					if(!escape){
						ctp++;
						if($(this).position().top > $('#'+site.currentPage).scrollTop()){
							$('#'+site.currentPage).find('> .container > .subLevel_2:first > .subMenu:first > li:eq('+ctp+') > a').click();
							if($('#level3').length && $('#level3').css('display') != 'none') closeLevel3();
							$('#footer').addClass('focus');
							$('#keyDown').addClass('signify');
							setTimeout(function(){
								$('#keyDown').removeClass('signify');
								$('#footer').removeClass('focus');
							}, 1000);
							escape = true;
						}
					}
				});
			}
			break;
		//TABULATION
		case 9:
			$('#viewport').scrollLeft(0);
			$('#viewport').scrollTop(0);
			break;
		//AUTRES
		default:
			break;
	}
}

if(typeof(mobile) == 'undefined'){
	$(document).keyup(function(event){
		keyboardNav(event.keyCode);
	});
}
