// JavaScript Document utéf-8

/*** globales pour $ et js ***********************************/

readyPush=new Array();	/* chaque élément sera évalué au $(document).ready  */
loadPush=new Array();	/* chaque élément sera évalué au $(window).load  */
needMouse=false;		/* si vrai, le onmousemouse sera activé sur le body */
withMouse=false;		/* si vrai, doit être une fonction */
x_mouse=y_mouse=0;		/* retournées par body.onmousemouse */
moveTarget=false;		/* activée par body.onmousemouse, stopée par body.mouseup */
globalZindex=100;		/* incrémenter 'manuellement' :) */

/*** classiques ***********************************/

function findObj(n,c)			{var x,d=c?c.document:document; if(!(x=d.getElementById(n))){x=d[n]};return x;}
function findTags(obj,tag,arr)	{if(tag=='*'){obj.ALLS = obj.all||obj.getElementsByTagName(tag);}else{obj[tag+"S"] = obj.all?obj.all.tags(tag):obj.getElementsByTagName(tag);};if(arr)return obj.ALLS || obj[tag+"S"] || [];}
function getBounds(obj)			{obj.X=obj.offsetLeft;obj.Y=obj.offsetTop;obj.W=obj.offsetWidth;obj.H=obj.offsetHeight;var tempObj=obj;while(tempObj=tempObj.offsetParent){if (isNaN(tempObj.offsetTop)) break;obj.X+=tempObj.offsetLeft;obj.Y+=tempObj.offsetTop; }return obj;}

// obsolètes :utiliser obj.parentNode
function findRealParent(obj)	{if(!obj.parentNode)obj.parentNode=obj.parentElement ; return obj.parentNode;}
/*
function getMouseEvent(obj){if(self.objToDrag==null) { self.objToDrag=false; self.zind=100; }var NavEvent,x_mouse,y_mouse,retVal,cible;NavEvent=self.event||getMouseEvent.caller.arguments[0];retVal=NavEvent.returnValue;typevent=NavEvent.type;cible=NavEvent.target||NavEvent.srcElement;var sx= self.scrollX || (document.body.scrollLeft+document.documentElement.scrollLeft) || 0;var sy= self.scrollY || (document.body.scrollTop+document.documentElement.scrollTop) || 0;x_mouse=NavEvent.clientX+sx||NavEvent.x;y_mouse=NavEvent.clientY+sy||NavEvent.y;if(typevent=='mousedown' && obj){objToDrag=obj;obj.x_in=x_mouse-obj.X;obj.y_in=y_mouse-obj.Y;if(document.selection){document.selection.empty(); if(/msie 4.+windows/i.test(navigator.userAgent))self.scrollTo(sx,sy);};document.onmousedown=Function("return getMouseEvent();");document.onmouseup=Function("getMouseEvent();");retVal=false;return retVal;};if(typevent=='mousedown' && objToDrag){zind++;document.onmousemove=Function("return getMouseEvent(objToDrag)");objToDrag.activeIt(x_mouse-objToDrag.x_in,y_mouse-objToDrag.y_in,cible);retVal=false;return retVal;};if(typevent=='mouseup' && objToDrag){ document.onmousemove=null;objToDrag.stopIt(x_mouse-objToDrag.x_in,y_mouse-objToDrag.y_in,cible);objToDrag=false;retVal=true;return retVal;}
if(typevent=='mousemove' && objToDrag){objToDrag.activeIt(x_mouse-obj.x_in,y_mouse-obj.y_in,cible);retVal=false;return retVal;}}
*/

String.prototype.trim = function() {return this.replace(/(^\s*)|(\s*$)/g,'');}

