var char_timeout = 50;
var news_timeout = 5000;
var headlines_length = 250;
var headlines_prefix = "HEADLINES:&nbsp;";
var headlines_count = 0;
var headlines_title = new Array();
var headlines_link = new Array();
// headlines startup
function startHeadlines() {
	// define run time values
	current_news = -1;
	current_length = 0;
	headlines_count = headlines_title.length;
	e_prefix = document.getElementById("headlines_prefix");
	e_link = document.getElementById("headlines_link");
	return (headlines_count == 0) ? false : runHeadlines();   	
}
// headlines main run loop
function runHeadlines() {
	var timeout;
	// go for the next news data block
	if (current_length == 0) {
		//current_news++;
		current_news = Math.round(Math.random() * headlines_count);
		current_news %= headlines_count;
		headlines_news = headlines_title[current_news].replace(/&quot;/g, '"');
		// headlines sub string
		var s = 0;
		if (headlines_news.length > headlines_length) {
			while ((headlines_length - s > 0) && (headlines_news.charAt(headlines_length - s) != ' ')) s++;
			headlines_news = headlines_news.substring(0, headlines_length - s);
		};
		e_prefix.innerHTML = headlines_prefix;
		e_link.href = headlines_link[current_news];
	};
	// stuff the current news text into the anchor
	e_link.innerHTML = headlines_news.substring(0, current_length) + postfix();
	// modify the length for the substring and define the timer
	if (current_length != headlines_news.length) {
		current_length++;
		timeout = char_timeout;
	} else {
		current_length = 0;
		timeout = news_timeout;
	};
	// call up the next cycle of the headlines
	setTimeout("runHeadlines()", timeout);
}
// postfix generator
function postfix() {
	if (current_length == headlines_news.length) return "...";
	return ((current_length % 2) == 1) ? "_" : " ";
}
