/*
*	Content Switcher
*	Generates a content switcher. Time or Event based
*	
*	Requires Trapeze jQuery distribution
*	
*	Marcos Abreu - March 27, 2009
*/

$.namespace("trapeze.ContentSwitcher");

trapeze.ContentSwitcher = $.Class.extend({
    item_list : [],
    current_index : 0,
    step : 1,
    delay : 8000,

    effect_out : function() {
        this.item_list.eq(this.current_index).fadeOut(1000, this.effect_in.bind(this));
    },

    effect_in : function() {
        this.current_index = ((this.current_index + this.step) > (this.item_list.length - 1)) ? 0 : this.current_index + this.step;
        this.item_list.eq(this.current_index).fadeIn(1000);
    },

    init : function(item_list, delay, step) {
        this.item_list = item_list;
        this.step = step;
        this.delay = delay;

        this.item_list.filter(':not(:nth-child('+this.current_index+1+'))').hide();
        $(document).everyTime(this.delay, 'content-switcher', this.effect_out.bind(this));
    }

});

