var gStartupFunctions = new Array();

function registerStartupFunction( pFunction ) {
	if( pFunction ) gStartupFunctions[gStartupFunctions.length] = pFunction;	
}

function doOnLoad() {
	for(var i=0; i<gStartupFunctions.length; ++i) {
		gStartupFunctions[i]();
	}	
}

onload=doOnLoad;

/* after this don't use onload= to assign startup functions,
	instead use registerStartupFunction( functionName ); */

function pageSetup() {
	var rollover = getElementsByClass("rollover");
	for(var i=0; i<rollover.length; ++i) {
		var imgTag = getFirstChildOfType(rollover[i], "IMG");
		if(imgTag) {
			var preload = new Image();
			preload.src = getOverSource(imgTag.src);
			imgTag.onmouseover=doMouseOver;
			if (imgTag.captureEvents) imgTag.captureEvents(Event.MOUSEOVER);
			imgTag.onmouseout=doMouseOut;
			if (imgTag.captureEvents) imgTag.captureEvents(Event.MOUSEOUT);
		}
	}				
}

registerStartupFunction( pageSetup );

function doMouseOver(e) {
	e = getEventTarget(e);
	e.src=e.src.replace("_off.", "_over.");
}

function doMouseOut(e) {
	e = getEventTarget(e);
	e.src=e.src.replace("_over.", "_off.");
}

function getElementsByClass(pClass, pContainer) {
	pContainer = pContainer||document;
	var allTags = pContainer.all||pContainer.getElementsByTagName('*');
	var result = new Array();

	for(var i=0; i<allTags.length; ++i) {
		if( allTags[i].className == pClass)
			result[result.length] = allTags[i];
	}
	return result;
} 

function getEventTarget(e) {
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	return tg;
}

function getFirstChildOfType(elem, nodeName, recurse) {
	if( !elem.hasChildNodes() ) return null;
		
	elem=elem.childNodes[0];
	while( elem ) {
		if(elem.nodeName == nodeName)
			return elem;
				
		elem=elem.nextSibling;
	}
	return null;
}

function getOverSource(srcString) {
	return srcString.replace("_off.", "_over.");
}