jQuery.fn.dynamicSlideshow = function(attr) {
   attr = attr || {};
   attr.duration = attr.duration || 3000;

   function initSlider(container, img,lien,alt) {
      var curr = Math.floor(Math.random()*img.length);
      setInterval( function(){
         if (curr == img.length) {
            curr = Math.floor(Math.random()*img.length);
         }
         var i = new Image();
         var azar = Math.floor(Math.random()*img.length) ;
         $(i).load(function(){

            $(container).append(this);
            $(container).find('img:first').css({'z-index': 1});
            $(this).css({opacity: 0.0, 'z-index': 2}).animate({opacity: 1.0}, 1000, function() {
                  $(container).find('img:first').remove();
               })
         }).attr('onClick',lien[azar]).attr('src', img[azar]).attr('alt', alt[azar]).attr('title', '').css({'position':'absolute','top':'0','left':'0','z-index':'8','cursor':'pointer'});
      }, attr.duration );
   };

   $(this).each(function(){
      var img = [];
      var lien = [];
      var alt = [];
      $(this).find("img").each(function(){
         img.push($(this).attr("src"));
         lien.push($(this).attr("longdesc"));
         alt.push($(this).attr("alt"));
      });
      var j = new Image();
      var container = this;
      $(this).empty();
      $(j).attr('onClick', lien[0]).attr('src', img[0]).attr('alt', img[0]).css({'position':'absolute','top':'0','left':'0','z-index':'0','cursor':'pointer'}).load(function(){
         $(container).append(this);
         initSlider(container, img,lien,alt);
      });
   });
}