$.slideshow = function(images) {  
  var images = window["eval"]("(" + images + ")");
  var i = 0;
  var r = 0;
  
  var interval = 6000;
  var fadetime = 3000;
  
//  setTimeout(function() {
//    preload();
//  }, 0);

  preload();
  startSlideshow();
  
  function startSlideshow() {
    addImage();
  }
  
  function addImage() {    
    setTimeout(function() {
      addImage()
    }, interval);
    
    
    if ($("#slide"+ i).length > 0) {
      $("#slide"+ i).remove();
    }
    
    var html = '';
    
    html += '<div id="slide'+ i +'">';
    
    if (images[i].length == 1) {
      html += '<div class="image"><img src="'+ images[i][0] +'" /></div>';      
    } else {
      html += '<div class="imageL"><img src="'+ images[i][0] +'" /></div>'; 
      html += '<div class="imageR"><img src="'+ images[i][1] +'" /></div>';
    }
    
    html += '</div>';      
    
    $("#slideshow").prepend(html);
    
    i = (++i % images.length);
    
    setTimeout(function() {
      removeImage()
    }, (interval));
  }
  
  function removeImage() {    
    if (images[r].length == 1) {
      $("#slide"+ r +" > div:first").fadeOut(fadetime);
    } else {
      var flip = ((rand(1, 2) == 1)?+1500:-1500);     
        
      $("#slide"+ r +" > div:first").fadeOut(fadetime + flip);
      $("#slide"+ r +" > div:last").fadeOut(fadetime - flip);    
    }
    
    r = (++r % images.length);
  }

  function preload() {
//    $.each(images, function(j) {
//      if ($(this).length == 1) {
//        $("<img>").attr("src", $(this)[0]);
//      } else {
//        $("<img>").attr("src", $(this)[0]);
//        $("<img>").attr("src", $(this)[1]);        
//      }
//    });
    
    $.each(images, function(j) {
      var html = '';
    
      html += '<div id="slide'+ j +'" style="display: none;">';
      
      if (images[j].length == 1) {
        html += '<div class="image"><img src="'+ images[j][0] +'" /></div>';      
      } else {
        html += '<div class="imageL"><img src="'+ images[j][0] +'" /></div>'; 
        html += '<div class="imageR"><img src="'+ images[j][1] +'" /></div>';
      }
      
      html += '</div>';      
    
      $("#slideshow").prepend(html);
    });
  }
  
  function rand( min, max ) {
    var argc = arguments.length;
    
    if (argc == 0) {
      min = 0;
      max = 2147483647;
    } else if (argc == 1) {
      throw new Error('Warning: rand() expects exactly 2 parameters, 1 given');
    }
    
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

  /*
   
  setTimeout(function() {
    preload();
  }, 0);
  
  add();
  
  function add() {
    var html = '';
    
    if (images[i].length == 1) {
      html += '<div>';
      html += '<div class="image"><img src="'+ images[i][0] +'" /></div>'; 
      html += '</div>';      
    } else {
      html += '<div>';
      html += '<div class="imageL"><img src="'+ images[i][0] +'" /></div>'; 
      html += '<div class="imageR"><img src="'+ images[i][1] +'" /></div>';
      html += '</div>';      
    }
    
    $("#slideshow").prepend(html);

    fade();
    
    setTimeout(function() {
      add();
      
    }, interval);
    
    i = (++i % images.length);
  }
  
  function fade() {
    if ($("#slideshow > div:last div").length == 1) {
      setTimeout(function() {
        $("#slideshow > div:last div:first").fadeOut(fadetime);
      }, interval + (Math.round(Math.random() * 50) *20));
    } else {
      setTimeout(function() {
        $("#slideshow > div:last div:first").fadeOut(fadetime);
      }, interval + (Math.round(Math.random() * 50) *20));
      
      setTimeout(function() {
        $("#slideshow > div:last div:last").fadeOut(fadetime);
      }, interval + (Math.round(Math.random() * 50) *20));
    }
      
    setTimeout(function() {
      $("#slideshow > div:last").remove();
    }, interval + fadetime + 10000);
  }
  
  
  */
}