Ticker = function(ticker_id)
{
    this.TickerSpeed = 2;
    this.TickerWaitTime = 15; //s
	
    this.TickerID = ticker_id;
    this.TickerInterval = "";
	this.EventListener = "";
    this.TickerTimeout = "";
    this.TickerHalt = false;
	
	this.Text = "";
	
	this.Ticker = "";
    var self = this;
    
    this.initTicker = function(ticker_reset)
    {
        clearTimeout(this.TickerTimeout);      
		
        if(ticker_reset)
		{
			this.Ticker = document.getElementById('ticker_' + this.TickerID);
			this.Text = this.Ticker.getElementsByTagName('span').item(0);
			
			var text_width = this.Text.offsetWidth;
			var ticker_width = this.Ticker.offsetWidth;
			
            this.Text.style.marginLeft = ticker_width + "px";

            this.TickerInterval = setInterval(run = function() { self.runTicker(false) }, 50);
		}
		else
		{
            this.TickerInterval = setInterval(run = function() { self.runTicker(true) }, 50);
		}	
		this.EventListener = setInterval(this.listenMouseEvents, 1);
    }
    
    this.runTicker = function(out)
    {     
        if(!this.TickerHalt)
        {
            var text_margin = Math.round(this.Text.style.marginLeft.substring(0, this.Text.style.marginLeft.length - 2));
			if(out)
			{
				if(text_margin - this.TickerSpeed <= (this.TickerSpeed + this.Text.offsetWidth) * -1)
				{
					this.Text.style.marginLeft = this.Ticker.offsetWidth + "px";
					clearInterval(this.TickerInterval);
					self.initTicker(true);
				}
				else
					this.Text.style.marginLeft = text_margin - this.TickerSpeed + "px";
			}	
			else
			{
				if(text_margin - this.TickerSpeed <= this.TickerSpeed + 9)
				{
					this.Text.style.marginLeft = 9 + "px";
					clearInterval(this.TickerInterval);
					this.TickerTimeout = setTimeout(run = function() { self.initTicker(false); }, this.TickerWaitTime * 1000);
				}
				else
					this.Text.style.marginLeft = text_margin - this.TickerSpeed + "px";
			}
        }
    }
	
	this.listenMouseEvents = function()
	{
		self.Ticker.onmouseover = self.pauseTicker;
		self.Ticker.onmouseout = self.resumeTicker;
	}
    
    this.pauseTicker = function()
    {
        self.TickerHalt = true;
    }
    
    this.resumeTicker = function()
    {
        self.TickerHalt = false;
    }
}