(function($) {
	function Scroll(obj, opt) {
		this.obj = obj;
		this.opt = $.extend(obj, opt);
		this.init = function() {
			clearInterval(obj.attr("timerID"));
			this.Scrolls(obj, opt);
		}
	}
	Scroll.prototype = {
		//					 timerID:null,
		Scrolls: function(obj, opt) {
			this.hovered(obj, opt)
		},
		scrollDown: function(obj, opt) {
			var _this = obj.eq(0).find("table:first");
			var lineH = _this.find("tr:first").height(); //获取行高
			_this.animate({
					marginTop: -lineH + "px"
				}, //动画展示css样式
				opt.speed,
				function() {
					_this.find("tr:first").appendTo(_this);
					_this.css({
						marginTop: "0px"
					});
				}
			)
		},
		hovered: function(obj, opt) {
			var timerID, $thats = this,
				_thisH = obj.eq(0).find("table:first").height(),
				thisH = obj.eq(0).height();
			obj.eq(0).find("table:first").unbind();
			//鼠标事件绑定
			obj.eq(0).find("table:first").hover(function() {
				clearInterval(obj.attr("timerID"));
			}, function() {
				if(_thisH > thisH) {
					timerID = setInterval(function() {
						$thats.scrollDown(obj, opt)
					}, opt.timer); //这里调用向下或者向上滚动函数
					obj.attr("timerID", timerID);
				}
			}).mouseout();
		}

	}
	$.fn.Scroll = function(obj) {
		var $that = this;
		//参数初始化
		if(!obj) var obj = {};
		var _this = $that.eq(0).find("table:first");
		var lineH = _this.find("tr:first").height(), //获取行高
			line = obj.line ? parseInt(obj.line, 10) : parseInt($that.height() / lineH, 10), //每次滚动的行数，默认为一屏，即父容器高度
			speed = obj.speed ? parseInt(obj.speed, 10) : 500, //卷动速度，数值越大，速度越慢（毫秒）
			timer = obj.timer ? parseInt(obj.timer, 10) : 2000; //滚动的时间间隔（毫秒）
		if(line == 0) line = 1;
		var rollNumObj = new Scroll($that, obj);
		rollNumObj.init();
	};
})(jQuery);
