var tickers = [];
var tickercnt = 0;

//loopmode 0 = reverse
//loopmode 1 = shift (doorschuiven)
function textTicker(objID, tickSpeed, startColor, endColor, reverse, loopMode, loopTimeout)
{
	this.obj = document.getElementById(objID);

	this.tickID = tickercnt;
	tickers[tickercnt++] = this;

	this.tickHandle = null;
	this.tickSpeed = tickSpeed;

	this.startColor = startColor;
	this.endColor = endColor;

	this.currentLetter = 0;
	this.numLetters = 0;

	this.loopMode = loopMode;
	this.loopTimeout = loopTimeout

	this.direction = (reverse > 0 ? -1 : 1);

	this.Start = function() {
		if(this.direction > 0) this.currentLetter = 0;
		else this.currentLetter = this.numLetters-1;

		if(this.tickHandle == null)
			this.tickHandle = setInterval("tickers["+this.tickID+"].Tick();", this.tickSpeed);
	}

	this.Stop = function() {
		if(this.tickHandle != null)
		{
			clearTimeout(this.tickHandle);
			this.tickHandle = null;
		}
	}

	this.setString = function(str) {

		var strarr = str.split("");
		var divstr = "";
		var bHTML = false;
		var divid = 0;
		for(var i = 0; i < strarr.length; i++)
		{
			if(strarr[i] == "<" && !bHTML) bHTML = true;
			if(strarr[i] == " " && !bHTML) strarr[i] = "&nbsp;";
			if(!bHTML)
				divstr += "<div id='"+this.obj.id+"_"+(divid++)+"' style='"+(this.startColor.toLowerCase() == "hidden" ? "visibility: hidden" : (this.startColor.toLowerCase() == "visible" ? "visibility: visible" : "color: "+this.startColor))+"; display: inline;'>"+strarr[i]+"</div>";	
			else divstr += strarr[i];
			if(strarr[i] == ">" && bHTML == true) bHTML = false;
		}
		this.numLetters = divid;
		this.obj.innerHTML = divstr;
	}

	this.setString(this.obj.innerHTML);

	this.Tick = function() {
		var div = document.getElementById(this.obj.id+"_"+this.currentLetter);
		if(div != null)
		{
			if(this.direction > 0)
			{
				if(this.endColor.toLowerCase() != "hidden" && this.endColor.toLowerCase() != "visible")
				{
					div.style.color = this.endColor;
					div.style.visibility = "visible";
				}
				else
					div.style.visibility = this.endColor;
			}		
			else
			{
				if(this.startColor.toLowerCase() != "hidden" && this.startColor.toLowerCase() != "visible")
				{
					div.style.color = this.startColor;
					div.style.visibility = "visible";
				}
				else
					div.style.visibility = this.startColor;
			}

			this.currentLetter += this.direction;
		}
		else
		{
			if(this.loopMode == 0)
			{
				this.direction = 0 - this.direction;
				this.currentLetter += this.direction;
			}
			else if(this.loopMode == 1)
			{
				if(this.direction > 0)
					this.currentLetter = 0;
				else
					this.currentLetter = this.numLetters-1;

				var tempColor = this.startColor;
				this.startColor = this.endColor;
				this.endColor = tempColor;
			}

			this.Stop();

			if(this.loopMode != -1)
				setTimeout("tickers["+this.tickID+"].Start();", this.loopTimeout);
		}
	}

	return this;
}