;(function($){

$.fn.scroll = function(opt) 
{
	//参数初始化
	if(!opt) var opt={};
	var item = opt.item ? opt.item : "li";
	var el = this.find(item+":first");
	var lineH = el.height() ? el.height() : el.css('line-height'); //获取行高
	if (typeof lineH == "string")
	{
		lineH = lineH.replace(/[^\d]+/, "");
	}

    var itemlist = this.find(item);
	var div = $('<div></div>');

	div.appendTo(this);
	itemlist.appendTo(div);
    var self = this.find("div:first");

	line  = opt.line ? parseInt(opt.line) : 1; //每次滚动的行数，默认为一屏，即父容器高度
	speed = opt.speed ? parseInt(opt.speed) : 1000; //卷动速度，数值越大，速度越慢（毫秒）
	timer = opt.timer ? parseInt(opt.timer) : 2000; //滚动的时间间隔（毫秒）
	if(line == 0) line = 1;
	var hight = this.height();
	var upHeight = 0 - ((hight/lineH) - parseInt(hight/lineH) + line) * lineH;
	//滚动函数
    var scrollUp = function(){
		self.animate({marginTop:upHeight}, speed, function(){
			for(i=1; i <= line; i++){
				self.find(item+":first").appendTo(self);
			}
			self.css({marginTop:0});
		});
	}

	var setInter = function(){
		self.timerID=setInterval(scrollUp, timer)
	};
	var stopInter = function(){
		clearInterval(self.timerID)
	};
	//鼠标事件绑定
    setInter();
	this.hover(stopInter, setInter);
}

})(jQuery);