<!-- Hide script from old browsers
startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className += " over";
				}
				node.onmouseout=function() {
					this.className = this.className.replace(" over", "");
				}
			}
		}
	}
}

function findCurrentNav() {
	var nav = document.getElementById('nav');									// Find the main nav
	var links = nav.getElementsByTagName('a');									// Get the links from the main nav
	var current = document.location.toString().toLowerCase().split('/');		// Find the last part of the link href (the page name itself)
	if (current.length > 3) {													// if we're not on the home page
		current = current[current.length - 1];									// set current to the page name
		for (var i=0; i<links.length; i++) {									// iterate through links. If the current page equals the link destination, set that link to current
			var page = links[i].href.toLowerCase().split('/');					// split the path into individual parts
			page = page[page.length-1];											// only use the last part (the page file name. ie, index.shtml)
			
			pageParts = page.replace('.shtml','').split('_');					// for subpages - also split up the file name into sections parts: jc_org = jc, org
			currentParts = current.replace('.shtml','').split('_');				// same as above, but for the current page
			if (page == current) {												// checking to see if we're on the page
				links[i].className += ' current';
			} else if (pageParts.length >= 2 && currentParts.length >= 2 && pageParts[0] == currentParts[0] && pageParts[1] == currentParts[1]) {
																				// checking if we're in the sub-page
				links[i].className += ' current';
			} else {
				// removing other non-selected 'current' links
				links[i].className = links[i].className.replace('current','');
			}
		}
	}
}
// End hiding script from old browsers -->

var swapswap = {
	suffix : "2", // default image file name suffix (before file type suffix, like .jpg)

	/**
	 * init()
	 * Initializes swapswap functionality, finding all img elements with a class of swap 
	 * and attaching the swap() function to them.
	 * @param suff	Optional suffix for mouseover state images. The default is 2, but can be anything you want.
	 */
	init : function(suff) {
		this.suffix = (suff == "") ? this.suffix : suff;			// check for supplied suffix. use default if not found
		var imgs = document.getElementsByTagName("img");			// get all the images on the page
		for (var i=0; i<imgs.length; i++) {
			if(imgs[i].className.indexOf("swap") != -1) {			// find the img.swap elements
				
				var img_path_array = imgs[i].src.split("/");
				var img_file_name = img_path_array[img_path_array.length - 1];	// the image file name
				var img_type = img_file_name.split(".")[1];		// the image type (jpg, gif, png)
	
				var img_alternate = new Image();					// preload the OVER state
				img_alternate.src = imgs[i].src.substring(0, imgs[i].src.length - 4) + this.suffix + "." + img_type;
				
				// attach the swap function to the img.swap elements
				imgs[i].onmouseover = function() { swapswap.swap(this); }
				imgs[i].onmouseout = function() { swapswap.swap(this); }
			}
		}
	},
	
	/**
	 * swap()
	 * Interchanges the src of the supplied image with an alternate image
	 * @param img	An img element
	 */
	swap : function(img) {
		var src = img.src;
		var img_path_array = img.src.split("/");
		var img_file_name = img_path_array[img_path_array.length - 1];
		var img_type = img_file_name.split(".")[1];
		var newSrc = "";																			// Variable to hold the new image to swap in
		if (src.indexOf(this.suffix + "." + img_type) == -1) {										// Check if current image NOT is the MouseOver state image
			newSrc = src.substring(0, src.length - 4) + this.suffix + "." + img_type;				// Swap image src attribute to the MouseOver state image
		} else {																					// current image IS the mouseOver state image
			newSrc = src.substring(0, src.length - (4 + this.suffix.length)) + "." + img_type;		// swap src attribute to the NORMAL state image
		}
		img.src = newSrc;																			// Set the image src attribute
	}
}

window.onload = function() {
	startList();
	swapswap.init("2");
}