﻿(function($) {
    $.fn.extend({
        Scroll: function(opt, callback) {
            if (!opt) var opt = {};
            var moving = false, mouseover = false;
            var _this = this.eq(0).find("ul:first");
            var lineH = _this.find("li:first").height(),
                        line = opt.line ? parseInt(opt.line, 10) : parseInt(this.height() / lineH, 10),
                        speed = opt.speed ? parseInt(opt.speed, 10) : 500,
                        timer = opt.timer ? parseInt(opt.timer, 10) : 300,totalHeight=00;_this.find("li").each(function(){totalHeight+=$(this).height();});
            if (line == 0) line = 1;
            var upHeight = 0 - line * lineH;
            $(this).find("ul > li").each(function() { $(this).css("height", $(this).height() + 5 + "px"); });if($(this).height()>totalHeight){return;}
            scrollUp = function() {
                clearInterval(timerID);
                upHeight = 0 - _this.find("li:first").height() - 1; moving = true;
                _this.find("li:first").animate({
                    marginTop: upHeight
                }, speed, function() {
                    var html = _this.find("li:first").html(), vclass = _this.find("li:first").attr("class");
                    $(this).remove()
                    if (vclass.length > 0) { vclass = "class='" + vclass + "' "; }
                    //if (vstyle.length > 0) { vstyle = "style='" + vstyle + "' "; }
                    $(_this).append("<li " + vclass + ">" + html + "</li>");
                    timerID = setInterval("scrollUp()", timer); moving = false; if (mouseover) { clearInterval(timerID); }
                });
            }
            _this.hover(function() {
                if (!moving) { clearInterval(timerID); }
                mouseover = true;
            }, function() {
                if (!moving) { timerID = setInterval("scrollUp()", timer); };mouseover = false;
            }).mouseout();
        }
    })
})(jQuery);
