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

/*------------------------------------------CAROUSEL HORIZONTAL-------------------------------------------------*/
var carouselSpeed=0.5;
function carouselManager(a,b){$("#carousel").attr("length",$("#carousel ul.list li").length).attr("current_id",0).attr("sliding","off");var c=0;$("#carousel ul.list li").each(function(){c+=$(this).outerWidth()});$("#carousel ul.list").css("width",c+"px");if($("#carousel ul.list").outerWidth()>$("#carousel .window").innerWidth()){$("#carousel .buttonRight").removeClass("off")}$("#carousel ul.list li").each(function(){$(this).attr("offset",$(this).position().left)});if(typeof(a)!="undefined"&&a==true&&typeof(b)!="undefined"){$("#carousel").attr("pagination","true");$("#carousel").attr("pagination_range",b);carouselMakePagination(b)}}function carouselMakePagination(a){$("#carousel").append('<ul class="pagination"></ul>');var b=0;$("#carousel ul.list li").each(function(){if(b<a){$("#carousel .pagination").append('<li class="active" onclick="carouselDirectAccess('+b+')">'+(b+1)+"</li>")}else{$("#carousel .pagination").append('<li onclick="carouselDirectAccess('+b+')">'+(b+1)+"</li>")}b++})}function carouselSetFocus(a,c){$("#carousel ul.pagination li").removeClass("active");for(var b=0;b<a;b++){if(typeof($("#carousel ul.pagination li")[c+b])!="undefined"){$($("#carousel ul.pagination li")[c+b]).addClass("active")}}}function carouselDirectAccess(d){var b=parseInt($("#carousel").attr("pagination_range"));$("#carousel").attr("current_id",d);var a=parseInt($("#carousel").attr("length"))-1;if(d==0){$("#carousel .buttonLeft").addClass("off");$("#carousel .buttonRight").removeClass("off")}else{if((d+b)>a){$("#carousel .buttonRight").addClass("off");$("#carousel .buttonLeft").removeClass("off")}else{$("#carousel .buttonLeft").removeClass("off");$("#carousel .buttonRight").removeClass("off")}}var c=parseInt($($("#carousel ul.list li")[d]).attr("offset"));carouselTrigger(c,b,d);carouselSetFocus(b,d)}function carouselTrigger(c,a,b){if($("#carousel").attr("pagination")=="true"){carouselSetFocus(a,b)}$("#carousel").attr("sliding","on");$("#carousel ul.list").animate({left:(-c)+"px"},(carouselSpeed*1000),function(){$("#carousel").attr("sliding","off")})}function carouselNext(b){if(!$("#carousel .buttonRight").hasClass("off")&&$("#carousel").attr("sliding")=="off"){var e=parseInt($("#carousel").attr("current_id"));var a=parseInt($("#carousel").attr("length"))-1;var c=e+b;if(c<=a){$("#carousel").attr("current_id",c);$("#carousel .buttonLeft").removeClass("off");var d=parseInt($($("#carousel ul.list li")[c]).attr("offset"));carouselTrigger(d,b,c)}c+=b;if(c>a){$("#carousel .buttonRight").addClass("off")}}return false}function carouselPrev(b){if(!$("#carousel .buttonLeft").hasClass("off")&&$("#carousel").attr("sliding")=="off"){var e=parseInt($("#carousel").attr("current_id"));var a=parseInt($("#carousel").attr("length"))-1;var c=e-b;if(c>=0){$("#carousel").attr("current_id",c);$("#carousel .buttonRight").removeClass("off");var d=parseInt($($("#carousel ul.list li")[c]).attr("offset"));carouselTrigger(d,b,c)}else{if(e<b){$("#carousel .buttonRight").removeClass("off");$("#carousel").attr("current_id",0);var d=parseInt($($("#carousel ul.list li")[0]).attr("offset"));carouselTrigger(d,b,0)}}c-=b;e=parseInt($("#carousel").attr("current_id"));if(c<0&&e==0){$("#carousel .buttonLeft").addClass("off")}}return false};

