// JavaScript Document

var index=0
var boucle
var ListeArt=new Array()

$(function(){
		   
		   $('.blocksel .produit:gt(0)').each(function(i){$(this).css({width:"0px"})	;$(".prixfou,.prix,.zoom",this).hide()})
		   
		   
		   
		   
		   $('.produit label').click(function(){
											  clearInterval(boucle);
											  if(!$(this).hasClass('encharg')){
												  		
											  			id="#taille"+$(this).attr('for');leParent=".aileproduit:has("+id+")"
														
														if($(leParent).size()>0){$(leParent).css({"z-index":1000,"position":"relative"})}
														$(id).toggle();
												  
											  }else{
													alert("chargement des tailles disponibles en cours. \nmerci de patienter jusqu'au changement de couleur")  
											  }
											  
			})		 
		   
		   
		   $('.divlistecat label').click(function(){
												  
											  			id="#liste"+$(this).attr('for');$(id).toggle();
											
											  
			})
		   
		   
		   $('.produit .addpanier').click(function(){$(".listetaille").hide();boucle=setInterval("boucleselection(1)",5000)})
		   
	       boucle=setInterval("boucleselection(1)",5000);
		
		   $("#switchproduit li").click(function(){clearInterval(boucle);$(".listetaille").hide();
																  if($(this).attr("class")=="precedent"){  boucleselection(-1) }else{boucleselection(1)}boucle=setInterval("boucleselection(1)",5000)   
			})  
		   
		   
		   $("#addpanier li.add").mouseover(function(){
													$("#addpanier li.add").css("z-index","1"); 
													 
											$("#addpanier li.add strong").css({"border-right-color":"white","border-bottom-color":"white"});
											
											
											$(".complement:visible").hide();
													$(this).css("z-index","10"); 
													 
											$(".complement",this).show();
									//		$("strong",this).css("border-color","#F1F1F1");
											$("strong",this).css({"border-right-color":"#F1F1F1","border-bottom-color":"#F1F1F1"});
											
											
											
			}).mouseout(function(){
				
													$("#addpanier li.add").css("z-index","1"); 
											$("#addpanier li.add strong").css({"border-right-color":"white","border-bottom-color":"white"});
											
											$(".complement:visible").hide();
				
		   }).click(function(){
			   
											$("input",this).val("1");
											$("#addpanier").submit();
		   })
		   
		   
		   $("#panierform select").change(function(){
						$("#panierform").submit();						   
												   
												   })
		   
		   
		   
		   
		   
		   $("a.dblunderline").append("<img src='design2/elmt/search.gif'/>");
		/*   $(".colonnephoto .replaceimg").click(function(){
															 url=$(this).attr("href")
															 title=$(this).attr("title")
															 alt=$("img",this).attr("alt")
															 imgsrc="upload/"+$("img",this).attr("src").split("vignettes/tb")[1]
															 
															 
															 $(".colonnephoto .first a").attr("href",url)
															 $(".colonnephoto .first a").attr("title",title)
															 $(".colonnephoto .first img").attr("alt",alt)
															 $(".colonnephoto .first img").attr("src",imgsrc)
															
															 })*/
		   
		   
		   chargeLesTailles()
})


chargeLesTailles=function(){
	
	$('.produit .listetaille').each(function(){
											 theid=$(this).attr('id');
											 theid=theid.substr(12);
											 ListeArt.push(theid)
											 
											 
 	})

	$.ajax({type: "POST",url: "ajaxtaille.php?id_art="+ListeArt.toString(),success: function(xml){
      				$("tailles",xml).each(function(){
												   
							var cible='#tailleidprod'+$(this).attr('id')
							 	   cible=$(cible)
						
							var bouton="label[@for='idprod"+$(this).attr('id')+"']"
								   $(bouton).removeClass('encharg')
								   
							var taille=$("taille",this)
							
							if(taille.size()==0){
									$(bouton).addClass("epuis")
									$(bouton).text("Produit épuisé")
									$(bouton).attr("for","")
									
									
							}else{
								
							
									$(taille).each(function(){
													cible.append("<li><input type=\"checkbox\" name=\"quantite["+$(this).attr('id_ref')+"]\" value=\"1\"/>&nbsp;"+$(this).attr('libelle')+"</li>")
									})
							
							
							}
					})
	  
   	} })
			
	
	
	
}


var autrefiche
var compo


boucleselection=function(sens){
	
	index=index+sens;
	limit=$(".blocksel .produit").size()
	
    if(index<0){index=limit-1;}
    if(index==limit){index=0;}
	
	autrefiche=".blocksel .produit:gt("+index+"),.blocksel .produit:lt("+index+")";
	autrefiche=$(autrefiche);
	$(".prixfou,.prix,.zoom,.corpprod",autrefiche).fadeOut();
	autrefiche.animate({width: "0px" }, 1200);
	
	compo=".blocksel .produit:eq("+index+")";
	compo=$(compo);
	compo.animate({width: "255px" }, 1500 ,function(){
	$(".prixfou,.prix,.zoom,.corpprod",compo).fadeIn();});
	
}