﻿(function($){
$.fn.extend({
        Scroll:function(opt,callback){
                //参数初始化
                if(!opt) var opt={};
                var _this=this;
                var lineH=opt.lineH, //获取行高
                     height=this.height(),
                     speed=opt.speed?parseInt(opt.speed,10):500, //卷动速度，数值越大，速度越慢（毫秒）
                     timer=opt.timer?parseInt(opt.timer,10):3000; //滚动的时间间隔（毫秒）

                var upHeight=0-lineH;
                
                //滚动函数
                scrollUp=function(){
                       if (height>lineH)
                       {
                               _this.animate({
                                       marginTop:upHeight
                               },speed,function(){
                                    if (upHeight==0)
                                        upHeight=0-lineH;
                                    else
                                        upHeight=upHeight+upHeight;
                                    if (Math.abs(parseInt(_this.css("marginTop"),10))+lineH>=height)
                                    {
                                        upHeight=0;
                                    }
                               });
                       }
                }

                timerID=setInterval("scrollUp()",timer);

                //鼠标事件绑定
                _this.hover(function(){
                        clearInterval(timerID);
                },function(){
                        timerID=setInterval("scrollUp()",timer);
                }).mouseout();
        }        
})
})(jQuery);
