// JavaScript Document
function rollOvers(){
	if (!document.getElementById) return
	
	var imgOriginSrc;
	var MouseOverHappened;
	var oldtop;
	var imgTemp = new Array();
	var imgarr = document.getElementsByTagName('img');
	
	for (var i = 0; i < imgarr.length; i++) {
		//Attribut hsrc pour Rollovers
		if (imgarr[i].getAttribute('hsrc')) {
			imgTemp[i] = new Image();
			imgTemp[i].src = imgarr[i].getAttribute('hsrc');
			imgarr[i].onmouseover = function() {
				imgOriginSrc = this.getAttribute('src');			
				this.setAttribute('src',this.getAttribute('hsrc'));
				MouseOverHappened=true;
			}
			imgarr[i].onmouseout = function() {
				if(MouseOverHappened)
					this.setAttribute('src',imgOriginSrc);
			}
		}
	
		//Attribut csrc pour action de click comme boutons
		if (imgarr[i].getAttribute('csrc')) {
			imgTemp[i] = new Image();
			imgTemp[i].src = imgarr[i].getAttribute('csrc');
			imgarr[i].onmousedown = function() {
				imgOriginSrc = this.getAttribute('src');			
				this.setAttribute('src',this.getAttribute('csrc'));
				MouseOverHappened=true;
			}
			imgarr[i].onmouseup = function() {
				if(MouseOverHappened)
					this.setAttribute('src',imgOriginSrc);
			}
		}
	}
}

sfHover = function() {
	var sfEls = document.getElementById("menuFirst").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
	
	
}
if (window.attachEvent) window.attachEvent("onload", sfHover);



function addEmail(courriel){
	ret = function(){
		if(ajaxOk()){
			eval(objAjax.responseText);
			killAjax();
		}
	}
	callAjax('/ajax/addemail.php?email='+courriel,ret,null);
}

function addEmailEN(courriel){
	ret = function(){
		if(ajaxOk()){
			eval(objAjax.responseText);
			killAjax();
		}
	}
	callAjax('/ajax/addemailEN.php?email='+courriel,ret,null);
}



function envoiDemande(hndl){
	if(validForm(hndl)){
		callAjax('/script/demande.php',null,$('resultat'),hndl);
	}
}

function envoiDemandeEN(hndl){
	if(validForm(hndl)){
		callAjax('/script/demandeEN.php',null,$('resultat'),hndl);
	}
}

jQuery.fn.adnMenu = function() {
	var o = $(this);
	var params = arguments[0] || {};
		if(!params.tag) params.tag = "ul"; //classe du hover
		if(!params.oClass) params.oClass = "shover"; //classe du hover
		if(!params.show) params.show = false; //animation d'affichage
		if(!params.hide) params.hide = false; //animation de cachage
		
	$(o).mouseenter(function(){
		$(this).addClass(params.oClass);
		if(params.show){
			if($(this).find("> "+params.tag).is(":visible")) $(this).find("> "+params.tag).hide();
			$(this).find("> "+params.tag).animate(params.show);
		}
	});
	$(o).mouseleave(function(){
		if($(this).find("> "+params.tag).length>0 && params.hide){
			$(this).find("> "+params.tag).animate(params.hide,function(){
				$(this).parent().removeClass(params.oClass);
			});
		}else{
			$(this).removeClass(params.oClass);
		}
	});
};

jQuery(document).ready(function(){
		slideshow();
});
updateDateRetour = function(){
	if(jQuery("#datederetour").val()==""){jQuery("#datederetour").val(jQuery("#dateprevue").val());}
};

var curheaderimage=1;
var hndltimer=0;
slideshow = function(){
	$("#slideshow a").each(function(){
		jQuery.preLoadImages($(this).attr("href"));
		if($(this).attr("title")=="1"){
			var reference = $(this);
			$("#ssimg1").click(function(){document.location.href=reference.attr("rel");});
		}
		$(this).click(function(e){
			clearTimeout(hndltimer);				   
			e.preventDefault();
			var oldImage = $("#ssimg1").attr("src");
			$("#slideshow a").removeClass("selected");
			$(this).addClass("selected");
			$("#imgwrapper").css({backgroundImage: "url('" + oldImage + "')"});
			$("#ssimg1").attr("src",$(this).attr("href")).hide().fadeIn("slow");
			var reference = $(this);
			$("#ssimg1").click(function(){document.location.href=reference.attr("rel");});
			curheaderimage = parseInt($(this).attr("title"));
			hndltimer = setTimeout("nextimageslideshow()",5000);
		});
	});
	hndltimer = setTimeout("nextimageslideshow()",5000);
};

nextimageslideshow = function(){
	curheaderimage++;
	if(curheaderimage>$("#slideshow a").length){
		curheaderimage=1;
	}
	$("#slideshow a").each(function(){if(parseInt($(this).attr("title"))==curheaderimage){$(this).click();}});
};

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery)



