﻿function MarqueeClass(options){
  	this.obj = typeof options.obj == 'object'?options.obj : document.getElementById(options.obj);
	this.lineHeight   =   options.lineHeight;     //单行高度，像素   
	this.lineCount   =   options.lineCount;     //实际行数   
	var scrollAmount = this.scrollAmount   =   options.scrollAmount;     //每次滚动高度，像素  
	this.wait = options.wait?options.wait * 1000 : 2 * 1000;   //换一屏后停留时间,单位：秒
	this.speed = options.speed?options.speed : 50;		//移动速度
	var _this = this;
	var oneScrollHeight = 0;//滚动的一周期中所滚动了的高度
	this.obj.onmouseover = function(){
		_this.scrollAmount = 0;
	};
	this.obj.onmouseout = function(){
		_this.scrollAmount = scrollAmount;
	};
	
	this.obj.innerHTML += this.obj.innerHTML;
	this.run = function(){
		
		this.obj.scrollTop += this.scrollAmount; 
		oneScrollHeight += this.scrollAmount;
		
		if(this.obj.scrollTop == this.lineCount * this.lineHeight){
			this.obj.scrollTop = 0;
			oneScrollHeight = 0;
		};
		if(this.obj.scrollTop % this.lineHeight == 0){
			window.setTimeout(function(){_this.run.apply(_this)},  _this.wait);
			oneScrollHeight = 0;
		}else window.setTimeout(function(){_this.run.apply(_this)},  _this.speed);
	};	
	this.start = function(){
		window.setTimeout( function(){_this.run.apply(_this)}, _this.wait); 
	}; 
};