// global console, window, $, prompt, saveState

/**
 * A JQuery plugin that will setup a slideshow.
 *
 * @version 1.0
 * @requires
 *      jquery.js
 *      jquery.timers.js
 * @author Ed Rodriguez Ed.Rodriguez@swfwmd.state.fl.us
 * @param string lapse The defined next tag to show and hide
 * @param string height The height of the slideshow
 * @param string speed The animation speed: slow, fast, normal
 */
$.fn.slideshow = function(options){
    var opts = $.extend({}, $.fn.slideshow.defaults, options);
    
    function log(message){
        if(typeof window.console != "undefined" && typeof window.console.log != "undefined"){
            console.log(message);
        }
    }
    log("Elements Found: "+this.length);
        
    opts.elements = this;
    opts.current = 0;
    
    function process(items, num){
        var elements = opts.elements;
        elements.each(function(i){
            if(i == opts.current){
                var height = (opts.height === undefined) ? $(this).height() : opts.height;
                $(this).parent(':first').height(height); 
                $(this).fadeIn(opts.speed);
                next = opts.current + 1;
            }else{
                $(this).fadeOut(opts.speed);
            }
        });
        opts.current = next;
        if(opts.current >= elements.length){
            opts.current = 0;
        }
    };
    
    this.each(function(i){
        if(i != 0){
            $(this).hide();
        }else{
            var height = (opts.height === undefined) ? $(this).height() : opts.height;
            $(this).parent(':first').height(height);
            $(this).hide();
        }
    });
    
    $(this[0]).fadeIn();
    
    var times = this.length;
    $(document).everyTime(opts.lapse, function(i){
        process(this, i);
    }, 0);
};
$.fn.slideshow.defaults = {
    lapse: 2500,
    height: undefined,
    speed: 'slow'
};
