
function SlideShowViewer (elementId, imageList)
{
    this.container = jQuery('#'+elementId);
    this.imageList = imageList;
    this.imageCount = imageList.length;
    this.currentIndex = 0;
    thisViewer = this;
    this.playAction = function () {
        thisViewer._nextSlide();
    }
}
        
SlideShowViewer.prototype.play = function (speed) {
    this._preloadImages();
    setInterval(this.playAction, speed);
    return false;
}

SlideShowViewer.prototype._nextSlide = function () {
    nextImageSrc = this.imageList[this.currentIndex];
    this.container.css({background: 'transparent url('+nextImageSrc+') left top no-repeat'});
    image = this.container.find('img:first');
    image.animate({opacity: 0}, 1500, function(){
        $(this)
        .attr('src', nextImageSrc)
        .css({'opacity': '1'})
    });
    
    if (this.currentIndex < this.imageCount-1) {
        this.currentIndex++;
    } else {
        this.currentIndex = 0;
    }
    return false;
}

SlideShowViewer.prototype._preloadImages = function() {
    for(var i = 0; i<this.imageList.length; i++)
    {
      jQuery("<img>").attr("src", this.imageList[i]);
    }  
}
