/**
 * Ticker animation support
 * author: Alex Vigdor     copyright 2007 ABCNews Internet Ventures
 **/
var tickerEl = null;
var tickerAnim = new Animation();
var tickerSeq = new Sequence();
var tickerHeadline;
tickerSeq.start=0;
tickerSeq.min=0.5;
tickerSeq.handler = function(val){
	val = Math.round(val);
	tickerEl.innerHTML = tickerHeadline.substring(0,val);
	return val;
}
tickerSeq.callback = function(){
	tickerEl.innerHTML = tickerHeadline;
}
tickerAnim.addSequence(600,tickerSeq);

function tickerOver(show){
	if(window.tickerPl){
		window.tickerPl.gotoItem(show,'skip');
		window.tickerPl.pause();
	}
}

function pauseTickerPl(){
if(window.tickerPl){
	window.tickerPl.pause();
}
}

function resumeTickerPl(){
if(window.tickerPl){
	window.tickerPl.resume();
}
}

function tickerKey(evt){
	if(!evt) var evt = event;
	if(evt.keyCode==40){
		var el = document.getElementById('show-ticker');
		var as = el.getElementsByTagName('a');
		if(as.length > 0){
			as.item(0).focus();
		}
		stopEvent(evt);
		return false;
	}
	else if(evt.keyCode==38){
		var actives = getElementsWithAttribute(document.getElementById('shownav'),'class','showNavActive');
		if(actives.length > 0){
			actives[0].parentNode.focus();
		}
		stopEvent(evt);
		return false;
	}
}

function ticker(headline,url,skip){
	if(masterAnimationController){
		masterAnimationController.cancel(tickerAnim);
	}
	else{
		tickerAnim.cancel(true);
	}
	tickerSeq.end=headline.length;
	tickerSeq.duration = 107 * headline.length;
	tickerHeadline=headline;
	
	tickerAnim.reset();
	var el = document.getElementById("show-ticker");
	while(!isEmpty(el.firstChild)){
		el.firstChild.omnouseover=null;
		el.firstChild.onmouseout=null;
		el.firstChild.onkeydown=null;
		el.removeChild(el.firstChild);
	}
	var ela = document.createElement("a");
	ela.setAttribute("href",url);
	ela.onmouseover=pauseTickerPl;
	ela.onmouseout=resumeTickerPl;
	ela.onkeydown = tickerKey;
	ela.className="tickertext";
	tickerEl = ela;
	el.appendChild(ela);
	if(skip){
		tickerSeq.callback();
	}
	else{
		if(masterAnimationController){
			masterAnimationController.animate(tickerAnim);
		}
		else{
			tickerAnim.run();
		}
	}
}	

function TickerItem(show,headline,url){
	this.id=show;
	this.headline= headline;
	this.url = url;
}
TickerItem.prototype.activate = function(args){
	var skip = (args && (args.length > 0) && (args[0] == 'skip'));
	ticker(this.headline,this.url,skip);
	document.getElementById('show'+this.id).className="showNavActive";
}
TickerItem.prototype.deactivate = function(){
	var el = document.getElementById('show'+this.id);
	el.className="showNavinActive";
}