
var Slideshow = function(imgIdPrefix) {
    this.imgIdPrefix = imgIdPrefix;
    this.num = 0;
};

Slideshow.prototype = {

    startup: function() { 
        this.num = 0;
        new PeriodicalExecuter(this.cycle.bind(this), 5); // change image every 5 seconds 
    }, 

    cycle: function() {
        new Effect.Fade((this.imgIdPrefix + this.num), { // the id of the <DIV> containing the photos 
                duration: 2, fps: 50, beforeStart: this.next.bind(this) }); 
    },

    next: function() {
        new Effect.Appear(this.getNextImgId(), {duration: 2, fps: 50, queue:'end'})
    },

    getNextImgId:function() {

        this.num += 1;
        var nextImgId = this.imgIdPrefix + this.num;

        if ($(nextImgId) == null) {
            this.num = 0;
            nextImgId = this.imgIdPrefix + this.num;
        }
        return nextImgId;
    }
};

