// ------------------------------------------------------------
// Add onload events non-destructively
// ------------------------------------------------------------

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}

// ------------------------------------------------------------
// News tickers
// ------------------------------------------------------------

function tickerInit() {

	num = -1; // Headline index
	pos = 0; // Character index
        
        if ( document.getElementById('ticker') != null ) {
                if ( anchor = document.getElementById('ticker').getElementsByTagName('a')[0]) {
                        if (tickerItems.length) {	
                                tickerNext();
                        }
                }
        }
}
addLoadEvent(tickerInit);

function tickerNext() {
	var delay;  

	if (pos == 0) {
		num = ++num % tickerItems.length;
		link = tickerItems[num].link;
		text = tickerItems[num].text;
	}

	prefix = "";
	string = text.substring(0,pos);
	suffix = tickerFlicker();

	anchor.href = link;
	anchor.innerHTML = prefix + string + suffix;

	if(pos != text.length) {
		pos++;
		delay = 50;
	} else {
		pos = 0;
		delay = 5000;
	}

	setTimeout('tickerNext()', delay);
}

function tickerFlicker() {
	return (pos != text.length) ? (pos%2) ? ' []' : ' &nbsp;' : '';
}

