// JavaScript Document



  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-766187-4']);
  _gaq.push(['_trackPageview']);


$(function() {
		//selectcat(document.forms["searchannu"].elements["categorie"].value);
		
		/****google analytics***/
		
		
		 var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		 ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		 var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);		
		

		$("form[name=formsearch] input[name=motscles]").click(function() { //supprime le chps de recherche
			
			if($("form[name=formsearch] div").css("display")=="block"){
					$("form[name=formsearch] div").slideUp("fast");
				}else{
					$("form[name=formsearch] div").slideDown("fast");
					
				}
			
			
			
			if($("form[name=formsearch] input[name=motscles]").val()=="Recherche un producteur" || $("form[name=formsearch] input[name=motscles]").val()=="Recherche un produit"){
				$("form[name=formsearch] input[name=motscles]").val("");
				
				
			}
		});
		
		
		
		
		
		$("form[name=searchannu] input[name=motscles]").keyup(function() { //copie le chps recerche
			$("form[name=formsearch] input[name=motscles]").val($("form[name=searchannu] input[name=motscles]").val());								 
								
		});
		
		
		$("select#categorie").change(function() {
			var idcat=document.forms["searchannu"].elements["categorie"].value;
			selectcat(idcat);
		});
		

		
		$("div#page").click(function() {$("div.login").slideUp("fast");});
		$("div.slidedown").click(function() {$("div.login").slideUp("fast");});
		$("a.retourpanier").click(function(){$("div#boxpanier").slideUp("fast");});
		
		
		$("div#header td.article").click(function(){location.href='/panier.html';});
		//$("div#header td.compte").click(function(){conecthead();});
		
		
		
		
		
		
		
		$("div.divaide").find("h3").click( function() { //aide deroulante
			
			if($(this).parent("div.divaide").find("div").css("display")=="none" || $(this).parent("div.divaide").find("div").css("display")==""){
				$(this).parent("div.divaide").find("div").slideDown("fast");
				$(this).css("background-image","url(../styles/ma/img/flecheaidedown.gif)");

				
				
			}else{
				$(this).parent("div.divaide").find("div").slideUp("fast");
				$(this).css("background-image","url(../styles/ma/img/flecheaideleft.gif)");
			}
		});		
		
		
	
									   
		
		menuderoulant();
		
		
		
		
		
		
		
		
		
});



function aide(id){
	
	
	/*
	d.innerHTML+="<div id='tooltip"+id+"'></div>";
	if(document.getElementById("tooltip"+id).style.display=="none" || document.getElementById("tooltip"+id).style.display==""){
		
		$("div#tooltip"+id).fadeIn("fast");
		document.getElementById("tooltip"+id).className="loading";
		if(w!=""){document.getElementById("tooltip"+id).style.width=w+"px";}
			$.ajax({
				type: "GET",
				url: "../../inc/xml/xml.help.php?id="+id,
				dataType: "xml",
				success: function(xml) {
					$(xml).find('help').each(function(){
						var titre = $(this).attr('titre');
						var texte = $(this).text();
						document.getElementById("tooltip"+id).innerHTML="<h1>"+titre+":</h1>"+texte;
						document.getElementById("tooltip"+id).className="";
					});
				}
			});
	}else{
		$("div#tooltip"+id).fadeOut("fast");
		document.getElementById("tooltip"+id).style.display="none";
		
	}
	
	*/
	var titre="";
	var texte="";
	
	$.ajax({
				type: "GET",
				url: "../../inc/xml/xml.help.php?id="+id,
				dataType: "xml",
				success: function(xml) {
					$(xml).find('help').each(function(){
						titre = $(this).attr('titre');
						texte = $(this).text();

					});
				
					jQuery.facebox("<div id=\"aide\"><h1>Aide - "+titre+"</h1>"+texte+"</div>");
				
				}
			});
	
	
	
}



function developdiv(id){
	if(document.getElementById(id).style.display=="none"){
		
	}else{
		
		
	}
}




function conecthead(){
	$("div.login").slideDown("fast");
	document.forms["Formlog"].elements["login"].focus();
}



function panierup(id,q,option){
	$("div#boxpanier").slideDown("fast");
	
			$.ajax({
				type: "GET",
				url: "../../inc/xml/xml.panier.php?id="+id+"&q="+q+"&option="+option,
				dataType: "xml",
				success: function(xml) {
					$(xml).find('panier').each(function(){
						var qte = $(this).find('q').text();
						var prix = $(this).find('prix').text();
						$("span#panierheader").html(qte+" articles<br />"+prix+" &euro;");
						$("#boxpanier b.nbr").html(q);
					
					});
				}
			});
	
	
	
}



function countcar(input,id,maxx){
	
	
	
	if(input.value.length>0){
		$("#"+id).fadeIn("fast");
		document.getElementById(id).innerHTML=input.value.length;
		if(maxx<input.value.length){
			document.getElementById(id).style.color="#FF0000";
			
		}else{
			document.getElementById(id).style.color="";
		}
	
	}else{
		document.getElementById(id).innerHTML="";
		$("#"+id).fadeOut("fast");
	}
	
}

function popup(p,w,h){
	window.open(p,"Bondecommande","width="+w+",height="+h+",scrollbars=yes");
	
}



function menuderoulant(){
	var ssmenuleft=new Array();
	switch($("input[name=menuannuaire]").val()){
		case "0" :  ssmenuleft = ['0','42' , '150' , '256' , '370' , '430' , '518' , '620' , '728']; break; //vente
		case "1" :  ssmenuleft = ['0','42' , '150' , '256' , '370' , '430' , '518' , '620' , '728']; break; //annuaire
	}
	
	
	$("ul#menu").each(function(){
		
		$(this).find("ul").css("display","none");	
		
		$(this).find("li").mouseover(function(){
			$(this).find("ul").css("display","block");
			//alert($(this).attr("rel"));
			$(this).find("ul").attr({style:"margin-left:"+ssmenuleft[$(this).attr("rel")]+"px"});
		});
		

		
		
		$(this).find("li").mouseout(function(){
				$(this).find("ul").css("display","none");
		});
		
		
		
    });
	
	
	/*
	$("#header ul li").mouseover(function(){
									  
										
											});
	*/
}


