function changeHilite() {
	$('.container-button-widget li a').removeClass('widget-actif').eq(Math.floor(i_prochaine/2)).addClass('widget-actif');
}

$(function() {		  

	// ------ Menu deroulant --------------------------------------------------------------
	
    $('#top-menu li').mouseover(function() {
        $(this).find('ul:not(.sous-sous-menu)').stop(true, true).slideDown(300, 'swing');
    });
    $('.sous-menu li').mouseover(function() {
        $(this).find('ul').stop(true, true).slideDown(400, 'swing');
    });
    $('#top-menu li').mouseleave(function() {
        $(this).find('ul').slideUp(200, 'swing');
    });
    $('.sous-menu').mouseleave(function() {
        $(this).slideUp(200, 'swing');
    });	
	

	
	// ------- Widget slider accueil ---------------------------------------------------------------------------
	
	total = $('#widget-home .container-photo img').size();

	function initIndex() {
		i_active = $('#widget-home div.active').index()-1;
		i_prochaine = $('#widget-home div.prochaine').index()-1;
	}
	

	function rouleWidget() {
		
		//$("#deboog").prepend("act:"+i_active+" proch:"+i_prochaine+" prec:"+i_precedente+" clic:"+i+"<br>");
			
		future_prochaine = i_prochaine+1;
		if(future_prochaine == total) future_prochaine=0;

		$('#widget-home div.active').fadeOut(750, function() {												   
			$('#widget-home div.active').removeClass('active').hide();														   
			$('#widget-home div.prochaine').removeClass('prochaine').addClass('active');
			$('#widget-home div.container-photo').eq(future_prochaine).addClass('prochaine');
			//$('.container-button-widget li.active').removeClass('active');
			//$('.container-button-widget li').eq(Math.floor(i_prochaine/2)).addClass('active');
		});
		$('#widget-home div.prochaine').fadeIn(750);
		
		if( Math.floor(i_prochaine/2)+1 != Math.floor(future_prochaine/2) && i_prochaine!=total-1 ) {
			//$('.container-button-widget li.active').removeClass('active');
			$('.container-button-widget li').animate({
				backgroundPosition : 280+"px 0px"
			},375);
			$('.container-button-widget li').eq(Math.floor(i_prochaine/2)).animate({
				backgroundPosition : 320+"px 0px"
			},375);
			setTimeout('changeHilite()', 375);
		}

		clearInterval(play);
		
		play = setInterval(function(){ 
			initIndex();
			rouleWidget();
        }, 3250); //Timer speed in milliseconds

	};

	rotateSwitch = function(){
        play = setInterval(function(){ 
			initIndex();
			rouleWidget();
        }, 3250); //Timer speed in milliseconds
    };
	
	
	if( $.browser.mozilla ) { // Firefox bug qith queuing SetIntrvals when Alt-Tabbed
		window.addEventListener('focus', function() {
			play = setInterval(function(){ 
				initIndex();
				rouleWidget();
			}, 3250); //Timer speed in milliseconds
		},false);    
		window.addEventListener('blur', function() {
			window.clearInterval(play);
		},false);
	} else { 
		rotateSwitch();
	}

	$('#widget-home ul li a').hover(function() {
		$('.container-photo').addClass("cacherHover");
		$('.container-photo').eq( $(this).parent().index()*2 ).removeClass("cacherHover").addClass('activeHover').css({'display':'block'}); 
	},function() {
		$('#widget-home .cacherHover').removeClass("cacherHover");
		$('#widget-home .activeHover').removeClass("activeHover").css({'display':'none'});
		$('#widget-home .active').css({'display':'block'});
		$('#widget-home .prochaine').css({'display':'none'});
	});
	
	// ---- FAQ --------------------- //
	
	$('#faq a.question').click(function() {
		i = $('#faq a.question').index(this);
		$('div.reponse').eq(i).toggle();
		if( $('#faq a.question').eq(i).hasClass('closed') ) {
			$('#faq a.question').eq(i).addClass('open').removeClass('closed');
		} else {
			$('#faq a.question').eq(i).addClass('closed').removeClass('open');
		}
		return false;
	});

	// ------- Modale Panier ---------------------------------------------------------------------------
	
	var langue_page = $('#langue_page').val();
	var txt_ajout = 'Ajout au panier';
	if (langue_page == 'en') txt_ajout = 'Add to cart';
	
	$("#confirmation_ajout_pannier").dialog({
		bgiframe: true,
		width: 450,
		modal: true,
		autoOpen : false,
		draggable : false,
		resizable : false,
		title : txt_ajout
		
	});
	
	
	
	$('.ajoutePanier').click( function() {
			$.ajax({
			        type: "POST",
			        url: 'ajax/ajout_panier.php?' + $(this).attr('name'),
			        timeout: 2000,
			        dataType: 'html',
			        success:  function(data) {
							
						$('#confirmation_ajout_pannier').html(data);						
						$('#confirmation_ajout_pannier').dialog('open');
						
						if( $(data).text().indexOf('ERREUR')==-1 ) {
							NbItemsPanier++;
							strHtml = new String( $("#confirmation_ajout_pannier").html() );
							splitted = strHtml.split("__prix__");
							totalPanier = totalPanier+splitted[1]*1;
							$('#qtePanier').text(NbItemsPanier);
							$('#totalPanier').text(totalPanier);
							//$('.ajoutePanier').attr("disabled","true");
						};
			}
			});
			
			

	

		if( "undefined" != typeof(event) ) event.returnValue = false; 
		return false;
	});
	
	// -------- Onglets dans une page d'UN produit ------------------------------ 
	
	$("ul#onglets li").click(function() {
		$("div.info-sous-onglet:visible").hide();
		$("div.info-sous-onglet").eq( $(this).index() ).show();
		$("ul#onglets li.actif").removeClass('actif');
		$(this).addClass('actif');
		return false;
	});
	
});