function trace(str){if( typeof document.traceBox == 'undefined' ){var traceBox=document.createElement('TEXTAREA');traceBox.cols='40';traceBox.rows='10';with(traceBox.style){position='absolute';right='20px';bottom='20px';zIndex='100001';}traceBox.ondblclick=function(){this.style.display='none';};document.body.appendChild(traceBox);document.traceBox=traceBox;}document.traceBox.value=str+"\n"+document.traceBox.value;document.traceBox.style.display='block';}
function arrondi(nbre){if(nbre=="") return "";nbre=nbre.replace(/,/g,".");if(isNaN(parseFloat(nbre,10)))return "0.00";nbre=String(Math.round(parseFloat(nbre,10)*100)/100);nbre=nbre.replace(/(^[0-9]+$)/,"$1.00");nbre=nbre.replace(/(^[0-9]+\.[0-9]$)/,"$1"+"0");return nbre;}
function ismail(mail){return (/^([a-z_0-9\.-]+)@([a-z_0-9\.-]+)\.([a-z]{2,5})$/).test(mail);}
function Fwrite(str){document.write(str);}
function change_url(str){location=str;}
function replace_url(str){location.replace(str);}
function clearSelection(){var sel;if(document.selection && document.selection.empty){try{document.selection.empty();}catch(e){};}else if(window.getSelection){sel=window.getSelection();if(sel && sel.removeAllRanges)sel.removeAllRanges();}}
function set_opacity(el,opacity){opacity =Math.max(0.001,Math.min((/Gecko/.test(navigator.userAgent) && !/Konqueror|Safari|KHTML/.test(navigator.userAgent)) ? 99.999 : 100,opacity));el.style["filter"] = "alpha(opacity="+opacity+")";el.style["-moz-opacity"] = opacity/100;el.style["-khtml-opacity"] = opacity/100;el.style["opacity"] = opacity/100;}
function noempty(str){return (str!='');}
function setCpNumber(obj){obj.value=obj.value.trim();obj.value=obj.value.replace(/[^0-9]/gi,'');}
function isphone(str){return (/^\+?[0-9]{10,}/).test(str);}
function iscp(str){return (/^[0-9]{5,6}/).test(str);}
function setPhoneNumber(obj){obj.value=obj.value.trim();obj.value=obj.value.replace(/[^+0-9]/gi,'');}

function createBoxError(){	if(typeof boxError=='object') return boxError;hideBoxError=document.createElement('DIV');hideBoxError.style.display='none';document.body.appendChild(hideBoxError);
hideBoxError.innerHTML='<div id="boxError"><h5 id="titreBoxError">Merci de renseigner correctement les champs suivants.</h5><ul id="listeBoxError"></ul><p><a href="#Close" id="lienBoxError" onclick="$.fancybox.close();return false;">Fermer</a></p></div>';
var boxError=self.boxError=hideBoxError.firstChild;boxError.titre=function(titre){$('#titreBoxError').html(titre);};boxError.liste=function(liste){$('#listeBoxError').html(liste);};boxError.lien=function(lien){$('#lienBoxError').html(lien);};
return boxError;
}



var moteur=[[,""],[,""],[,""],[,""]], mDelay=0, Zind=100, marge=20;

