TestimonialManager = Class.create();
TestimonialManager.prototype = {

    eltDivs: null,
    selectedIndex: 0,
    maxIndex: null,
    interval: 10,
    
	initialize: function() {
        Event.observe(window, 'load', this.init.bindAsEventListener(this), false);
    },

    init: function() {
        this.eltDivs = Element.getElementsByClassName('containerTestimonial', 'testimonial');
        if (this.eltDivs && this.eltDivs.length > 1) {
            this.maxIndex = this.eltDivs.length - 1;
            new PeriodicalExecuter(this.handleTick.bind(this), this.interval);
        }
    },

    handleTick: function() {
        var oldIndex = this.selectedIndex;
        this.selectedIndex = ((this.selectedIndex + 1 > this.maxIndex) ? 0 : this.selectedIndex + 1 );
        new Effect.Fade(this.eltDivs[oldIndex], { afterFinish: this.switchData.bind(this) } );
    },

    switchData: function() {
        new Effect.Appear(this.eltDivs[this.selectedIndex]);
    }
    
};

new TestimonialManager();

    
