$(document).ready(function() {


var widthLarge = '380px';
var widthSmall = '34px';

     //**********//
     //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',widthLarge);
                $(this).parent().children("div.imgActusSlide").css('width',widthLarge);
                ouvre($(this).parent()); 
                my_open_div = $(this).parent();             
           }                            
     });

     //on retrecis les autres
     $("#actuSlideImg div[class=wrapperActusSlide][class!=actif]").each( function(){
               $(this).css('width',widthSmall);
               $(this).children("div.imgActusSlide").css('width',widthSmall).css('overflow','hidden');
               ferme($(this));
     });
     //gestion du survol
     $("#actu_a_la_une > div").click( function(){
       my_new_div = $(this);
        //on trouve le numero de l'article ouvert
        nb_chaude =  $(this).children("div.numActusSlide").text(); 
       $("#actu_a_la_une > div").css('cursor','pointer');
       $(this).css('cursor','default');
        
        if(nb_chaude != old_chaude){
            if(nb_chaude > old_chaude){
                $(my_open_div).stop().animate({"width": widthSmall},"slow");  
                $(my_open_div).children("div.imgActusSlide").stop().animate({"width": widthSmall},"slow");
                $(this).stop().animate({"width": widthLarge}, "slow");
                $(this).children("div.imgActusSlide").stop().animate({"width": widthLarge}, "slow",  
                       function(){ 
                            ouvre($(my_new_div )); 
                       }
                );  
      
           } else {
                $(this).stop().animate({"width": widthLarge}, "slow");
                 $(this).children("div.imgActusSlide").stop().animate({"width": widthLarge}, "slow", 
                       function(){ 
                            ouvre($(my_new_div )); 
                       }
                );  
                $(my_open_div).stop().animate({"width": widthSmall},"slow");  
                $(my_open_div).children("div.imgActusSlide").stop().animate({"width": widthSmall},"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": widthSmall},"slow");  
                $(my_open_div).children("div.imgActusSlide").stop().animate({"width": widthSmall},"slow");
 
                $(my_new_div).stop().animate({"width": widthLarge}, "slow");
                $(my_new_div).children("div.imgActusSlide").stop().animate({"width": widthLarge},  "slow",  
                       function(){ 
                            ouvre($(my_new_div )); 
                       }
                );     
           } else {
                $(my_new_div).animate({"width": widthLarge}, "slow");
                $(my_new_div).children("div.imgActusSlide").animate({"width": widthLarge}, "slow",  
                       function(){ 
                            ouvre($(my_new_div )); 
                       }
                );    
                $(my_open_div).animate({"width": widthSmall},"slow");  
                $(my_open_div).children("div.imgActusSlide").animate({"width": widthSmall}, "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');
     $(mon_div).removeClass('actif');

}
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');
} 
