(function($) {
    $.fn.fader = function(options){
        return this.each(function() {
            $.fader(this, options);
        });
    };
    $.fader = function(element, options){
        if( options == 'stop'){
            clearTimeout(timeoutID);
            stopFlag = true;
        }else{
            stopFlag = false;
            timeoutID = 0;
            var settings = {
                'timeout':'6000',
                'speed':'slow'
            }
            if (options)
                $.extend(settings, options);
            if ( 'undefined' === typeof flagInit){
                $('p',element).hide();
                flagInit = false;
            }else
                $('p',element).fadeOut(settings.speed);
            var current =  $('p:first',element);
            current.fadeIn(settings.speed, function(){
                if(!stopFlag)
                    timeoutID = setTimeout(function(){
                        $.fader.next(current,settings);
                    }, settings.timeout);
            });
        }
    }
    $.fader.next = function(element, settings){
        $(element).fadeOut(settings.speed, function(){
            current = $(element).next(':first');
            if(current.size() == 0)
                current = $(element).siblings(':first');
            current.fadeIn(settings.speed, function(){
                if(!stopFlag)
                    timeoutID = setTimeout(function(){
                        $.fader.next(current, settings);
                    }, settings.timeout);
                
            });
            
        });
    };

})(jQuery);

