var promoTicker = function(id, target, string, top, left, bottom, right)
{
	this.myid = id;
	this.updateTime = 100;
	this.myString = string;
	this.myTarget = target;
	this.myTop = top;
	this.myLeft = left;
	this.myRight = right;
	this.myBottom = bottom;
	this.myWidth = right - left;
	this.myHeight;
	this.shift = -this.myWidth;
	this.running = false;
	this.myTimeStamp;
	
	this.initBox = function()
	{
		this.shift = -this.myWidth;
		document.getElementById(this.myTarget).style.left = this.myLeft - this.shift + "px";
		document.getElementById(this.myTarget).style.width = "auto"
		document.getElementById(this.myTarget).innerHTML = this.myString; 
		//try and force the element to be the right size so it doesn't wrap the text 
		var tempWidth = document.getElementById(this.myTarget).clientWidth;
		// now make it really wide and see how high it is
		document.getElementById(this.myTarget).style.width = 10000 + "px";
		var tempHeight = document.getElementById(this.myTarget).clientHeight;
		//now put it back to the original width 
		document.getElementById(this.myTarget).style.width = tempWidth + "px";
		while (document.getElementById(this.myTarget).clientHeight > tempHeight)
		{
			tempWidth+=10;
			document.getElementById(this.myTarget).style.width = tempWidth + "px";		
		}
		//document.getElementById('debug').innerHTML = document.getElementById(this.myTarget).clientWidth;
		document.getElementById(this.myTarget).style.top = (((this.myBottom - (this.myTop + tempHeight))/2) + this.myTop) + "px";
		document.getElementById(this.myTarget).style.left = this.myLeft - this.shift + "px";
		document.getElementById(this.myTarget).style.overflow = "hidden";
		this.myHeight = tempHeight;
		document.getElementById(this.myTarget).style.clip = "rect(" + 0 + "px, " + (this.myWidth + this.shift) + "px, " + this.myHeight + "px, " + this.shift + "px)";
		this.running = true;
	}
	
	this.doShift = function()
	{
		var now = new Date();
		// how long since we last did a shift
		var diff = now.valueOf() - this.myTimeStamp.valueOf();
		// we want to shift 4 pixels per 50 ms roughly
		var myShift = Math.round((diff/50)*4);
		if (myShift > 20)
		{
			this.shift = this.shift + 20;
			this.myTimeStamp = new Date();
		}
		else
		{
			this.shift = this.shift + myShift;
			this.myTimeStamp = new Date(this.myTimeStamp.valueOf() + ((myShift*50)/4));
		}
			
		// now update the time stamp to reflect the 
		//document.getElementById("debug").innerHTML = document.getElementById(this.myTarget).clientWidth + " " + this.shift + " " + (this.myWidth + document.getElementById(this.myTarget).clientWidth);
		document.getElementById(this.myTarget).style.left = this.myLeft - this.shift + "px";
		document.getElementById(this.myTarget).style.clip = "rect(" + 0 + "px, " + (this.myWidth + this.shift) + "px, " + this.myBottom + "px, " + this.shift + "px)";
	}
}

promoTicker.prototype.updateTicker = function()
{
	if (this.myTimeStamp == null)
	{
		this.myTimeStamp = new Date();
	}
	this.doShift();
	if (this.shift > document.getElementById(this.myTarget).clientWidth)
	{
		//document.getElementById("debug").innerHTML = "stopped"
		this.running = false;
	}
	else
	{
		this.running = true;
	}
}

promoTicker.prototype.init = function()
{
	this.initBox();
}

promoTicker.prototype.updateText = function(string)
{
	this.myString = string;
}

promoTicker.prototype.running = function()
{
	return this.running;
}