function mOver(obj,level,SM){
clearTimeout(mDelay);var d=document,decalX=8,decalY=5; // decalX permet le chevauchement ; decalY être utilisé pour le niveau 0
	for (var i=moteur.length-1;i>=level;i--){
		if(moteur[i][0] && moteur[i][0]!=obj) moteur[i][0].className=moteur[i][0].className.replace("actif","");
		if(moteur[i][1] && moteur[i][1]!="" && i>=level){
		var SSM=(typeof moteur[i][1] != 'string' ? moteur[i][1] : findObj(moteur[i][1]) );
			if(document.all && !window.opera) mShowSIF(SSM);
		SSM.style.visibility='hidden';
		}
	}
	if(!obj || obj==null) return;
moteur[level][0]=obj;
	if(SM!="" || typeof SM != 'string'){
	var klass=obj.className;
	klass=klass.replace("actif"," "); // securite pour Fix
	var multiKlass = klass.replace(/(.*)/,"$1"+" actif"); // permet de remplacer "rouge text12" par "rouge text12 actif"
	if(klass.indexOf('fix')==-1) obj.className=multiKlass; // au lieu de obj.className=klass+"Actif"
	//document.title=obj.className;
	moteur[level][1]=SM;
	var kalc= (typeof SM != 'string'? SM : findObj(SM) ), LI=findRealParent(obj);
		if(!kalc.style.width){
		kalc.style.width=kalc.offsetWidth+'px'; // pour IE5 :: white-space invalide
			if(kalc.mode=='H' && level==0){ /* taille minimum==au lien */
			kalc.style.width=Math.max(obj.offsetWidth,kalc.offsetWidth)+'px';
			}
		}
	getBounds(LI);
	getBounds(kalc);
	var maxRight=10000,maxBottom=0;
		if(kalc.ref){
		var ref=findObj(kalc.ref);
		getBounds(ref);
		maxRight=(ref.X+ref.W);
		maxBottom=(ref.Y+ref.H);
		}
		switch(kalc.mode){
			case 'V': 
			kalc.style.left = level==0 ? (obj.offsetWidth+(document.all?0:obj.offsetLeft))+'px' : (LI.W-decalX)+'px' ;
			kalc.style.top=  level==0 ? -(decalY)+'px': (decalY)+'px';
			break;
			
			case 'VR': 
			kalc.style.left = level==0 ? (-kalc.W+(!document.all?obj.offsetLeft:0))+'px' : (-kalc.W+decalX)+'px' ;
			kalc.style.top=  level==0 ? -(decalY)+'px': (decalY)+'px';
				if( (maxBottom-(LI.Y+kalc.H))<0 ){
				kalc.style.top=  level==0 ? -(kalc.H-LI.H)+'px': -(kalc.H-LI.H-decalY)+'px';
				}
			break;
			
			default:
			var out= level==0 ? (maxRight-(LI.X+kalc.W)) : (maxRight-(LI.X+LI.W+kalc.W)) ;
				if(out<0){
				kalc.style.left = level==0 ? (out)+'px' : -(kalc.W-decalX)+'px';
				}else{
				kalc.style.left = level==0 ? '0px' : (LI.W-decalX)+'px';
				}
				if(kalc.mode=='HU'){
				kalc.style.top = level==0 ? -(kalc.H)+'px' : -(kalc.H-obj.offsetHeight+decalY)+'px';
				}
			//alert('maxRight='+maxRight+' out='+out+' LI.X='+LI.X+' kalc.W='+kalc.W);
		}
	Zind++;
	LI.style.zIndex=Zind;
	kalc.style.visibility='visible';

	/* Traitement de l'affichage des Form.Select(All IE) et Iframe (IE<5.5)*/
	if(document.all && !window.opera) { getBounds(kalc); mHideSIF ('IFRAME', kalc); mHideSIF ('SELECT', kalc); }
	/* fin cache iframes & selects*/
	}
	if(!obj.onmouseout){obj.onmouseout=Function("mDelay=setTimeout(\"mOver(null,0,'')\", 400)");}
return;
/* fonctions spécifiques  */
// associe un s-menu à des Select ou iframe à cacher 
	function mHideSIF (tagName, sm) { if(!sm.mustHide)sm.mustHide=new Array();getBounds(sm);for (var i = 0; i < document.all.tags(tagName).length; ++i) { var SIF = document.all.tags(tagName)[i];if (!SIF || !SIF.offsetParent) continue;getBounds(SIF); if (SIF.X > (sm.X + sm.W) || (SIF.X + SIF.W) < sm.X || SIF.Y > (sm.Y + sm.H) || (SIF.Y + SIF.H) < sm.Y || SIF.style.visibility == "hidden" ) continue;sm.mustHide[sm.mustHide.length] = SIF;SIF.style.visibility = "hidden";}}
	function mShowSIF (sm){ if (sm.mustHide){ for (var i = 0; i < sm.mustHide.length; ++i) sm.mustHide[i].style.visibility = "visible"; } sm.mustHide = null;}
/* fin fonctions spécifiques  */

} /* fin mOver */

/* Traitement des onmouseover des liens de menu UL LI -> A  */
/* menu H : tout es à left/ */
function addEventsMenu(UL, level, opt){
	if(!level) {
	level=0;
	if( !(UL=findObj(UL)) ) return;
		if(opt=UL.getAttribute('title')){
		opt=eval('new Object('+opt+')');
		UL.title='';
		}else{
		//opt={mode:'H', ref:false};
		ref=UL.id!=''?UL.id:false;
		opt={mode:'H', ref:ref};
		}
	/* alert(opt.ref);return; */
	}
	if(level>3)return; /* securité 0 1 2 3 suffisent */
var n=UL.childNodes.length;
	for(var i=0; i<n; i++){
	var LI=UL.childNodes[i];
		if(LI.tagName=='LI'){
		var ULS=findTags(LI,'UL','arr');
		var a=LI.getElementsByTagName("A")[0];
			if(ULS.length>0){ /* attribuer mOver(this,0++,'SM5'->objUL) au 1er lien pour afficher le 1er UL */
			a.SM=LI.getElementsByTagName("UL")[0];
			a.SM.mode=opt.mode; a.SM.ref=opt.ref;
			a.onmouseover=Function("","if(mOver) mOver(this,"+level+",this.SM);");
			var nn=LI.childNodes.length;
				for(var ii=0; ii<nn; ii++){
				var ULUL=LI.childNodes[ii];
					if(ULUL.tagName=='UL'){
					addEventsMenu(ULUL, level+1,opt);
					}
				}
			}else{ /* attribuer seulement mOver(this,1++,'') */
				if(level>0){ /* on passe le premier niveau, il n'y a pas à maintenir de déclinaison d'affichage*/
				a.onmouseover=Function("","if(mOver) mOver(this,"+level+",'');");
				}
			}
		}
	}
}
/*  FIN Traitement des onmouseover des liens de menu UL LI -> A  */


