/*
 * @author  : Greg Wilton
 * @version : 1.0 (2003-11-18)
 *
 * Extensions to the functionality of the CUE javascript
 */
var NavExt = {
/*
 * initialize extensions to the CUE javascript (do on body.onload)
 */
init: function (hasDropdowns, isHierarchical) {
	if (document.getElementById && document.getElementsByTagName) {
		// if the site uses dropdown menus
		if (hasDropdowns == 1) {
			this.addNav1MouseOver("menuTable2");
		}
		// the site must be stuctured with a hierarchical architecture
		if (isHierarchical == 1) {
			var style = [{prop:"color",val:"#990000"}, 
					{prop:"fontWeight",val:"bold"}];
			var found = this.setActiveMenuItem("tools", style);
			if (!found) {
				found = this.setActiveMenuItem("nav1", style);
				if (!found) {
					found = this.setActiveMenuItem("nav2", style);
				}
			}
		}
	}
},

/*
 * changes the style of the menu item that is point to the page being viewed
 */
setActiveMenuItem: function (id, style) {
	var parent = document.getElementById(id);
	if (parent != null)  {
		var a = parent.getElementsByTagName("a");
		var loc = document.location.toString();
		for (var i = a.length - 1; i >= 0; i--) {
			var href = this.getHref(a[i].href, loc);
			if (href == loc) {
				for (var j = style.length - 1; j >= 0; j--) {
					eval("a[i].style." + style[j].prop + "='" 
							+ style[j].val + "'");
				}
				return true;
			}
		}
	}
	return false;
}, 

/*
 * Helper method to aviod cross-browser inconsistencies with the value returned
 * by calling a.href. (assumes all links are absolute from the root ie. /foo)
 */
getHref: function (href, loc) {
	if (href.charAt(0) == "/") {
		var domain = loc.substring(0, loc.findInstance("/", 3));
		return domain + href;
	}
	return href;
},

/* 
 * Enables the whole menu item on the dropdown menus to be clickable 
 * not just the anchor tag
 */
addNav1MouseOver: function (x) {
	var tables = document.getElementsByTagName("TABLE");
	for (var i = tables.length - 1; i >= 0; i--) {
		if (tables[i].className == x) {
			var tds = tables[i].getElementsByTagName("TD");
			for (var j = tds.length - 1; j >= 0; j--) {
				var a = tds[j].getElementsByTagName("A");
				if (a.length > 0) {
					tds[j].$a = a[0];
					tds[j].onclick = function () {
						document.location = this.$a;
					};
					tds[j].style.cursor = "pointer";
				}
			}
		}
	}
}
	
};

/* ***** */

String.prototype.findInstance = function (substring, instance) {
	var counter = 0;
	var pos = -1;
	while (counter < instance && pos < this.length) {
		if (this.charAt(++pos) == substring) {
			counter++;
		}
	}
	return (counter == instance) ? pos : -1;
};