var IASlideshow = Class.create();
IASlideshow.prototype = {
    initialize: function(images) {
        this.options = Object.extend({
            imageId0: 'slideshowImage0',
            imageId1: 'slideshowImage1',
            transitionTime: 7
        }, arguments[1] || {});

        this.slideshowImages = $A(images).collect(function (i) {
            var image = new Image
            image.src = i;
            return image;
        });
        
        //console.log(this.slideshowImages);
        
        this.currentImage = 1;
        this.currentSlideshowImage = 0;
        
        this.pe = new PeriodicalExecuter(this.nextImageInSlideshow.bind(this), this.options.transitionTime);
    },


    nextImageInSlideshow: function() {
        if(this.currentImage >= this.slideshowImages.length) {
            this.currentImage = 0;
        }
        
        this.currentSlideshowImage = (this.currentSlideshowImage == 0 ? 1 : 0);
        
        var image = this.slideshowImages[this.currentImage];
        if (this.currentSlideshowImage == 1) {
            $(this.options.imageId1).src = image.src;
            Effect.Appear(this.options.imageId1);
            Effect.Fade(this.options.imageId0);
        }
        else {
            $(this.options.imageId0).src = image.src;
            Effect.Appear(this.options.imageId0);
            Effect.Fade(this.options.imageId1);
        }
        this.currentImage += 1;
        //console.log(currentImage);
        //console.log(image.src);
        //console.log(currentSlideshowImage);
    }
}

