var ContentFader = Class.create({

    initialize: function(container) {
        this.IMAGE_WIDTH = 600;
        this.AUTO_TIMER = 10;
        this.container = $(container)
        this.contents = this.container.select(".fader-content");

        this.currentindex = 0;

        for (i = 0; i < this.contents.length; i++) {
            if (i > 0) {
                this.contents[i].hide();
            }
        }

        new PeriodicalExecuter(this.autoSwitch.bind(this), this.AUTO_TIMER);
    },

    setPanel: function(button) {
        var index = button;
        if (this.currentindex != index) {
            new Effect.Fade(this.contents[this.currentindex], { duration: 1.0 });
            this.currentindex = index;
            new Effect.Appear(this.contents[index], { duration: 1.0 });
        }
    },

    autoSwitch: function(pe) {
        if (this.auto_paused) return;
        var nextIndex = this.currentindex < this.contents.length - 1 ? this.currentindex + 1 : 0;
        this.setPanel(nextIndex);
    },

    pauseAutoSwitch: function() {
        this.auto_paused = true;
    },

    unpauseAutoSwitch: function() {
        this.auto_paused = false;
    }
});
