jQuery().ready(function(){

  for(var nbElement=1 ; nbElement<=$('.diaporama div').length ; nbElement++){
  
    $(".diaporama:nth-child("+nbElement+") div").each(function(){

      var elementPrincipal = $(this);
      var nbImage = elementPrincipal.children("a").length;
      
      var enCours = Math.floor(Math.random() * nbImage)+2;
      nbImage++;
      
      elementPrincipal.children("a").children("img").css("display","none");

      elementPrincipal.children("a:nth-child("+enCours+")").children("img").fadeIn(800);

      var title = elementPrincipal.children("a:nth-child("+enCours+")").attr("title");
      
      elementPrincipal.children("span").html(title);

      var aleatoire = parseInt(Math.random()*2000+5000);

      elementPrincipal.everyTime(aleatoire , function(i) {

        elementPrincipal.children("a:nth-child("+enCours+")").children("img").fadeOut(800,function() {

          // Animation complete
          enCours++;
          if(enCours>nbImage) enCours = 2;

          var title = elementPrincipal.children("a:nth-child("+enCours+")").attr("title");
          elementPrincipal.children("span").html(title);

          elementPrincipal.children("a:nth-child("+enCours+")").children("img").fadeIn(800);

        });

      });

    });
    
  }

});
