$(document).ready(function(){
    //TOUTES LES FONCTIONS JQUERY SPECIFIQUES DU SITE
           
    //Arret du défilement de la zone "Selection" lorsque l'on est sur une fiche
    stop_mouse_over = false;
    $('.liste_depliante').bind("mouseenter",function(){
        stop_mouse_over = true;
    }).bind("mouseleave",function(){
        stop_mouse_over = false;
    });
    
    
    // ANIMATION DE LA ZONE "NOTRE SELECTION"
    $('#ligne_pdt_selection').serialScroll({
  		target:'#selection_conteneur',
  		items:'.case_pdt', // Selector to the items ( relative to the matched elements, '#sections' in this case )
  		prev:'.fleche_gauche',// Selector to the 'prev' button (absolute!, meaning it's relative to the document)
  		next:'.fleche_droite',// Selector to the 'next' button (absolute too)
  		axis:'x',// The default is 'y' scroll on both ways
  		duration:500,// Length of the animation (if you scroll 2 axes and use queue, then each axis take half this time)
  		force:true, // Force a scroll to the element specified by 'start' (some browsers don't reset on refreshes)
  		jump:true, // If true, items become clickable (or w/e 'event' is, and when activated, the pane scrolls to them)
  		interval:7000, // It's the number of milliseconds to automatically go to the next
  		
  		onBefore:function( e, elem, $pane, $items, pos ){
    			/**
    			 * 'this' is the triggered element 
    			 * e is the event object
    			 * elem is the element we'll be scrolling to
    			 * $pane is the element being scrolled
    			 * $items is the items collection at this moment
    			 * pos is the position of elem in the collection
    			 * if it returns false, the event will be ignored
    			 */
                 //alert(hover_liste_depliante);
          //si on est sur un produit, on évite le scroll   
          if(stop_mouse_over == true)
          {
            return false;
          }
              
  			  //those arguments with a $ are jqueryfied, elem isn't.
    			e.preventDefault();
    			if(this.blur)
    				this.blur();
    			
            //on cache les détails du produit qu'on quitte	
            //$items.removeClass("case_pdt_orange");
            $(".case_pdt_orange").removeClass("case_pdt_orange");
            //$(".liste_depliante").slideUp("fast");
            $(".ligne_pdt").removeClass("ligne_pdt_orange");
            $("#ligne_pdt").addClass("ligne_pdt_orange");
            $('#liste_depliante_1').prev().addClass("ligne_pdt_orange");
            //$('#liste_depliante_1').slideUp("slow");

          //on grise/dégrise les flèches gauche et droite
          if (pos==0) { //si c'est le premier élément
              $(".fleche_gauche").addClass("fleche_gauche_grise");
          } else {
              $(".fleche_gauche").removeClass("fleche_gauche_grise");
          } 
                
          if (pos==5) { //si c'est le dernier élément
              $(".fleche_droite").addClass("fleche_droite_grise");
          } else {
              $(".fleche_droite").removeClass("fleche_droite_grise");
          }                   
      },
      
      onAfter:function( elem ){
          //'this' is the element being scrolled ($pane) not jqueryfied
          
          //on ne recharge pas la fiche le 1er coup, apres le chargement de la page
          if(apres_chargement_page == 0)
            load_ajax_page('#liste_depliante_1', $(elem).attr('title'),0);
          else  
            apres_chargement_page = 0;
          //on affiche les détails du produit visé
          $(elem).addClass("case_pdt_orange");
      }
    });
  
    //Rendre le produit déplaçable
    $(".drag_pdt")
        .draggable({
            appendTo: '#conteneur',    //le conteneur du clone
            containment: '#conteneur', //restreint le déplacement à cette zone
            //distance: 10,              //distance minimum à parcourir
            helper: 'clone',           //c'est un clone qui est déplacé
            opacity: 0.8,
            handle: '.photo_pdt img'
        })
        .find(".photo_pdt img")
            .css({cursor: 'move'});
        

    
    //Rendre le panier réactif au produit laché
    $("#zonePanier").droppable({
        accept: '.drag_pdt',
        activeClass: 'activePanier',
        hoverClass: 'hoverPanier',
        
        //lors du drop
        drop: function(event, ui){ 
            //effet visuel de transfers
            //$(ui.draggable).effect("transfer", {to: "#zonePanier", className: 'ui-effects-transfer'});
            var pdt_id = ($(ui.draggable).attr("title"));  
            ajoutPanier(pdt_id, 1);    
        }
    });
    
    //Ajout au panier avec quantité
    $(".jq_panier")
        .click(function(){
            var pdt_id=$(this).siblings(".pdt_id").val();
            var quantite=$(this).siblings(".quantite").val();
            ajoutPanier(pdt_id, quantite);    
        })
        .css({cursor: 'pointer'});
        
    //Liens "voir la photo"    
    $('a.pic').lightBox();  
    
    //Menu des familles animé
    $("li.famillesLi").hover(function(event) {
    	event.preventDefault();
      $(this)
        .siblings("li.famillesLi")
          .find("ul.sousFamille").slideUp().end()
        .end()
        .find("ul.sousFamille").slideDown();   
    });
    
    $("ul.sousFamilleActive").slideDown();  
});