/*  Functions du site  */

		var paramsFancy = {
			margin : 0
			,padding : 0
			,hideOnContentClick : true
			,showCloseButton : true
			,overlayOpacity : 0.5
			,overlayColor : '#FFFFFF'
			/*,overlayColor : '#01894B'*/
			,speedIn : 500
			,speedOut : 100
			,transitionIn : 'elastic'
			/*,modal : true*/
		};

/*** petites annonces */
function visuels(){
	if($('.photo-annonce').length){
	$('.photo-annonce').fancybox(paramsFancy);
	}
}

function validation(form){

var message='';

	if( typeof Fancy == 'undefined' ){
	createBoxError();
	/*** utiliser et modifier le paramsFancy global */
	var paramsFancyBoxError=paramsFancy;
	$.extend(paramsFancyBoxError, { modal : true, transitionIn : 'none', transitionOut : 'none'});
	// juste besoin d'un objet qui simule un A
	Fancy=Fancy=new Object();
	Fancy.href='#boxError';
	$(Fancy).fancybox(paramsFancyBoxError);
	}
	
	for(var i=0; i<form.length; i++){
	var elmt=form[i], name=form[i].name, V_elmt;
		
		if(name && (V_elmt=form['V_'+name]) ){
		elmt.value=elmt.value.trim();
		var V_elmt, funct, retour=false;
			
			if( funct=self[V_elmt.title] ){
			retour = funct(elmt.value);
				
				if( retour ){
				}else{
				message+= '<li>'+V_elmt.value+'</li>'+ "\n";
				}
			}
		}
	}

	if(message==''){
	form.submit();
	//trace('ok');
	return true;
	}else{
	boxError.liste(message);
	$(Fancy).trigger("click");
	return false;
	}

}

function annuler(form){
	if(confirm(form.annulation.value)){
	form.act.value='annuler';
	form.onsubmit=function(){return true;}
	form.submit();
	}
}

function apercu(form){
form.act.value='apercu';
}

function publier(form){
	if(confirm(form.comfirmation.value)){
	form.act.value='publier';
	validation(form);
	}
}


function init_annonce(){
//trace($('a[href^=#A]').length);
var A_to_hide=false;
	$('a[href^=#A]').each(
	function(a,b){
		$(b).toggle(
			function(){
			$(b.rel).show('slow');
				if(A_to_hide){
				$(A_to_hide).trigger('click');
				}
			A_to_hide=b;
			}
			,
			function(){$(b.rel).hide('slow');A_to_hide=false;}
		);
		
	});
}

