(function($) {
    $.fn.oTicker = function() {
        return this.each(function(){
            new orp_Ticker(this);
        });
    }
    $.fn.oLoad = function(url, args) {
        return this.each(function(){
            if (url) {
                if (!args) args = {};
                args.e = $(this);
                args.url = url;
                if ($(this).hasClass('oui-list')) args._onComplete = oui.list.initItems;
                new buff_Loader(args);
            }
        });
    }
})(jQuery);

function orp_Ticker(e) {
    var list = $(e).find('li');
    if (list.length == 0) return;
    var timeout = $(e).attr('orp:timeout');
    
    timeout = timeout * 1000;
    if (timeout < 1000) timeout = 1000;
    var transition = $(e).attr('orp:transition');
    var fade = (transition == 'fade');
    $(e).find('li').hide();
    $(e).find('li:first-child').show();
    setInterval(tick, timeout);
    
    var counter = 0;
    function tick() {
        if (fade) {
            $(list[counter]).fadeOut(400, hideMe);
        } else {
            $(list[counter]).hide();
        }
        counter++;
        if (counter >= list.length) counter = 0;
        if (fade) {
            setTimeout(fadeIn, 400);
        } else {
            $(list[counter]).show();
        }
    }
    
    function hideMe() {
        $(this).hide();
    }
    
    function fadeIn() {
        $(list[counter]).fadeIn(400);
    }
}
