function Marquee(id,speed,dir,stop)
{
	this.obj = document.getElementById(id);
	this.obj.style.overflow = 'hidden';
	this.speed = 1000/speed;
	this.direction = dir;
	this.coords = new Coords(this,dir);
	this.stopped = false; 
	if(stop)
	{
		if(document.addEventListener)
		{
			this.obj.addEventListener("mouseover",this.stop(this,true),false);
			this.obj.addEventListener("mouseout",this.start(this,true),false);
		} 
		else if(document.attachEvent)
		{
			this.obj.attachEvent("onmouseenter",this.stop(this));
			this.obj.attachEvent("onmouseleave",this.start(this));
		}
		else
		{
			this.obj.onmouseover = this.stop(this);
			this.obj.onmouseout = this.start(this);
		}
	}

	this.obj[this.coords.type] = this.coords.start;
}

Marquee.prototype.stop = function(obj,c)
{
	return function(e)
	{
		if(c && !isMouseLeaveOrEnter(e,this)) return;
		obj.stopped = true;
	}
}

Marquee.prototype.start = function(obj,c)
{
	return function(e)
	{
		if(c && !isMouseLeaveOrEnter(e,this)) return;
		obj.stopped = false;
		obj.scroll();
	}
}

Marquee.prototype.scroll = function()
{
	if(this.coords.inc*this.obj[this.coords.type] >= this.coords.end) this.obj[this.coords.type] = this.coords.start;
	this.obj[this.coords.type] += this.coords.inc;
	if(!this.stopped) setTimeout(this.loop(this),this.speed);
}

Marquee.prototype.loop = function(obj)
{
	return function()
	{
		obj.scroll();
	}
}

function Coords(obj,dir)
{
	var child = obj.obj.getElementsByTagName("*")[0];
	if(dir == 'top' || dir == 'bottom')
	{
		this.type = 'scrollTop';
		child.className += ' vertical';
		this.size = (obj.obj.scrollHeight)-(obj.obj.offsetHeight);
	}
	if(dir == 'left' || dir == 'right')
	{
		this.type = 'scrollLeft';
		child.className += ' horizontal';
		child.style.width = (obj.obj.scrollWidth-obj.obj.offsetWidth)+"px";	
		this.size = obj.obj.scrollWidth-obj.obj.offsetWidth;

	}
	this.inc = 1;
	this.start = 0;
	this.end = this.size;
	if(dir == 'bottom' || dir == 'right')
	{
		this.inc = -1;
		this.start = this.size;
		this.end = 0;
	}
}


function isMouseLeaveOrEnter(e, handler)
{ 
	if (e.type != 'mouseout' && e.type != 'mouseover') return false;
	var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement;
	while (reltg && reltg != handler) reltg = reltg.parentNode;
	return (reltg != handler); 
}