// Add onmouseover and onmouseout functions to add and remove an 'over' class to the LI tags in the navigation DIV tag
// Used to show and hide floating subnavigation lists in Internet Explorer, because it doesn't apply the :hover pseudo-class to LI tags
function styleLIs(objId){
	for(var i = 0; i < objId.childNodes.length; i++){
		var node = objId.childNodes[i];
		if(node.nodeName == "LI"){
			node.onmouseover = function(){this.className += " over"; this.className = this.className.replace(/^\s*|\s*$/g,"");};
			node.onmouseout = function(){this.className = this.className.replace("over", ""); this.className = this.className.replace(/^\s*|\s*$/g,"");};
			styleLIs(node);
		}else if(node.nodeName == "UL"){styleLIs(node)}
	}
}

// Name of the id that holds the site navigation UL tag
var navId = "navprimaryholder";

// Call the styleLIs function at the onload event if the browser is Internet Explorer
//window.onload = function(){if(document.all && document.getElementById)styleLIs(document.getElementById(navId))}

var rslt;
var loaded = false; // Declares that images have not been loaded.

function newImg(img_src){ // Creates new image objects and loads the urls imto the browser's memory cache. Called by the loadImg function.
	if (document.images){ // Checks for the existence of the images[] array (JavaScript 1.1 and higher).
		rslt = new Image(); // Creates the image object.
		rslt.src = img_src; // Assigns the image source url to the new image object.
		return rslt; // Returns the result to the loadImg funtion.
	}
}

function loadImg(){ // Passes the urls to the newImg function.
	if (document.images){ // Checks for the existence of the images[] array (JavaScript 1.1 and higher).

		// Begin Images Sources
		var img1 = newImg("images/main_aboutus_o.gif");
		var img2 = newImg("images/main_professionals_o.gif");
		var img3 = newImg("images/main_practiceareas_o.gif");
		var img4 = newImg("images/main_offices_o.gif");
		var img5 = newImg("images/main_publications_o.gif");
		var img6 = newImg("images/main_events_o.gif");
		var img7 = newImg("images/main_careers_o.gif");
		// End Images Sources

		loaded = true; // Lets the swapImg funtion know the images are loaded.
	}
}

// Swap images
var swapped = false; // Declares that no images are currently swapped.
var active_extension = "_o"; // Sets the filename extension for image active states.
var restore_info = new Array(); // Holds the image object names and urls for swapped images.
function swapImg(){ // Swaps and restores single or multiple images. Called by any event handler, usually onMouseOver.
	if (document.images && loaded == true && swapped == false){ // Performs if the images[] array (JavaScript 1.1 and higher) exists and if the loadImg function has completed.
		for (var i = 0; i < swapImg.arguments.length; i++){ // Loops for each set of two arguments (image name and url) passed by the event handler.
			restore_info[i * 2] = swapImg.arguments[i]; // Assigns the image name to the restore_info[] array.
			restore_info[i * 2 + 1] = document[swapImg.arguments[i]].src; // Assigns the original url to the restore_info[] array.
			document[swapImg.arguments[i]].src = document[swapImg.arguments[i]].src.substring(0, document[swapImg.arguments[i]].src.lastIndexOf('\.')) + active_extension + document[swapImg.arguments[i]].src.substring(document[swapImg.arguments[i]].src.lastIndexOf('\.')); // Assigns the new url to the image object.
		}
	} else if (document.images && loaded == true && swapped == true){ // Restores all swapped but non-locked images to their original urls. Called by any event handler, usually onMouseOut.
		for (var i = 0; i < restore_info.length; i += 2) document[restore_info[i]].src = restore_info[i + 1]; // Assigns the original url to the image object.
		restore_info = new Array(); // Resets the saved restore information.
	}
	swapped = !swapped; // Flips the swapped flag between swap and restore functionality.
}

// Call the loadImg function to preload the over-state navigation images
window.onload = function(){loadImg()}
