$(document).ready(function() {
     //**********//
     //Zone chaude//
     //**********//
     var nb_chaude = 1; //article courant
     var old_chaude = 1; //ancien article ouvert
     var my_open_div; //objet du div ouvert
     var my_new_div; //nouveau div à ouvrir
     var auto;
     //On fait floater
     $("#actuSlideImg div.wrapperActusSlide").css("float","left");
     //On cible le premier
     $("#actuSlideImg div.wrapperActusSlide div.numActusSlide").each( function(){
           if($(this).text() == '1') {
                $(this).parent().css('width','581px');
                $(this).parent().children("div.imgActusSlide").css('width','581px');
                ouvre($(this).parent()); 
                my_open_div = $(this).parent();             
           }                            
     });
     //on retrecis les autres
     $("#actuSlideImg div[class=wrapperActusSlide][class!=actif]").each( function(){
               $(this).css('width','30px');
               $(this).children("div.imgActusSlide").css('width','30px').css('overflow','hidden');
               ferme($(this));
     });
     //gestion du survol
     $("#zone-site_a_la_une > div").hover( function(){
       my_new_div = $(this);
        //on trouve le numero de l'article ouvert
        nb_chaude =  $(this).children("div.numActusSlide").text(); 
        
        if(nb_chaude != old_chaude){
            if(nb_chaude > old_chaude){
                $(my_open_div).stop().animate({"width": "30px"},"slow");  
                $(my_open_div).children("div.imgActusSlide").stop().animate({"width": "30px"},"slow");
                $(this).stop().animate({"width": "581px"}, "slow");
                $(this).children("div.imgActusSlide").stop().animate({"width": "581px"}, "slow",  
                       function(){ 
                            ouvre($(my_new_div )); 
                       }
                );  
      
           } else {
                $(this).stop().animate({"width": "581px"}, "slow");
                 $(this).children("div.imgActusSlide").stop().animate({"width": "581px"}, "slow", 
                       function(){ 
                            ouvre($(my_new_div )); 
                       }
                );  
                $(my_open_div).stop().animate({"width": "30px"},"slow");  
                $(my_open_div).children("div.imgActusSlide").stop().animate({"width": "30px"},"slow");
           }
           ferme($(my_open_div));
           my_open_div =  this;
           old_chaude = nb_chaude;
        }
        window.clearInterval(auto);
        change_auto();
   });
    //pour changer automatiquement 
    change_auto();
    function  change_auto(){
       auto = window.setInterval( function(){
        
          var trouve = 0;
          
          //on trouve le numero du prochain article à ouvrir 
          nb_chaude = eval(nb_chaude)+1; 
          //on cible l'actu
          $("#actuSlideImg div.wrapperActusSlide div.numActusSlide").each( function(){
                //au cas ou on trouve pas l'actu
                if($(this).text() == 1) {
                       my_new_div =  $(this).parent();  
                 }     
                 if($(this).text() == nb_chaude) {
                       trouve = 1;     
                       my_new_div =  $(this).parent();  
                 }                            
          });
          //si pas trouvé, on prend la première
          if(trouve == 0) nb_chaude  = 1;
 
          if(nb_chaude > old_chaude){
                $(my_open_div).stop().animate({"width": "30px"},"slow");  
                $(my_open_div).children("div.imgActusSlide").stop().animate({"width": "30px"},"slow");
 
                $(my_new_div).stop().animate({"width": "581px"}, "slow");
                $(my_new_div).children("div.imgActusSlide").stop().animate({"width": "581px"},  "slow",  
                       function(){ 
                            ouvre($(my_new_div )); 
                       }
                );     
           } else {
                $(my_new_div).animate({"width": "581px"}, "slow");
                $(my_new_div).children("div.imgActusSlide").animate({"width": "581px"}, "slow",  
                       function(){ 
                            ouvre($(my_new_div )); 
                       }
                );    
                $(my_open_div).animate({"width": "30px"},"slow");  
                $(my_open_div).children("div.imgActusSlide").animate({"width": "30px"}, "slow"); 
  
            }
            ferme($(my_open_div));
            old_chaude = nb_chaude;
            my_open_div =  my_new_div;
          
       }
       , 7000);
   }
}); 
function ferme(mon_div){
     //On fait disparaitre les textes
     $(mon_div).children("strong.titreActusSlide").css('display','none');
     $(mon_div).children("p.descActusSlide").css('display','none');
    // $(mon_div).children("div.imgActusSlide").css('overflow','hidden');
}
function ouvre(mon_div){
     //On fait apparaitre les textes
     $(mon_div).children("strong.titreActusSlide").css('display','block');
     $(mon_div).children("p.descActusSlide").css('display','block');
     $(mon_div).addClass('actif');
}
