/**
 * Rotates through a series of elements, cross-fading them at a specific interval
 */
Director.RotateController = Class.create();
Director.RotateController.prototype = {

    rotate: function() {
        curr_element = this.elements_to_rotate[this.curr_index];
        if(this.curr_index == this.elements_to_rotate.length-1) {
            this.curr_index = 0;
        } else {
            this.curr_index++;
        }
        next_element = this.elements_to_rotate[this.curr_index];
        if(curr_element && next_element) {
            Effect.Fade(curr_element, { duration:1, from:1.0, to:0.0, queue: 'end' });
            Effect.Appear(next_element, { duration:1, from:0.0, to:1.0, queue: 'end' });
        }
    },

    initialize: function(elements_to_rotate, starting_index, interval_in_seconds) {
        this.elements_to_rotate = elements_to_rotate;
        this.curr_index = starting_index;
        this.interval_in_seconds = interval_in_seconds;

        setInterval(function() {
                        this.rotate();
                    }.bindAsEventListener(this),
                    this.interval_in_seconds * 1000);

    }
}