//>----------------------------------------------------------------------------------------------

function makeSelected(sHref){
	$('a[href="' + sHref + '"]').addClass("selected");
}

//>----------------------------------------------------------------------------------------------

function makeMenuSelected(sHref){
	var oA = $('#menu a[href="' + sHref + '"]:last');
	oA.addClass("selected current");
	oA.parent().addClass("current");
	oA.parents().filter('#menu *').addClass("selected");
}

//>----------------------------------------------------------------------------------------------

function Rotator(oDiv)
{
	this.iFading = 2000; // Durée de la transistion en millisecondes
	this.iDuration = 10000; // Durée d'affichage en millisecondes d'un éléments
	
	this.oItems = $(oDiv).children();
	this.iNbr = this.oItems.size();
	
	this.start = function()
	{
		if (this.iNbr > 1)
		{
			var iCurrent = Math.floor(Math.random() * this.iNbr);
			this.oItems.slice(iCurrent + 1, this.iNbr).hide();
			var thisObj = this;
			setTimeout(function(){thisObj.rotateBannersFadeIn(iCurrent + 1);}, this.iDuration - this.iFading);
		}
	}
	
	this.rotateBannersFadeIn = function(iIndex)
	{
		if (iIndex == 0)
		{
			this.oItems.slice(1, this.iNbr - 1).hide();
			this.oItems.slice(this.iNbr - 1, this.iNbr).fadeOut(this.iFading);
			var thisObj = this;
			setTimeout(function(){thisObj.rotateBannersFadeIn(iIndex + 1);}, this.iDuration);
		}
		else if (iIndex < this.iNbr)
		{
			this.oItems.slice(iIndex, iIndex + 1).fadeIn(this.iFading);
			var thisObj = this;
			setTimeout(function(){thisObj.rotateBannersFadeIn(iIndex + 1);}, this.iDuration);
		}
		else
		{
			this.rotateBannersFadeIn(0);
		}
	}
}

//>----------------------------------------------------------------------------------------------

$(document).ready(function(){
	
	var aBackgroundImages = [
		"img/elements/background.jpg",
		"img/elements/background2.jpg",
	];
	var iRandom = Math.floor(Math.random() * aBackgroundImages.length);
	$("body").css("background-image", "url(\"" + aBackgroundImages[iRandom] + "\")");
	
	$("img").attr("onMouseDown", "return false").attr("onMouseMove", "return false");
	$("a[rel='img']").colorbox({
		transition:"none",
		opacity:0.5,
		current:"",
		previous:"Précédant",
		next:"Suivant",
		close:"Fermer"
	});
	$("a.ajax_box").colorbox({
		transition:"none",
		opacity:0.5,
		close:"Fermer",
		inline:true
	});
	$("div.rotator").each(function(i){
		var oRotator = new Rotator(this);
		setTimeout(function(){oRotator.start();}, i*5000);
	});
	
	// Menu déroulant
	$("#menu img").click(function(){
		var oDiv = $(this).parent();
		oDiv.children("ul").slideDown("normal");
		oDiv.siblings().children("ul").slideUp("normal");
	});
});

//>----------------------------------------------------------------------------------------------