/*------------------------------------------GREYBOX-------------------------------------------------*/
//Config générale
var greyBoxDefaultConfig = {
	duration: 0.6,
	opacity: 0.6
};
//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.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.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}$("#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)}$("#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(b)};greyBoxDisplay(e,a.opacity);break;case"get":var e=function(){$("#greyBoxContent").load(b)};greyBoxDisplay(e,a.opacity);break;case"post":var e=function(){$.ajax({type:"POST",url:b,data:a.data,success:function(f){$("#greyBoxContent").html(f)}})};greyBoxDisplay(e,a.opacity);break;case"iframe":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("#greyBoxContent").html('<iframe src="'+b+'" border="0" frameborder="0" width="100%" height="'+f+'" allowTransparency="true"></iframe>')};greyBoxDisplay(e,a.opacity);break;case"youtube":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("#greyBoxContent").html('<object width="100%" height="'+f+'"><param name="movie" value="http://www.youtube.com/v/'+b+'&hl=fr_FR&fs=1&rel=0&color1=0x006699&color2=0x54abd6"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/'+b+'&hl=fr_FR&fs=1&rel=0&color1=0x006699&color2=0x54abd6" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="100%" height="'+f+'"></embed></object>')};greyBoxDisplay(e,a.opacity);break;case"dailymotion":var e=function(){var f=400;if(typeof(a.height)!="undefined"){f=a.height}$("#greyBoxContent").html('<object width="100%" height="'+f+'"><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);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();$("#greyBoxImage").fadeIn("medium");$("#greyBox").css("width","auto").css("left","-"+(Math.ceil($("#greyBoxContent").outerWidth()/2))+"px")})};greyBoxDisplay(e,a.opacity);break;default:break}}else{greyBoxDisplay(a.customFunction,a.opacity)}return false}function greyBoxDisplay(b,a){if($("#greyBox").attr("status")!="running"){$("#greyBox").attr("status","running");$(document).scrollTop(0);if(jQuery.browser.msie&&jQuery.browser.version=="6.0"){$("#overlay").css("position","absolute").css("height",$(window).height()+"px");$("#greyBoxLoader").css("height","200px")}$("#overlay").fadeTo(greyBoxEffectDuration,a,function(){$("#greyBox").fadeIn(greyBoxEffectDuration,function(){$("#greyBox").attr("status","done");b()})})}}function greyBoxHide(){if($("#greyBox").attr("status")!="running"){$("#greyBox").attr("status","running");$("#greyBox").fadeOut(greyBoxEffectDuration,function(){$("#greyBox").hide();$("#overlay").fadeOut(greyBoxEffectDuration,function(){$("#greyBox").attr("status","done")})})}};

/*------------------------------------------GREYBOX-------------------------------------------------*/
/*--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(j.is("input")){if(j.attr("type")=="text"||j.attr("type")=="password"||j.attr("type")=="file"){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){return true}else{greyBoxShow(d.alert,400,"html");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()&&e.outerWidth()>80){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);$("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")})}})}};

/*--- VARIABLE FORMATAGE DATEPICKER ---*/
var datepickerValues = {
	dateFormat: 'dd/mm/yy',
	dayNames:['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
	dayNamesMin:['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
	monthNames:['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre']
}
/*--- VARIABLE FORMATAGE DATEPICKER ---*/

/*--- show fiche ---*/


function init_image()
{
	var size = $('#carousel .window .list li').size();
	
	for(i=0; i<size; i++)
	{
		var src = $('#carousel .window .list li a img').eq(i).attr('src');
		var href = $('#carousel .window .list li a').eq(i).attr('href');
        $('.visuel').eq(i).html('<a onclick="return greyBoxShow(\'' + href + '\', 200, \'image\');" href="' + href + '"><img  alt="" src="'+src+'" width="401" height="318" /></a>').fadeIn('slow');
	}
	
	$('.show_fiche').hide();
	$('.show_fiche').eq(0).show();
	
}

$(document).ready(function() {
    /*----- FICHE VISUEl ------*/
    
    $('#carousel .window .list a').click(function(){
    
         src = $(this).children('img').attr('src');
		 href = $(this).attr('href');
         $('.visuel').html('<a onclick="return greyBoxShow(\'' + href + '\', 200, \'image\');" href="' + href + '"><img alt="" src="'+src+'" width="401" height="318" /></a>').fadeIn('slow');
         return false;
    });

	/*------- SHOW SITEMAP ------*/
	$("ul.menu li.more a").click(function()
		{
			if(!$(this).hasClass('show')){
				$(this).addClass('show');
				$("#sitemap").fadeIn();
				return true;
			}
			else{
				$(this).removeClass('show');
				$("#sitemap").fadeOut();
				return false;
			}
		}
	);
	
});

