// This array will hold function pointers to the various top lists init functions
var topListInits = new Array();

// This array will hold references to all of the top list objects
var scrollingLists = new Array();

// Attached the top list initilization to the page's onload event.
window.onload = function(){
	runTopListInits();
}

/**
 * This function executes all the top lists' init functions. Typically, this
 * function will be called in the body's onload event. This will initialize
 * all of the top lists by looping over each top list init function that has
 * been stored in the topListInits array.
 */
function runTopListInits() {
	for (i = 0; i < topListInits.length; i++) {
		topListInits[i].call(this);
	}
}

/**
 * This function simply wraps a call to the topListInits push method. Only 
 * functions top list initialization functions should be placed in this array.
 * All functions pushed onto this array will be executed during the 
 * runTopListInits function call that is typically performed in the body's
 * onload event. 
 */
function pushInitFunction(method) {
	topListInits.push(method);
}

/**
 * This function is typically used as a callback for an AJAX call's failure 
 * callback. This will simply display the error information in the DOM element
 * that it is executed from within. This should only run if a responseText 
 * exists in the object passed in. This is a standard piece of browsers' AJAX
 * support.
 */
function reportError(request) {
	if (request.responseText)
		document.write(request.responseText);
}

/** 
 * This class represents a scrolling list using standard javascript's OOP 
 * capabilities. This is neccessary since each scrolling list needs its own
 * concept of time so that it can roll over independently of other lists on
 * the current page. The trick is in the setTimeout function call. Since this 
 * method can only be passed a global function, not an object's method, we 
 * first push a reference to this object on the global array, scrollingLists.
 * Once this closure is created we can rest assured that when the timer 
 * attempts to execute the scrolling list's scroll method that it will be 
 * executing on the object's instance properties. This ensures that we can 
 * have n lists running simultaneously on the same page without fear of 
 * collisions of any sort.
 */
function ScrollingTopList(listDivId, scrollingDivId) {

	//Specify initial delay before marquee starts to scroll on page (ms)
	this.delayb4scroll = 1000; 
	//Specify marquee scroll speed (larger is faster 1-10)
	this.marqueespeed = 1; 
	//Pause marquee onMousever (0=no. 1=yes)?
	this.pauseit = 1; 

	this.copyspeed = this.marqueespeed;
	this.pausespeed = (this.pauseit==0)? this.copyspeed: 0;
	this.actualheight = '';

	this.list = document.getElementById(listDivId);
	this.cross_marquee = document.getElementById(scrollingDivId);
	this.marqueeheight = this.list.offsetHeight;

	// Set up the scrolling syles and dimensions
	this.cross_marquee.style.width = "98%";
	this.cross_marquee.style.position = "absolute";
	this.cross_marquee.style.padding = "2px";

	this.cross_marquee.style.top = 0;

	//if Netscape 7x, add scrollbars to scroll and exit
	if (navigator.userAgent.indexOf("Netscape/7")!=-1) {
		this.cross_marquee.style.height=this.marqueeheight+"px";
		this.cross_marquee.style.overflow="scroll";
		return;
	}

	scrollingLists.push(this);
	var i = scrollingLists.length - 1;
	var to = 'lefttime=setInterval("scrollingLists[' + i + '].scroll()",50)';
	setTimeout(to, this.delayb4scroll);
	
	/**
	 * This method performs the scrolling. Essentially, the inner list 
	 * (cross_marquee) is passed up through the window that is formed when its
	 * enclosing element sets it's overflow style to hidden. The contents of
	 * the inner list appears to scroll up through this window.
	 */
	this.scroll = function() {
		if (!this.tables) {
			this.tables = this.cross_marquee.getElementsByTagName("table");
			this.listTable = this.tables.item(0);
			this.setMouseOver(this.listTable);
		}
		var marquee = this.cross_marquee;
		marquee.style.height = this.listTable.offsetHeight;
		this.actualheight = marquee.offsetHeight;

		if (parseInt(marquee.style.top)>(this.actualheight*(-1)+8)) {
			marquee.style.top=parseInt(marquee.style.top)-this.copyspeed+"px";
		} else {
			marquee.style.top=parseInt(this.marqueeheight)+8+"px";
		}
	}
	
	this.stop = function() {
		this.copyspeed = 0; 
	}

	this.setMouseOver = function(table) {
		var rows = table.getElementsByTagName("tr");
		for (i=0; i<rows.length; i++) {
			rows[i].onmouseover = function() {
				this.copyspeed = 0; 
			}
			rows[i].onmouseout = function() {
				this.copyspeed = this.marqueespeed; 
			}
		}
	}

}

