// Javascript functions to scroll text from left to right

var current_scroll_text; //stores the currently scrolling text
var current_scroll_id = 0; //the unique id the element that contains the text NOTE: This element should conain ONLY the scrolling text.
var scroll_interval_id; //stores the setInterval id that scrolls the text
var scroll_timeout_id; //stores the setTimeout is that stops text scrolling
var moused_in_flag; //tracks whether the mouse is currently over the element that contains the text
var original_scroll_text; //stores the original text before scrolling
var scroll_index; //tracks the start character of the text during scrolling
var scroll_length; //the number of characters that can be shown at once during scrolling

/* Function that starts scrolling, must be activated on the page
 * Cancels the stop scrolling timeout if activated by the currently scrolling element (fixes IE onMouseOut problem)
 * parameter text - The complete text to be scrolled through.
 * parameter id - The id of the element that contains the text. NOTE: This element should conain ONLY the scrolling text.
 * parameter length - The number of characters which can be shown during scrolling.
 */
function startTextScroll(text,id,length) {
	if(current_scroll_id != id) {
		if(current_scroll_id != 0) {
			document.getElementById(current_scroll_id).innerHTML = current_scroll_text.substr(0,scroll_length-3)+"...";
		}
		scroll_index = 0;
		scroll_length = length;
		current_scroll_text = text;
		current_scroll_id = id;
		clearInterval(scroll_interval_id);
		scroll_interval_id = setInterval('textScroll()',150);
	}
	moused_in_flag = true;
	clearTimeout(scroll_timeout_id);
}

/* Function that advances the current text by one character and displays it on the page.
 * After the entire text has been looped through, it resets from the beginning.
 */
function textScroll() {
	if(scroll_index < current_scroll_text.length) {
		document.getElementById(current_scroll_id).innerHTML = current_scroll_text.substr(scroll_index, scroll_length);
		scroll_index++;
	}else {
		scroll_index = 0;
	}
}

/* Function that sets timeout to end scrolling, must be activated on the page
 * parameter id - The id of the element that contains the text.
 */
function textScrollTime(text,id) {
	scroll_timeout_id = setTimeout("endTextScroll('"+id+"')", 500);
	moused_in_flag = false;
}

/* Function that ends scrolling on the current element and resets it to the original text.
 * parameter id - The id of the element that contains the text.
 */
function endTextScroll(id) {
	if(moused_in_flag == false) {
		document.getElementById(current_scroll_id).innerHTML = current_scroll_text.substr(0,scroll_length-3)+"...";
		current_scroll_id = 0;
		clearInterval(scroll_interval_id);
	}
}