var W3CDOM = (document.createElement && document.getElementsByTagName);

var mouseOvers = new Array();
var mouseOuts = new Array();

/* Ed's Funky Image Replacement Code
============================================================================
Original from http://www.quirksmode.org/. Amended to allow multiple calls 
to different elements. The function will grab any images that are descendants
of the given element and add rollover code to them.
****************************************************************************/
// Run a test to see if the browser will load images
AddLoadEvent(InitInfoDropDowns);

function InitInfoDropDowns(){
	var x = GetElementsByClass('infoDropDown');
	for(i=0; i<x.length; i++){
		x[i].onmouseover = ShowHideInfoDropDowns;
		x[i].onmouseout = ShowHideInfoDropDowns;
		
		var imgs = x[i].getElementsByTagName('img');
		for (var j=0; j<imgs.length; j++){
			AddInfoRollovers(imgs[j]);
		}
	}
}

function AddInfoRollovers(x){
	var j = mouseOuts.length;
	// create pre-loading arrays
	var suffix = x.src.substring(x.src.lastIndexOf('.'));
	mouseOuts[j] = new Image();
	mouseOuts[j].src = x.src;
	mouseOvers[j] = new Image();
	mouseOvers[j].src = x.src.substring(0, x.src.lastIndexOf('.')) + '_over' + suffix;
	// add identifiers to the images for rollover functions to reference
	x.number = j;
}

function ShowHideInfoDropDowns(){
	var ul = this.getElementsByTagName('ul');
	for(i=0; i<ul.length; i++){
		ul[i].style.display = (ul[i].style.display != 'block') ? 'block' : 'none';
	}
	var img = this.getElementsByTagName('img');
	for(j=0; j<img.length; j++){
		img[j].src = (img[j].src.indexOf('_over') == -1) ? mouseOvers[img[j].number].src : mouseOuts[img[j].number].src;
	}
	return false;
}

/* Helper Functions
****************************************************************************/
// Allows you to add multiple function to the onload event
function AddLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
		window.onload = func;
	}else{
		window.onload = function(){
			oldonload();
			func();
		}
	}
}
// Returns an array of elements that have a specific class
function GetElementsByClass(searchClass, domNode, tagName){
	if (domNode == null) domNode = document;
	if (tagName == null) tagName = '*';
	var elem = new Array();
	var tags = domNode.getElementsByTagName(tagName);
	var tcl = " " + searchClass + " ";
	for(i=0, j=0; i<tags.length; i++){
		var test = " " + tags[i].className + " ";
		if (test.indexOf(tcl) != -1)
			elem[j++] = tags[i];
	}
	return elem;
}
