//Gestion conflit avec autres librairies
	jQ = jQuery.noConflict();



jQuery(document).ready(function() {
	var loginTimer;
	//onglet connexion
    jQ("li.lienConnecter").mouseenter( function(){
        clearTimeout(loginTimer);
        jQ(".blockConnexion").show();
        jQ(this).addClass('over');
	}).mouseleave( function(){
        var lien = this;
        loginTimer = setTimeout(function() {
            jQ(".blockConnexion").hide();
            jQ(lien).removeClass('over');
        }, 700);
	});
	
	//menu XXL
	var heightBody = 0;
	heightBody = jQ("body").height();
	jQ("#zoneGrisee").css({"height":heightBody+"px"});
	var myTimeout;
	var ceLI;
	
	jQ(".menuVert li.menuV").hover( function(){
		ceLI = jQ(this);
		ceMenuXXl = jQ(this).children(".menuXXL");
		ceHoverMenu = jQ(this).children(".hoverMenu");
		ceMenuXXl.removeClass("ouvert");
		ceHoverMenu.removeClass("ouvert");
		clearTimeout(myTimeout);
		myTimeout = setTimeout(function() {
			jQ(".menuXXL").stop(false,true);
			jQ(".hoverMenu").stop(false,true);
			jQ(".menuVert li.menuV").addClass("separateurNone");
			jQ(".MenuMarron li.menu2").addClass("separateurNone");
			jQ(".ouvert").fadeOut('fast', function(){
				jQ(this).parent("li").css({"position":"relative"});
			});
			ceLI.css({"position":"static"});
			jQ(".iframe_select").css({"z-index":"1"});
			ceLI.removeClass("separateurNone");
			ceMenuXXl.fadeIn();
			ceHoverMenu.fadeIn();
			jQ("#zoneGrisee").show();
			
		}, 250);
	},function(){
		ceMenuXXl2 = jQ(this).children(".menuXXL");
		ceHoverMenu2 = jQ(this).children(".hoverMenu");
		ceMenuXXl2.addClass("ouvert");
		ceHoverMenu2.addClass("ouvert");
		clearTimeout(myTimeout);
		myTimeout = setTimeout(function() {
			jQ(".menuXXL").stop(false,true);
			jQ(".hoverMenu").stop(false,true);
			jQ("#zoneGrisee").hide();
			jQ(".menuVert li.menuV").removeClass("separateurNone");
			jQ(".MenuMarron li.menu2").removeClass("separateurNone");
			ceMenuXXl2.fadeOut('fast');
			ceHoverMenu2.fadeOut('fast');
			jQ(".ouvert").fadeOut('fast');
			jQ(".iframe_select").css({"z-index":"-1"});
			
		}, 500);
	});	
	
	//menu XXL marron
	jQ(".MenuMarron li.menu2").hover( function(){
		ceLI = jQ(this);
		ceMenuXXl = jQ(this).children(".menuXXL");
		ceHoverMenu = jQ(this).children(".hoverMenu");
		ceMenuXXl.removeClass("ouvert");
		ceHoverMenu.removeClass("ouvert");
		clearTimeout(myTimeout);
		myTimeout = setTimeout(function() {
			jQ(".menuXXL").stop(false,true);
			jQ(".hoverMenu").stop(false,true);
			jQ(".menuVert li.menuV").addClass("separateurNone");
			jQ(".MenuMarron li.menu2").addClass("separateurNone");
			jQ(".ouvert").fadeOut('fast', function(){
				jQ(this).parent("li").css({"position":"relative"});
			});
			ceLI.css({"position":"static"});
			jQ(".iframe_select").css({"z-index":"1"});
			ceLI.removeClass("separateurNone");
			ceMenuXXl.fadeIn();
			ceHoverMenu.fadeIn();
			jQ("#zoneGrisee").show();
		}, 250);
	},function(){
		ceMenuXXl2 = jQ(this).children(".menuXXL");
		ceHoverMenu2 = jQ(this).children(".hoverMenu");
		ceMenuXXl2.addClass("ouvert");
		ceHoverMenu2.addClass("ouvert");
		clearTimeout(myTimeout);
		myTimeout = setTimeout(function() {
				jQ(".menuXXL").stop(false,true);
				jQ(".hoverMenu").stop(false,true);
				jQ("#zoneGrisee").hide();
				jQ(".iframe_select").css({"z-index":"-1"});
				jQ(".menuVert li.menuV").removeClass("separateurNone");
				jQ(".MenuMarron li.menu2").removeClass("separateurNone");
				ceMenuXXl2.fadeOut('fast');
				ceHoverMenu2.fadeOut('fast');
				jQ(".ouvert").fadeOut('fast');
		}, 500);
	});	
	
	//choix panier
	/*jQ(".survolPanier").hover( function(){
		// jQ(".PanierDeroule").stop(false,true);
		if (!jQ(".PanierDeroule").is(":animated")){
			jQ("ul.MenuMarron li.menu2").css({"position":"static"});
			jQ(".ombreHautPanier").show();
			jQ(".PanierDeroule").slideDown();
		}
	},function(){
		jQ(".PanierDeroule").stop(false,true);
		// if (!jQ(".PanierDeroule").is(":animated")){
			jQ(".PanierDeroule").slideUp( function(){
				jQ("ul.MenuMarron li.menu2").css({"position":"relative"});
				jQ(".ombreHautPanier").hide();
			});
		// }
	});*/
	jQ(".survolPanier").live('mouseenter', function(){
		if (!jQ(".PanierDeroule").is(":animated")){
			jQ("ul.MenuMarron li.menu2").css({"position":"static"});
			jQ(".ombreHautPanier").show();
			jQ(".PanierDeroule").slideDown();
		}
	});
	jQ(".survolPanier").live('mouseleave', function(){
		jQ(".PanierDeroule").stop(false,true);
		jQ(".PanierDeroule").slideUp( function(){
			jQ("ul.MenuMarron li.menu2").css({"position":"relative"});
			jQ(".ombreHautPanier").hide();
		});
	});
	
	
	
	//choix critere
	jQ(".ElementsSelection li").hover( function(){
		jQ(this).children(".listeElemCritere").stop(false,true);
		jQ(".iframe_select").css({"z-index":"1"});
		jQ(this).children(".listeElemCritere").fadeToggle("fast");
	},function(){
		jQ(this).children(".listeElemCritere").stop(false,true);
		jQ(this).children(".listeElemCritere").fadeToggle("fast");
		jQ(".iframe_select").css({"z-index":"-1"});
	});
	
	//choix langue 01
	jQ(".choixLangue").click( function(){
		jQ(this).next(".choixLangueListe").stop(false,true);
		jQ(this).next(".choixLangueListe").slideDown();
	});
	
	//choix langue 02
	jQ(".choixLangueListe div a").click( function(){
		varLang = jQ(this).attr("class");
		varSrcLang = jQ(this).children("img").attr("src");
		jQ(".choixLangue img").attr("src",varSrcLang);
		jQ(".langueActuelle").val(varLang);
		jQ(".choixLangueListe").slideUp();
	});
	
	//choix langue 03
	jQ(".choixLangueListe").mouseleave( function(){
		jQ(this).stop(false,true);
		jQ(".choixLangueListe").slideUp();
	});
	
	//menu colonne gauche
	jQ(".categorieSpe").click( function(){
		if(!jQ(this).is(".catActive")) {
			jQ(this).next("ul").stop();
			jQ(this).next("ul").slideDown();
			jQ(".catActive").next("ul").slideUp();
			jQ(".categorieSpe").removeClass('catActive');
			jQ(this).addClass('catActive');
		}
	});
	
    //sous-menu colonne gauche
	jQ(".categorieSpe2").click( function(){
		if(!jQ(this).is(".catActive2")) {
			jQ(this).next("ul").stop();
			jQ(this).next("ul").slideDown();
			jQ(".catActive2").next("ul").slideUp();
			jQ(".categorieSpe2").removeClass('catActive2');
			jQ(this).addClass('catActive2');
		}
	});
	jQ(".categorieSpe2 a").click(function(e) {
		e.preventDefault();
	});
    
	jQ(".affichageOnglet").hide();
	jQ(".affichageOnglet").eq(0).show();
	
	//changement onglet
	jQ(".onglets li span").click( function(){
		if(!jQ(this).is(".active")) {
			var nbElemOnglet = jQ(this).index(".onglets li span");
			jQ(".onglets li").removeClass("active");
			jQ(this).parent().parent().parent("li").addClass("active");
			jQ(".onglets li").removeClass("special");
			jQ(".onglets li").eq(nbElemOnglet+1).addClass("special");
			jQ(".affichageOnglet").hide();
			jQ(".affichageOnglet").eq(nbElemOnglet).show();
		}
	});
    jQ(".categorieSpe2 a").click(function(e) {
		e.preventDefault();
	});
	
	jQ(".contenanceOption").parent().change(function(){
		jQ(".contenanceColor").hide();
		jQ(".c"+jQ(this).val()).show();
		jQ(".active").removeClass("active");
		jQ(".c"+jQ(this).val()+":first").addClass("active"); 
		jQ(".prixTotal").html(jQ(".c"+jQ(this).val()+":first").children(".hideprice").html());
		jQ("#contenanceExpresse").val(jQ(".c"+jQ(this).val()+":first").children('.hidecontenance').val());
		jQ("#colorExpresse").val(jQ(".c"+jQ(this).val()+":first").children('.hidecolor').val());
	});

	/*change image*/
	jQ(".pageProduitCondiList a.typeCond").mouseenter(function(){
	    jQ(".conditionmentImageSelected").hide();
	    jQ(".imgc"+jQ(this).children('input').val()+":first").show();
	});
	
	/*change image*/
	jQ(".blockCondi a.typeCond").mouseleave(function(){
	    jQ(".conditionmentImage").hide();
	    jQ(".conditionmentImageSelected").show();
	});
	
	/*change image*/
	jQ(".smallImageMain").click(function(){
	    jQ(".smallImageMain").hide();
	    jQ(".conditionmentImageSelected").hide();
	    jQ(".conditionmentImageSelected").removeClass("conditionmentImageSelected");
	    jQ(".largeImageMain").addClass("conditionmentImageSelected");
	    jQ(".largeImageMain").show();
	});

	/*click conditionment Image*/
	jQ(".pageProduitCondiList a.multiCond").click(function(){
	    
		/*image part*/
	    jQ(".conditionmentImageSelected").hide();		
	    jQ(".conditionmentImageSelected").removeClass("conditionmentImageSelected");
	    jQ(".imgc"+jQ(this).children('input').val()+":first").show();
	    jQ(".imgc"+jQ(this).children('input').val()+":first").addClass("conditionmentImageSelected");
	    jQ(".smallImageMain").css('display','block');//show();
	    
	    /*active elem part*/
	    jQ("a.typeCond").removeClass("active");
	    jQ("a.typeCoul").removeClass("active");
		jQ(this).addClass("active");
	    
	    
	    /*volume part*/
	    jQ(".divSelectVolume").hide(); 
	    jQ(".c"+jQ(this).children('input').val()).show();
	    //jQ(".selectCondi").children(".selector").children("span").html(jQ(".oc"+jQ(this).children('input').val()+":first").html());
	    
	    jQ(".volumeConditionmentSelect").val(jQ("#conditionmentVolumeCart").val());
	    jQ(".volumeConditionmentSelect").change();
	    	    
	    /*input part*/ 
	    jQ("#conditionmentCart").val(jQ(this).children('input').val());
	    jQ("#conditionmentVolumeCart").val(jQ(".oc"+jQ(this).children('input').val()+":selected").val());
	    
	    /*change price*/
	    jQ(".prixUnitaire").html(jQ(".prix-" +jQ("#conditionmentCart").val()+"-"+jQ("#conditionmentVolumeCart").val()).html());
	    
	    jQ('.conditionmentSKU').hide();
	    jQ(".sku-" +jQ(this).children('input').val()+"-"+jQ(".oc"+jQ(this).children('input').val()+":selected").val()).show();
	    
	    jQ('.ajoutPanier').attr('onClick',"ajaxAddToCart();_gaq.push(['_trackEvent','achat','ajout_panier','page-produit', '"+jQ(".onclick-" +jQ(this).children('input').val()+"-"+jQ(".oc"+jQ(this).children('input').val()+":selected").val()).html()+"']);return false;");
	    /**jQ("select").each( function(){
	    	jQ(this).val( jQ(this).children("first").val() );
	    });*/
	});
	
	jQ(".pageProduitCondiList a.typeCoul").click(function(){
		/*autreinfo part*/
	    jQ(".autresInfosProd .txtDetails .info").hide();
	    jQ(".autresInfosProd .txtDetails .cont"+jQ("#conditionmentVolumeCart").val()).show();
	});
	
	/*click on volume */
	jQ(".volumeOption").parent().change(function(){ 
		jQ("#conditionmentVolumeCart").val(jQ(this).val());
		jQ(".prixUnitaire").html(jQ(".prix-" +jQ("#conditionmentCart").val()+"-"+jQ("#conditionmentVolumeCart").val()).html());
		
		jQ('.conditionmentSKU').hide();
		jQ("span.sku-" +jQ("#conditionmentCart").val()+"-"+jQ("#conditionmentVolumeCart").val()).show();
  	        jQ('.ajoutPanier').attr('onClick',"ajaxAddToCart();_gaq.push(['_trackEvent','achat','ajout_panier','page-produit', '"+jQ(".onclick-" +jQ("#conditionmentCart").val()+"-"+jQ("#conditionmentVolumeCart").val()).html()+"']);return false;");
	});
	
	jQ(".changeSize").parent().change(function(){
		jQ(".autresInfosProd .txtDetails .info").hide();
		jQ(".autresInfosProd .txtDetails .cont"+jQ(this).val()).show();
	});
	
	/*grand crus option change*/
	jQ("#grandCruSelect").change( function(){
		jQ(".prixUnitaire").hide();
		jQ(".tv"+jQ(this).val()).show();
                jQ('.ajoutPanier').attr('onClick',"ajaxAddToCart();_gaq.push(['_trackEvent','achat','ajout_panier','page-produit', '"+jQ(".sku"+jQ(this).val()).html()+"']);return false;");		
	});
	
	var valQte;
	
	jQ(".qteMoins").click( function(){
		valQte = jQ(this).parent().children().children("input").val();
		valQte--;
		if(valQte > 0) {
			jQ(this).parent().children().children("input").val(valQte);
		}
	});
	
	jQ(".qtePlus").click( function(){
		valQte = jQ(this).parent().children().children("input").val();
		valQte++;
		if(valQte > 0) {
			jQ(this).parent().children().children("input").val(valQte);
		}
	});
	
	/*update cart*/
	jQ(".updateCartLink").click( function(){
		jQ('#updateCart').submit();
	});
	
	//slider basique
	jQ("#slider").easySlider({speed:800});
	jQ("#slider2").easySlider({numSlider:2,speed:800});
	jQ("#slider3").easySlider({numSlider:8,nbElements:2,speed:800});
	jQ("#slider4").easySlider({numSlider:9,nbElements:2,speed:800});
	jQ("#slideProduits1").easySlider({numSlider:3,nbElements:7,speed:600});
	jQ("#slideProduits2").easySlider({numSlider:4,nbElements:7,speed:600});
	jQ("#slideProduits3").easySlider({numSlider:5,nbElements:7,speed:600});
	jQ("#slideProduits4").easySlider({numSlider:6,nbElements:7,speed:600});
	jQ("#slideProduits5").easySlider({numSlider:7,nbElements:7,speed:600});
	jQ("#slideProduits6").easySlider({numSlider:3,nbElements:9,speed:600,controlsShow:false});
	jQ("#slideProduits7").easySlider({numSlider:4,nbElements:9,speed:600});
	jQ("#slideProduits8").easySlider({numSlider:5,nbElements:5,speed:600,controlsShow:false});
	jQ("#slideProduits9").easySlider({numSlider:6,nbElements:6,speed:600,controlsShow:false});
	jQ("#slideProduits10").easySlider({numSlider:7,nbElements:7,speed:600,controlsShow:false});
	
	/****** SLIDE NUMEROTE 1  ******/
	
	//Set Default State of each portfolio piece
	jQ(".paging").show();
	jQ(".paging a:first").addClass("active");
		
	//Get size of images, how many there are, then determin the size of the image reel.
	var elementsNb = jQ(".image_reel ul li").size();
	var imageWidth = jQ(".image_reel ul li").width()+10;
	var imageReelWidth = imageWidth * elementsNb;
	
	//Adjust the image reel to its new size
	jQ(".image_reel").css({'width' : imageReelWidth});

	
	//Paging + Slider Function
	rotate = function(){
		var triggerID = $active.attr("rel") - 1; //Get number of times to slide
		var image_reelPosition = triggerID * imageWidth; //Determines the distance the image reel needs to slide

		jQ(".paging a").removeClass('active'); //Remove all active class
		$active.addClass('active'); //Add active class (the $active is declared in the rotateSwitch function)
		
		//Slider Animation
		jQ(".image_reel").animate({ 
			left: -image_reelPosition
		}, 500 );
		
	}; 
	
	//Rotation + Timing Event
	rotateSwitch = function(){		
		play = setInterval(function(){ //Set timer - this will repeat itself every 3 seconds
			$active = jQ('.paging a.active').next();
			if ( $active.length === 0) { //If paging reaches the end...
				$active = jQ('.paging a:first'); //go back to first
			}
			rotate(); //Trigger the paging and slider function
		}, 7000); //Timer speed in milliseconds (3 seconds)
	};
	
	//rotateSwitch(); //Run function on launch
	
	
	//On Click
	jQ(".paging a").click(function() {	
		$active = jQ(this); //Activate the clicked paging
		//Reset Timer
		// clearInterval(play); //Stop the rotation
		rotate(); //Trigger rotation immediately
		// rotateSwitch(); // Resume rotation
		return false; //Prevent browser jump to link anchor
	});
	
	//style form - Uniform
	jQ("select, input:checkbox, input:radio").uniform();
	
	//Shadowbox
	Shadowbox.init();

	function openShadowbox(){
		Shadowbox.open();
	}
	
	//tooltip conditionnement page produit
	jQ('.pageProduit .blockInfosProd a.typeCond').tooltip({ 
		track: true, 
		delay: 0, 
		showURL: false, 
		fade: 250 
	});

	// R�cup�rer la valeur du select (de la page formulaire) et afficher le formulaire ad�quat
	jQ('#formSelect').change(function () {
        v =  jQ("#formSelect option:selected").val();
		id = "#form"+v;
		jQ(".blockForm").css({display:"none"});
        jQ(id).css({display:"block"});
		
    }).trigger('change');
	
	// Lancer le slider de la HomeUS
	jQ('.SliderName_3').each(function (i) {
		var demo3Effect5 = {name: 'myEffect35', delay: 1, duration: 500, fade: true};
		var demoSlider_3 = Sliderman.slider({container: 'SliderName_3', width: 700, height: 291, contentmode: true, effects: demo3Effect5, display: {autoplay: 3000, mousewheel: true, pause: true}});
	});
	
	// Gestion de l'auto-compl�tion du champ recherche
	jQ("#homeSearch").autocomplete("../auto-complete/images.php", {
		width: 255,
		max: 12,
		highlight: false,
		scroll: true,
		scrollHeight: 300,
		formatItem: function(data, i, n, value) {
		return "<div class='content-img'><img src='../images/produits/" + value + "'/></div><div class='content-txt'><div class='content-titre'>" + value.split(".")[0] + "</div><div class='content-prix'>5,50 &euro;</div><div class='content-poids'>LES 100G</div><p class='content-description'>Le Earl Grey est un grand classique anglais d'une grande finesse. est un grand classique anglais.</p></div><div style='clear:both'></div> ";
	},
		formatResult: function(data, value) {
			//retourne le nom du fichier sans l'extension
			return value.split(".")[0];
		}
	}); 
	

	
	// V�rification des formulaires
	//jQ(".validComm").click(function() {
	//	valid = true;
	//	jQ('input[type=text]').each (function (i) {
	//		if(jQ(this).val()=="") {
	//			jQ(this).attr("title","champ en erreur");
	//			jQ(this).tooltip({ 
	//				track: true, 
	//				delay: 0, 
	//				showURL: false, 
	//				fade: 250,
	//				id: "tooltipWrongData"
	//			});
	//			//jQ("#tooltip").attr("id","tooltipWrongData");
	//			valid = false;	
	//		}
	//	});
	//});
	
	//Page listing.html : tooltip sur la fleche d'inversement du tri
	jQ('.trieInverser').tooltip({ 
		track: true, 
		delay: 0, 
		showURL: false, 
		fade: 250 
	});
	
	//Changement de la hauteur des infos suppl�mentaire des formulaires de contact lorsqu'ils sont vides
	jQ('.formContactSelect .infosSuppl').each(function (i) {
		if(jQ(this).text()=="") {
			jQ(this).height(0);
		}
	});
	
	//R�cup�rer la version du navigateur
	var version;
	jQ.each(jQ.browser,function(i,val) {
		version = val;
	});
	if(version < 8) {
		jQ('.ligneCreationCpt div.contentSelect').css('background-position','1px right');
	}
	
	//Gris� les paiements dans tunnel-06
	jQ(".colPaiement").click(function() {
		jQ(".lignePaiement img").css("opacity","0.5");
		jQ(this).find("img").css("opacity","1");
	});
	
	// Gestion des s�lections de listing
	if(jQ(".ElementsSelection").length > 0) {
		var widthLi = jQ(".ElementsSelection li:first").width();
		if(widthLi < 141) {
			jQ(".ElementsSelection li:first .listeElemCritere").css("marginLeft",widthLi - 141);
		}
	}
	
	//Limiter le nombre de caract�re des input Cadeau
	jQ(".inputCadeau").keydown(function (e) {
		if(this.value.length>=69){
			this.value=this.value.substring(0,69);
		}
	});
	jQ(".inputCadeau").keyup(function (e) {
		if(this.value.length>=69){
			this.value=this.value.substring(0,69);
		}
	});

	jQ('.validEmail').click(function() {
		jQ('#confirmInscription').stop(true,true).slideDown(200).delay(2000).slideUp(200);
		return false;
	});
	
	if(jQ("#blocMag1").length > 0 && jQ("#blocMag2").length > 0 && jQ("#blocMag3").length > 0) {
		var maxHeight = 0;
		maxHeight = jQ("#blocMag1").height();
		
		if(jQ("#blocMag2").height() > maxHeight) {
			maxHeight = jQ("#blocMag2").height();
		}
		if(jQ("#blocMag3").height() > maxHeight) {
			maxHeight = jQ("#blocMag3").height();
		}
		
		jQ("#blocMag1").height(maxHeight);
		jQ("#blocMag2").height(maxHeight);
		jQ("#blocMag3").height(maxHeight);
	}
});
