var i=1;
var fonds = new Array();
var time = 5000;

function cycleFond(){
	// On vérifie si on est pas à la fin du tableau
	if(fonds.length<i) var newFond=fonds[0];
	else var newFond=fonds[i];
	
	// On change le fond
	$('#banniere').css('background-image', "url('"+newFond+"')");
	$('#fond').animate(	{opacity: 0}, 2000, 'swing', function(){
		$('#fond').css('background-image', "url('"+newFond+"')");
		$('#fond').css('opacity', '1');
	});
		
	i++;
	/// On vérifie si on est pas à la fin du tableau
	if(fonds.length<(i+1)) i=0;
	setTimeout("cycleFond("+time+")", time);
}

$(document).ready(function(){
	// Menu horizontal
	$('#menu li').css('cursor', 'pointer');
	$('#menu li').hover(
		function(){
			$(this).css('height', '45px');
			$(this).css('margin-top', '4px'); },
		function(){
			$(this).css('height', '31px');
			$(this).css('margin-top', '18px'); }
	);

	// Menu vertical
	if( !($.browser.msie && (6==$.browser.version || 7==$.browser.version)) )
		$("#categories").accordion({ autoHeight: false });
	else
		$("#categories").accordion({ autoHeight: false, animated : false });
	$('.sous_categorie li').hover(
		function(){	$(this).addClass('ui-state-hover'); },
		function(){	$(this).removeClass('ui-state-hover'); }
	);
	if($("#menu_actif").length > 0){
		$( "#categories" ).accordion( "option", "active", parseInt($('#menu_actif').html()) );
	}
	
	// Liens nouvelle fenetre
	$('.newWindow').click(function(){
		window.open(this.href);
		return false;
	});
	
	// Bannière
	if(!($.browser.msie && $.browser.version==6)){
		$('#fonds img').each(function(){ fonds.push(this.src); });
		$('#fond').css('background-image', "url('"+fonds[0]+"')");
		setTimeout("cycleFond()", time);
	}
});
