// JavaScript Document
//window.onload = rolloverInit;

addOnload(rolloverInit);

function rolloverInit() {
	for (var i=0; i<document.images.length; i++) {
		if (document.images[i].className == "rollover") {
			setupRollover(document.images[i]);
		}
	}
}

function setupRollover(thisImage) {
	thisImage.outImage = new Image();
	thisImage.outImage.src = thisImage.src;
	thisImage.onmouseout = rollOut;

	thisImage.overImage = new Image();
	thisImage.overImage.src = parseDirectory(thisImage.src) + thisImage.id + "down.png";
	thisImage.onmouseover = rollOver;
}


function rollOver() {
	this.src = this.overImage.src;
}

function rollOut() {
	this.src = this.outImage.src;
}

function addOnload(newFunction) {
	var oldOnload = window.onload;
	
	if (typeof oldOnload == "function") {
		window.onload = function() {
			if (oldOnload) {
				oldOnload();
			}
			newFunction();
		}
	}
	else {
		window.onload = newFunction;
	} 
}


/* 
 * Returns the directory part of the given file path, if any.
 */
function parseDirectory(filePath)
{
	var dir = ""; // no path
	
	if (filePath == null) return dir;
	
	var i = filePath.lastIndexOf("/");
	if (i >= 0)
	{
		dir = filePath.substring(0, i+1);
	}
	return dir;
}
