
var MenuWidth = 960; /* largeur max du menu */
var unfoldMenu = 300; /* largeur max de l'element deployer */
var lowerOpacity = 0.6; /* Opacité des éléments */
var normalOpacity = 1; /* Opacité de l'élément en focus */
var speedAnim = 300; /* Vitesse de l'animation */
var timeout = 2500;
var maxWidth = 0;
var minWidth = 0;
var lastBlock = null;

function toNext()
{
	var next = lastBlock.next();
	if(next.size() == 0)
		next  = $("ul#accordeon li").first();
	$(lastBlock).animate({width: minWidth+"px", opacity: lowerOpacity}, {queue:false, duration: speedAnim});
	$(next).animate({width: maxWidth+"px", opacity: normalOpacity}, {queue:false, duration: speedAnim});
	lastBlock = next;
	setTimeout(toNext, timeout);
}

function highlightElem()
{
		$(lastBlock).animate({width: minWidth+"px", opacity: lowerOpacity}, {queue:false, duration: speedAnim});
		$(this).animate({width: maxWidth+"px", opacity: normalOpacity}, {queue:false, duration: speedAnim});
		lastBlock = this;
}

function initAccordeon()
{
	var accordItems = $("ul#accordeon li");
	var listContainer = accordItems.size(); /* compte le nombre d"element dans le menu */
	
	$("#accordeon").css("width", MenuWidth);
		
		if (listContainer<=3) {/* si le nombre d'element est inferieur a 3 il n'y a pas d'animation */
			maxWidth = MenuWidth/listContainer;
			minWidth = maxWidth;
		 } 
		 else {
			maxWidth = unfoldMenu;
			minWidth = Math.floor((MenuWidth-maxWidth)/(listContainer-1)-0.1);			
		 }
		 
		if (idArt == "") {
			lastBlock = accordItems.first();
		}
		else {
			lastBlock = $("#a"+idArt).parent();
		};
		
		accordItems.css("opacity", lowerOpacity); 
		accordItems.css("width", minWidth); 
		lastBlock.css("opacity", normalOpacity);	
		lastBlock.css("width", maxWidth);
		
		accordItems.hover(highlightElem); 
		setTimeout(toNext, timeout);
}

$("#accordeon").ready(initAccordeon);