function ouvre_annonce(){
	if(/^(#A[0-9]+)/.test(location.hash) || (location.hash=='#A_nouvelle_annnonce')){
	var ancre=location.hash;
	setTimeout( function(){$('a[href='+ancre+']').trigger('click');},500);
	}
}
/*  Functions du site  */



/*  Chargement $ready  */

$(document).ready(function() {

	if(needMouse){
		$("body").mousemove( function(e) {x_mouse=e.pageX; y_mouse=e.pageY; if(withMouse)withMouse(); if(moveTarget && moveTarget.activeIt){clearSelection();moveTarget.activeIt();return false;} } );
		$("body").mouseup( function(e) {if(moveTarget && moveTarget.stopIt) moveTarget.stopIt();moveTarget=false;} );
	}

/* *** VOTRE CODE ICI *** */

addEventsMenu('menu');

// diaporamas simples avec image ol sans controles
$('.image ol').each(
	function(a,b){
		$(b).css('height',$(b).height()+'px').addClass('diapo');
		$(b).diaporama({ animationSpeed: "slow", delay:2, controls:false });
	}
);


	if($('.liste-articles a').length){
	//trace($('.liste-articles a').length);
	$('.liste-articles a').attr('rel','example_group');
	paramsFancy.autoScale=false;
	$('.liste-articles a').fancybox(paramsFancy);
	}

/* *** FIN DE VOTRE CODE *** */

	for(var i=0;i<readyPush.length;i++){eval(readyPush[i]);}

/* *** detection version FlashPlayer déclaration de la version demandée *** */
navigator.NeedFlashVersion=7;navigator.NeedFlash=false;navigator.FlashVersion=0;navigator.CanPlayFlashPlayer=false;if( document.getElementsByTagName ){var of=document.getElementsByTagName('OBJECT'); var nf=of.length;for (var i=0;i<nf;i++){var source=of[i].innerHTML;if(!(/\.swf["?]/gi.test(source))) continue;of[i].AllowScriptAccess = "always";if( !navigator.NeedFlash ){navigator.NeedFlash=0;try{navigator.FlashVersion=parseInt(navigator.plugins["Shockwave Flash"].description.match(/[0-9]+[.,]/));}catch(e){try{var ie_vers=of[i].GetVariable("$version");navigator.FlashVersion=(parseInt(ie_vers.match(/[0-9]+[.,]/)));}catch(e){}}}navigator.NeedFlash++;}if(navigator.NeedFlash && navigator.FlashVersion<navigator.NeedFlashVersion){navigator.CanPlayFlashPlayer=false;var div=document.createElement('DIV');div.className='NeedFlashVersion';div.innerHTML='You need to upgrade your Flash Player';document.body.appendChild(div);}else{navigator.CanPlayFlashPlayer=true;}}
/* *** FIN detection version FlashPlayer *** */
});

/*  Chargement $load  */
$(window).load(function() {
	for(var i=0;i<loadPush.length;i++){eval(loadPush[i]);}
});

/* *** objets *** */
// http://tuts.guillaumevoisin.fr/jquery/diaporama/
(function($){
	$.fn.diaporama = function(options) {

		var defaults = {
			delay: 3,
			animationSpeed: "normal",
			controls:true
		};
				
		var options = $.extend(defaults, options);
		
		this.each(function(){
		
			var obj = $(this);
			
			
			if($(obj).find("li").length > 1){
				var inter = setInterval(function(){nextElt(options)}, (options.delay*1000));
				var sens = "right";
				var pause = false;
				
				$(obj).find("li").hide();
				$(obj).find("li:first-child").addClass("active").fadeIn(options.animationSpeed);
				
				// Controls
				
				if(options.controls)
				{
					$(obj).after("<div class='diaporama_controls'><div class='btns'>&nbsp;<a href='#' class='prev'>Prec.</a> <a href='#' class='pause'>Pause</a> <a href='#' class='next'>Suiv.</a></div></div>");
					
					$(obj).siblings().find(".prev").click(function(){
						clearInterval(inter);
						prevElt(options);
						if(!pause)
							inter = setInterval(function(){prevElt(options)}, (options.delay*1000));
						sens = "left";
					});
					
					$(obj).siblings().find(".next").click(function(){
						clearInterval(inter);
						nextElt(options);
						if(!pause)
							inter = setInterval(function(){nextElt(options)}, (options.delay*1000));
						sens = "right";
					});
													
					$(obj).siblings().find(".pause").toggle(
						function(){
							$(this).removeClass("pause").addClass("play");
							clearInterval(inter);
							pause = true;
						},
						function(){
							$(this).removeClass("play").addClass("pause");
							inter = setInterval(function(){ (sens == "right")?nextElt(options):prevElt(options)}, (options.delay*1000));
							pause = false;
						}
					);
				}
				
				// Affiche l'�l�ment suivant
				
				function nextElt(options)
				{
					$(obj).find("li.active").fadeOut(options.animationSpeed);
					
					if(!$(obj).find("li.active").is(":last-child"))
					{
						$(obj).find("li.active").next().addClass("active").prev().removeClass("active");
						$(obj).find("li.active").fadeIn(options.animationSpeed);
						
					}
					else
					{
						$(obj).find("li:first-child").addClass("active").fadeIn(options.animationSpeed);
						$(obj).find("li:last-child").removeClass("active");
					}
				}
				
				//
				
				function prevElt(options)
				{
					$(obj).find("li.active").fadeOut(options.animationSpeed);
					
					if(!$(obj).find("li.active").is(":first-child"))
					{
						$(obj).find("li.active").prev().addClass("active").next().removeClass("active");
						$(obj).find("li.active").fadeIn(options.animationSpeed);
						
					}
					else
					{
						$(obj).find("li:last-child").addClass("active").fadeIn(options.animationSpeed);
						$(obj).find("li:first-child").removeClass("active");
					}
				}
			}
		});
		
		return this;
	};
})(jQuery);
/* *** FIN objets *** */
