


function Marquee()
{
	var entity ;
	if(typeof arguments[0] == "string"){
		this.id=arguments[0];
		entity = document.getElementById(arguments[0]);
		
	}
	else if(arguments[0]!=null)
	{
		entity = arguments[0];
		if(entity.id!=null && entity.id !="")
		{
			this.id = entity.id;
		}
		else{
			this.id = entity.id = "_MSCLaSS_" + Marquee.count++;
		}
	}
	else{
		throw new Error("未设置要滚动的对象");
	}
	this.direction = this.width = this.height =  this.correct = this.CTL = this.MouseOver = 0;
	this.step = 1;
	this.timer = 300;
	this.directionArray = {"top":0 , "bottom":1 , "left":2 , "right":3};

	entity.style.entityw = entity.style.overflowX = entity.style.overflowY =  entity.style.overflow = "hidden";
	entity.noWrap = true;
	this.IsNotOpera = (navigator.userAgent.toLowerCase().indexOf("opera") == -1);
	Marquee.all[this.id]=this;
	
}
Marquee.count = 0;
Marquee.all={};
Marquee.prototype.stop=function(){
	clearInterval(this.timerID);
}
Marquee.prototype.start=function(){
	if(this._init)
	{
		this._init();
	}
	var T=this;
	clearInterval(this.timerID);
	this.timerID = setInterval(
		"Marquee.all['" + this.id + "'].scroll();"	
		,this.timer);
	
}
Marquee.prototype.pause=function(){
	clearInterval(this.timerID);
	var T=this;
	setTimeout(function(){
		setInterval(
		"Marquee.all['" + T.id + "'].scroll();"	
		,this.timer);
		T=void(0);
	},this.delayTime);
}
Marquee.prototype.Continue=function(){
	
}
Marquee.prototype._init=
Marquee.prototype.init = function()
{	
	this._init=null;
	var entity = document.getElementById(this.id);
	
	if(this.timer < 20)this.timer = 20;
	if(this.width == 0)this.width = parseInt(entity.style.width);
	if(this.height == 0)this.height = parseInt(entity.style.height);
	if(typeof this.direction == "string")this.direction = this.directionArray[this.direction.toString().toLowerCase()];
	this.HalfWidth = Math.round(this.width / 2);
	this.HalfHeight = Math.round(this.height / 2);
	this.BakStep = this.step;
	if(this.width)entity.style.width = this.width;
	if(this.height)entity.style.height = this.height;
	var msobj = this;
	var timer = this.timer;

	if( ( msobj.direction==0 && entity.scrollHeight < entity.offsetHeight ) ||
		( msobj.direction==1 && entity.scrollWidth < entity.offsetWidth )
	 ){
		return;
	 	
	 }
	var entity=document.getElementById(msobj.id);
	msobj.ClientScroll = msobj.direction > 1 ? entity.scrollWidth : entity.scrollHeight;
	if((msobj.direction <= 1 && msobj.ClientScroll <= msobj.height + msobj.step) || (msobj.direction > 1 && msobj.ClientScroll <= msobj.width + msobj.step))
		return;
	entity.innerHTML += entity.innerHTML+"<table style='width:500px;height:500px;visibility:hidden;'><tr><td></td></tr></table>";

	entity.onmouseover = Marquee.domHandlers.onmouseover;
	entity.onmouseout = Marquee.domHandlers.onmouseout;
}
Marquee.domHandlers={
	onmouseover : function()
	{
		var msobj=Marquee.all[this.id];
		msobj.stop();
	},
	onmouseout : function()
	{
		var msobj=Marquee.all[this.id];
		msobj.start();
		
	}
}

Marquee.prototype.scroll = function()
{
	var entity = document.getElementById(this.id);
	switch(this.direction)
	{
		case 0://上
		
			if(entity.scrollTop >= this.ClientScroll)
			{
				entity.scrollTop -= this.ClientScroll;
			}
			entity.scrollTop += this.step;
		break;


		case 2://左
			if(entity.scrollLeft >= this.ClientScroll)
			{
				entity.scrollLeft -= this.ClientScroll;
			}
			entity.scrollLeft += this.step;
		break;

	}
}
