var WebtvTicker;

WebtvTicker = function ()
{
	
	this._init = false;
	this._running = false;
	this._text = "";
	this._runner = false;
	this._parent = false;
	this._runwidth = 0;
	this._runexec = false;
	
	this.init = function ()
	{
		this._parent = $('playerFooter');
		this._text = this._parent.select('p')[0].innerHTML.replace(/\n/g, '');
		this._text = this._text.split(' ');
		for(var i=this._text.length;i--;){
			if(this._text[i].toLowerCase().substr(0, 4)=='www.') this._text[i] = '<a href="http://'+this._text[i]+'" target="_blank">'+this._text[i]+'</a>';
		}
		this._text = this._text.join(' ');
		
		this._text = this._text+"&nbsp;&nbsp;+++&nbsp;&nbsp;";

		this._parent.update('');
		$(this._parent).setStyle({position:'relative',display:'block',overflow:'hidden',height:'20px',width:'458px'});
		
		try{$('playerFooter_runner').remove();}catch(e){}
		this._runner = document.createElement('div');
		this._runner.setAttribute('id','ticker_runner');
		$(this._parent).appendChild(this._runner);
		$(this._runner).setStyle({position:'absolute',/*width:'auto',*/left:'0px',top:'0px',height:'20px',overflow:'visible',whiteSpace:'pre'});
		
		var _text = this._text; $(this._runner).update(_text);
		var _k = 0;
		while(this._runner.getWidth() < this._parent.getWidth() && _k<20){
			_text += this._text;
			$(this._runner).update(_text);
			_k++;
		}
		this._runwidth = this._runner.getWidth();
		this._text = _text
		this._text += _text;
		this._text += _text;
		$(this._runner).update(this._text);
		$(this._parent).observe('mouseover', this.stop.bind(this));
		$(this._parent).observe('mouseout', this.run.bind(this));
		this._init = true;
		this.run();
		Wlog('webtv.ticker:: init');
	};
	
	this.run = function(){
		if(!this._init) this.init();
		if(!this._running){
			var _obj = this;
			this._runexec = new PeriodicalExecuter(function(pr){
																												 var _div = $('ticker_runner');
																												 var _l = parseInt($(_div).positionedOffset().left,10);
																												 if(Math.abs(_l) >= _obj._runwidth) $(_div).setStyle({left:'0px'});
																												 else $(_div).setStyle({left:(_l-1)+'px'});
																												 }, .05);
			this._running = true;
		}
	};
	
	this.stop = function(){
		if(this._running){
			this._runexec.stop();
			this._running = false;
		}
	};
};

try{
	Webtv.prototype.ticker = new WebtvTicker();
	Webtv_reg.push('ticker');
	Wlog('webtv.ticker:: bound');
}
catch(e){
	Wlog('webtv.ticker:: could not bind myself');
}
