$(document).ready(function(){
	wP = $("#promo ul li.fiche_prod_promo").size()*200;
	$("#promo ul.uldep").css("width",wP+"px");
	wP2 = $("#articles ul li.fiche_prod_article").size()*176;
	$("#articles ul.prod_moment").css("width",wP2+"px");
	wP3 = $("#complement ul li.fichettes").size()*175;
	$("#complement ul").css("width",wP3+"px");
	// Déplacement des promotions
	$("#promo .bt_promo_right").click(function(){
		leng = $("#promo_in ul.uldep").css("margin-left").length;
		minL = $("#promo_in ul.uldep").css("margin-left").substr(0,leng-2);
		if(minL > -wP+600){
			$("#promo_in ul.uldep").animate({
				marginLeft:	'-='+600+"px"
			});
		}
	});
	$("#promo .bt_promo_left").click(function(){
		leng = $("#promo_in ul.uldep").css("margin-left").length;
		minL = $("#promo_in ul.uldep").css("margin-left").substr(0,leng-2);
		if(minL < 0){
			$("#promo_in ul.uldep").animate({
				marginLeft:	'+='+600+"px"
			});
		}									   
	});
	// Déplacement des offres du moment
	$("#articles .bt_articles_right").click(function(){
		leng = $("#articles_in ul.prod_moment").css("margin-left").length;
		minL = $("#articles_in ul.prod_moment").css("margin-left").substr(0,leng-2);
		if(minL > -wP2+880){
			$("#articles_in ul.prod_moment").animate({
				marginLeft:	'-='+880+"px"
			});
		}
	});
	$("#articles .bt_articles_left").click(function(){
		leng = $("#articles_in ul.prod_moment").css("margin-left").length;
		minL = $("#articles_in ul.prod_moment").css("margin-left").substr(0,leng-2);
		if(minL < 0){
			$("#articles_in ul.prod_moment").animate({
				marginLeft:	'+='+880+"px"
			});
		}									   
	});
	// Déplacement "Autres produits :"
	$("#complement .bt_articles_right").click(function(){
		leng = $("#fichettes_in ul").css("margin-left").length;
		minL = $("#fichettes_in ul").css("margin-left").substr(0,leng-2);
		if(minL > -wP3+875){
			$("#fichettes_in ul").animate({
				marginLeft:	'-='+875+"px"
			});
		}
	});
	$("#complement .bt_articles_left").click(function(){
		leng = $("#fichettes_in ul").css("margin-left").length;
		minL = $("#fichettes_in ul").css("margin-left").substr(0,leng-2);
		if(minL < 0){
			$("#fichettes_in ul").animate({
				marginLeft:	'+='+875+"px"
			});
		}									   
	});
	// Calendrier HOME
	$("#potager").click(function(){
		$("#ornements").removeClass("actif");
		$(".ornements").css("display","none");
		$(this).addClass("actif");
		$(".potager").css("display","block");
		return false;
	});
	$("#ornements").click(function(){
		$("#potager").removeClass("actif");
		$(".potager").css("display","none");
		$(this).addClass("actif");
		$(".ornements").css("display","block");
		return false;
	});
	/* MENU */
	$('#fond_0 .open').each(function () {
		var time = 200;
		var hideDelay = 200;
		var hideDelayTimer = null;
		var beingShown = false;
		var shown = false;
		var trigger = $(this);
		var info= $(".sfond_0",this);
		$(trigger).mouseover(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown) {
				// don't trigger the animation again
				return;
			} else {
				// reset position of info box
				beingShown = true;
				info.css("display","block");
				beingShown = false;
				shown = true;
					/*$(this).animate({
						marginTop: '+='+decal+"px"
					},delay, function() {
						beingShown = false;
						shown = true;
					});*/
			}
			return false;
		}).mouseout(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				info.css("display","none");
				shown = false;
					/*$(this).animate({
						marginTop: '-='+decal+"px",
						opacity: 0,
						filter:''
					},200, function () {
						shown = false;
						$(this).css('display', 'none');
					});*/
			}, hideDelay);
			return false;
		});
	});
	$('#fond_1 .open').each(function () {
		var time = 200;
		var hideDelay = 200;
		var hideDelayTimer = null;
		var beingShown = false;
		var shown = false;
		var trigger = $(this);
		var info= $(".sfond_1",this);
		$(trigger).mouseover(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			if (beingShown || shown) {
				return;
			} else {
				beingShown = true;
				info.css("display","block");
				beingShown = false;
				shown = true;
			}
			return false;
		}).mouseout(function () {
			if (hideDelayTimer) clearTimeout(hideDelayTimer);
			hideDelayTimer = setTimeout(function () {
				hideDelayTimer = null;
				info.css("display","none");
				shown = false;
			}, hideDelay);
			return false;
		});
	});
	/*AFFICHAGE DU MINI PANIER*/
	var time = 200;
	var hideDelay = 200;
	var hideDelayTimer = null;
	var beingShown = false;
	var shown = false;
	var trigger = $("#header_top .panier a.achat");
	var info= $("#header_top #panier_mini",this);
	$([trigger.get(0), info.get(0)]).mouseover(function () {
		if (hideDelayTimer) clearTimeout(hideDelayTimer);
		if (beingShown || shown) {
			// don't trigger the animation again
			return;
		} else {
			// reset position of info box
			beingShown = true;
			info.css("display","block");
			beingShown = false;
			shown = true;
				/*$(this).animate({
					marginTop: '+='+decal+"px"
				},delay, function() {
					beingShown = false;
					shown = true;
				});*/
		}
		return false;
	}).mouseout(function () {
		if (hideDelayTimer) clearTimeout(hideDelayTimer);
		hideDelayTimer = setTimeout(function() {
			hideDelayTimer = null;
			info.css("display","none");
			shown = false;
				/*$(this).animate({
					marginTop: '-='+decal+"px",
					opacity: 0,
					filter:''
				},200, function () {
					shown = false;
					$(this).css('display', 'none');
				});*/
		}, hideDelay);
		return false;
	});
	var timeA = 200;
	var hideDelayA = 200;
	var hideDelayTimerA = null;
	var beingShownA = false;
	var shownA = false;
	var triggerA = $("#header_top .mon_compte .account");
	var infoA= $("#header_top .mon_compte #dpop");
	$([triggerA.get(0), infoA.get(0)]).mouseover(function () {
		if (hideDelayTimerA) clearTimeout(hideDelayTimerA);
		if (beingShownA || shownA) {
			return;
		} else {
			beingShownA = true;
			infoA.css("display","block");
			beingShownA = false;
			shownA = true;
		}
		return false;
	}).mouseout(function () {
		if (hideDelayTimerA) clearTimeout(hideDelayTimerA);
		hideDelayTimerA = setTimeout(function() {
			hideDelayTimerA = null;
			infoA.css("display","none");
			shownA = false;
		}, hideDelayA);
		return false;
	});
	$('.ref_fiche select').each(function(){
		$(this).change(function(){
			aff = $(this).getSetSSValue();
			for(j=0;j<20;j++){
				if(j==aff){
					$(this).parent().parent().children(".ref_bis_"+aff).css("display","block");
					$(this).parent().parent().children(".ref_ter_"+aff).css("display","block");	
				}else{
					$(this).parent().parent().children(".ref_bis_"+j).css("display","none");
					$(this).parent().parent().children(".ref_ter_"+j).css("display","none");
				}
			}	
		});									 
	});
	/* PANIER BOUTONS */	
	$("#thepanier .moins").click(function(){
		n=$(this).attr('id').substring(5);
		cible="#thepanier #qte"+n;
		$(cible).val(Number($(cible).val())-1);
		// $("#panierform").submit();
	});
	$("#thepanier .plus").click(function(){
		n=$(this).attr('id').substring(4);
		cible="#thepanier #qte"+n;
		$(cible).val(Number($(cible).val())+1);
		// $("#panierform").submit();
	});
	$("#thepanier .qte").change(function(){
		 v=$(this).val();
		  if(Number(v)<1){
			  $(this).val(0);
		  }
		// $("#panierform").submit();
 	});	
	$("#thepanier .suppr").click(function(){
		n=$(this).attr('id').substring(5);
		cible="#thepanier #qte"+n;
		$(cible).val(Number(0));
		$("#panierform").submit();
	});
	$("#noclient .insc").click(function(){
		$("#form_insc").css("display","block");
	});
	$(".modif_coord").click(function(){
		$("#divcoordclient").css("display","block");
	});
	/* AFFICHAGE DES CARACTERISTIQUES */
	if($.trim($("#contenu ul.detail").html()) == ""){
		$("#contenu h3.hidd").css("display","none");
	}
	$('.sfond_0').each(function(){
		if($("ul",this).size() == 1){
			$("ul",this).css("max-width","500px");	
		}
	});
	$("#complet .text").each(function(){
		$(this).css("min-height", $(this).prev('.img_calendrier').height());
		$(this).css("display","block");
	});
	
	
	$('.checkarticle').click(function(){
		$("#panierform").submit();
	})
	
	$('.deletecheckarticle').click(function(){
		// alert("poutaing")
		$("#panierform").submit();
	})
});
$(window).load(function(){
	for(i=0;i<200;i++){
		$('#my-dropdown'+i).sSelect({ddMaxHeight: '100px'});
	}
	$("#panier .add_cart").click(function(){
		$('#addpanier').submit();
		return false;
	});
	$("#panier .add_panier").click(function(){
		$(this).parent("#panier").children().children("form").submit();
		$(this).parent().parent("#panier").children().children("form").submit();
		return false;
	});
	$("#formident .bt_cal").click(function(){
		$('#formident').submit();
		return false;
	});
	$("#idem_livr").click(function(){
		$("#livraison").toggleClass('cache');
	});
	$("#nav .bt_0").click(function(){
		$("#fond_1").addClass('invisible');
		$("#nav .bt_1").addClass('fermer').removeClass('ouvert');
		$(this).addClass('ouvert').removeClass('fermer');
		$("#fond_0").removeClass('invisible');
	});
	$("#nav .bt_1").click(function(){
		$("#fond_0").addClass('invisible');
		$("#nav .bt_0").addClass('fermer').removeClass('ouvert');
		$(this).addClass('ouvert').removeClass('fermer');
		$("#fond_1").removeClass('invisible');
	});
	$("#dpop .bt_in").click(function(){
		$(this).parent("form").submit();								 
	});
	if($("input:checkbox").size()>0 && $('input', '.decrochage').attr('class') != 'viewlivraison') $("input:checkbox").uniform();
	
	
	
		$("#form_recherche_").submit(function(){
			// alert('Handler for .submit() called.');
			var string='';
			if($(".checked").size()>0){
				string = string + 'couleur';
				$(".checked").each(
				  function(a){
					// alert($('input',$(this)).val())
					string = string + '-' +$('input',$(this)).val();
				  }
				);
			}

			if($("#my-dropdown177").val() != 0) string = string + ' floraison-' +$("#my-dropdown177").val()
			if($("#my-dropdown178").val() != 0) string = string + ' plantation-' +$("#my-dropdown178").val()
			// alert(string)
			$("#la_recherche_").val(string);
			
			v=$("#la_recherche_",this).val()
			var reg =/\s|,|-|'/g;
			v=v.replace(reg,"-");
			 v="recherches-"+v+".html"
			 // alert(v)
			 self.location.href=v;
				 
			return false;
			// return true;
		});
		
		// RECHERCHE
			$("#motsearch").submit(function() {
				v=$("#la_recherche",this).val()
				var reg =/\s|,|-|'/g;
				v=v.replace(reg,"-");
				v = noaccent(v);
				 v="recherche-"+v+".html"
				 // alert(v)
				 self.location.href=v;
				 return false;
			});
	

		
	
});

function noaccent(chaine) {
  temp = chaine.replace(/[àâä]/gi,"a");
  temp = temp.replace(/[éèêë]/gi,"e");
  temp = temp.replace(/[îï]/gi,"i");
  temp = temp.replace(/[ôö]/gi,"o");
  temp = temp.replace(/[ùûü]/gi,"u");
  temp = temp.replace(/[ç]/gi,"c");
  return temp;
}


	function lookup(inputString) {
		if(inputString.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').hide();
		} else {
			$.post("ajax_panier.php", {queryString: ""+inputString+""}, function(data){
				if(data.length >0) {
					$('#suggestions').show();
					$('#autoSuggestionsList').html(data);
				}
			});
		}
	} // lookup
	
	function fill(thisValue) {
		$('#inputString').val(thisValue);
		setTimeout("$('#suggestions').hide();", 200);
	}
