function RadTicker(clientID)	
{
	var oldTicker = window[clientID];
	
	if (oldTicker && typeof(oldTicker.Dispose) == "function")
	{
		oldTicker.Dispose();
	}
	oldTicker = null;
	
	this.ClientID = clientID;
	this.ControlElement = document.getElementById(clientID);
	this.CurrentLine = 0;
	this.CurrentLength = 0;
	
	var instance = this;
	
	this.UnLoadHandler = function()
    {
		instance.Dispose();
    };

    this.AttachEvent(window,"unload",instance.UnLoadHandler);
    
    //DESHEV: that will leak function and object references.  a lot!
    if (window.OnCallbackRequestStart)
	{
		var tickerRef = this;
		var funcRef = window.OnCallbackRequestStart;
		window.OnCallbackRequestStart = function()
		{
			tickerRef.ClearTimeouts();
			funcRef();
		}
	}
}

RadTicker.prototype.Dispose = function()
{
	this.disposed = true;
	try
	{
		this.ClearTimeouts();
		
		this.DetachEvent(window, "unload", this.UnLoadHandler);
		this.UnLoadHandler = null;
		
		this.ControlElement = null;
	}
	catch (error)
	{
	}
}

RadTicker.prototype.AttachEvent = function(element, eventName, eventHandler)
{
      try
      {
            if (element.attachEvent)
            {
                  element.attachEvent("on" + eventName, eventHandler);
            }
            else
            {
                  element.addEventListener(eventName, eventHandler, true);
            }
      }
      catch(error)
      {
            //
      }
};

RadTicker.prototype.DetachEvent = function(element, eventName, eventHandler)
{
	if (element == null || eventName == null || eventHandler == null)
		return;
		
	try
	{
		if (element.detachEvent)
		{
			  element.detachEvent("on" + eventName, eventHandler);
		}
		else
		{
			  element.removeEventListener(eventName, eventHandler, true);
		}
	}
	catch(error)
	{
		//
	}
};

RadTicker.prototype.Start = function()
{
	if(this.AutoStart)
	{
		this.StartTicker();	
	}
}

RadTicker.prototype.StartTicker = function()
{
	this.Reset = 1;
	this.TickLine(0);
}

RadTicker.prototype.TickNextLine = function()
{
	this.TickLine(this.CurrentLine);
}

RadTicker.prototype.TickLine = function(which)
{
	if (this.disposed == true)
		return;
		
	this.CurrentLength = 0;
	this.ControlElement.innerHTML = "";
	this.CurrentLine = which;
	this.TickOne(which);
}

RadTicker.prototype.ResetTicker = function()
{
	this.CurrentLength = 0;
	this.ClearTimeouts();
	this.ControlElement.innerHTML = "";
	return;	
}

RadTicker.prototype.TrimString = function(str)
{
	return str.replace(/^\s{1,}/ig, "").replace(/\s{1,}$/ig, "");
};

RadTicker.prototype.TickOne = function(which)
{
	if (this.disposed == true)
		return;
		
	var thetext = this.TrimString(this["TickerLine"+which]);
	var textlen = thetext.length;
	var curlen = this.CurrentLength;
	
	if(curlen < textlen)
	{
		var innerHTML = this.ControlElement.innerHTML;
		if(thetext.charAt(curlen) == '&')
		{
			innerHTML = innerHTML + "&amp;";
		}
		else if (thetext.charAt(curlen) == ' ' && curlen + 1 < textlen && thetext.charAt(curlen + 1) == ' ')
		{
			innerHTML = innerHTML + " " + "&nbsp;";
			this.CurrentLength ++;
		}
		else
		{
			innerHTML = innerHTML + thetext.charAt(curlen);
		}
		this.ControlElement.innerHTML = innerHTML;
		this.CurrentLength ++;
		var instance = this;
		this.tickTimeOut = window.setTimeout(function() {instance.TickOne(which)}, this.TickSpeed);
	}	
	else
	{
		this.OnLineEnd();
	}
}

RadTicker.prototype.ClearTimeouts = function(which)
{
	window.clearTimeout(this.tickTimeOut);
	window.clearTimeout(this.lineTimeOut);
}

RadTicker.prototype.OnLineEnd = function(which)
{
	this.CurrentLength = 0;
	
	var newlinenum = (this.CurrentLine+1) % this.TickerLines;
	
	if( newlinenum <= this.CurrentLine && !this.Loop)
	{
		this.OnTickerEnd();
		return;
	}
	else
	{
		this.CurrentLine = newlinenum;
	}
	
	if(this.AutoAdvance)
	{
		var instance = this;
		this.lineTimeOut = window.setTimeout(function() {instance.TickLine(newlinenum)}, this.LineDuration);
	}
}

RadTicker.prototype.OnTickerEnd = function()
{
	if(this.OnTickerEndCode)
	{
		eval(this.OnTickerEndCode);		
	}
}

//BEGIN_ATLAS_NOTIFY
if (typeof(Sys) != "undefined")
{
    if (Sys.Application != null && Sys.Application.notifyScriptLoaded != null)
    {
        Sys.Application.notifyScriptLoaded();
    }
}
//END_ATLAS_NOTIFY