function addSubNavListeners() {
	// Get the current page.
	var cp = document.getElementById('currpage').value;
	// Get the links.
	var navlnks = document.getElementById('surnav_case').getElementsByTagName("a");
	// Run through the links
	for (e = 0; e < navlnks.length; e++) {
		// Get the link.
		var lnk = navlnks[e];
		// When you mouse over it, the subnav appears.
		if (window.addEventListener) {
			lnk.addEventListener('mouseover', subnavOn, false);
/*
			if (lnk.id != cp + '_lnk') {
				//lnk.addEventListener('mouseover', clrOn, false);
				//lnk.addEventListener('mouseout', clrOff, false);
			}
*/
		}
		else {
			if (lnk.id != cp + '_lnk') {
				lnk.setAttribute('onmouseover', 'iesuckssubnavOn(this.id);'); // fader(this.id, "o");
				//lnk.setAttribute('onmouseout', 'fader(this.id, "o", "rev");');
			}
			else {
				lnk.setAttribute('onmouseover', 'iesuckssubnavOn(this.id);');
			}
		}
		// Position it right.
		if (document.getElementById(lnk.id + '_subnav_case')) {
			// Get the subnav case.
			var sd = document.getElementById(lnk.id + '_subnav_case');
			// Apply the left value.
			sd.style.left = (document.getElementById(lnk.id).offsetLeft - 14) + 'px';
			// And the opacity.
			sd.style.opacity = 0;
/*
			// Get the current subnav.
			//var cs = document.getElementById('currsubnav').value;
			// And add the color fade to the subnav's links.
			var snvlnks = sd.getElementsByTagName("a");
			// Run through the links
			for (r = 0; r < snvlnks.length; r++) {
				if (snvlnks[r].className != 'subnav_currpage') {
					// Get the link.
					var knk = snvlnks[r];
					// When you mouse over it, the subnav appears.
					if (window.addEventListener) {
						//knk.addEventListener('mouseover', clrSOn, false);
						//knk.addEventListener('mouseout', clrSOff, false);
					}
					else {
						//knk.setAttribute('onmouseover', 'fader(this.id, "o");');
						//knk.setAttribute('onmouseout', 'fader(this.id, "o", "rev");');
					}
				}
			}
*/
		}
		// And appear the current page's subnav.
		if ((lnk.id == cp + '_lnk') && document.getElementById(lnk.id + '_subnav_case')) {
			document.getElementById(lnk.id + '_subnav_case').style.display = 'block';
			opacity(lnk.id + '_subnav_case', 0, 100, 100);
		}
	}
	// When you mouse off, the subnav disappears.
	if (window.addEventListener) {document.getElementById('nav_buff').addEventListener('mouseout', subnavOff, false);}
	else {
		// IE sucks boiled dick.
		document.getElementById('nav_buff').setAttribute('onmouseout', 'subnavOff()');
		/*
		  var hn = document.createElement('div');
		  hn.style.position = 'absolute'; hn.style.top = '175px'; hn.style.width = '856px'; hn.style.height = '5px'; hn.style.border = '1px solid red';
		  hn.setAttribute('onmouseover', 'subnavOff()');
		  document.getElementById('carapace').appendChild(hn);
		  var vn = document.createElement('div');
		  vn.style.position = 'absolute'; vn.style.top = '222px'; vn.style.width = '856px'; vn.style.height = '5px';
		  vn.setAttribute('onmouseover', 'subnavOff()');
		  document.getElementById('carapace').appendChild(vn);
		  document.getElementById('main_logo').setAttribute('onmouseover', 'subnavOff()');
		*/
	}
}
if (window.addEventListener) {window.addEventListener('load', addSubNavListeners, false);}
else {addSubNavListeners();}


function subnavOn() {
	// Get the current subnav element.
	var csn = document.getElementById('currsubnav');
	// Check if the current subnav case exists and is not the subnav of the calling link.
	if ((document.getElementById(csn.value + '_subnav_case')) && (csn.value != this.id)) {
		// Fade it down.
		opacity(csn.value + '_subnav_case', 100, 0, 100);
		// And take away its display.
		setTimeout("document.getElementById('" + csn.value + '_subnav_case' + "').style.display = 'none';", 200);
	}
	// Set the current subnav to the calling link.
	csn.value = this.id;
	// If the calling link has a subnav case...
	if (document.getElementById(this.id + '_subnav_case')) {
		// Set its position.
		document.getElementById(this.id + '_subnav_case').style.left = (document.getElementById(this.id).offsetLeft - 14) + 'px';
		// Set its display.
		document.getElementById(this.id + '_subnav_case').style.display = 'block';
		// And fade it up.
		if (document.getElementById(this.id + '_subnav_case').style.opacity < 1) {opacity(this.id + '_subnav_case', 0, 100, 100);}
	}
}
function subnavOff(e) {
	if (!e) var e = window.event;
	var tg = (window.event) ? e.srcElement : e.target;
	if (tg.id != 'nav_buff') {return;}
	var reltg = (e.relatedTarget) ? e.relatedTarget : e.toElement;
	while (reltg != tg && reltg.nodeName != 'BODY') {reltg = reltg.parentNode;}
	if (reltg == tg) {return;}

	// Get the active subnav.
	var csn = document.getElementById('currsubnav');
	// And the current page.
	var cp = document.getElementById('currpage');
	// If the active subnav is not the current page and has a subnav case.
	if ((csn.value != (cp.value + '_lnk')) && (document.getElementById(csn.value + '_subnav_case'))) {
		// Fade it down.
		opacity(csn.value + '_subnav_case', 100, 0, 100);
		// And take away its display.
		setTimeout("document.getElementById('" + csn.value + '_subnav_case' + "').style.display = 'none';", 200);
	}
	// Set the active subnav to the calling link.
	csn.value = cp.value + '_lnk';
	// If the calling link has a subnav case...
	if (document.getElementById(cp.value + '_lnk_subnav_case')) {
		// Display it.
		document.getElementById(cp.value + '_lnk_subnav_case').style.display = 'block';
		// And fade it up.
		if (document.getElementById(cp.value + '_lnk_subnav_case').style.opacity < 1) {opacity(cp.value + '_lnk_subnav_case', 0, 100, 100);}
	}
}


/* Internet Explorer sucks the dangling dick. */
function iesuckssubnavOn(objid) {
	// Get the current subnav element.
	var csn = document.getElementById('currsubnav');
	// Check if the current subnav case exists and is not the subnav of the calling link.
	if ((document.getElementById(csn.value + '_subnav_case')) && (csn.value != objid)) {
		// Fade it down.
		opacity(csn.value + '_subnav_case', 100, 0, 100);
		// And take away its display.
		setTimeout("document.getElementById('" + csn.value + '_subnav_case' + "').style.display = 'none';", 200);
	}
	// Set the current subnav to the calling link.
	csn.value = objid;
	// If the calling link has a subnav case...
	if (document.getElementById(objid + '_subnav_case')) {
		// Set its position.
		document.getElementById(objid + '_subnav_case').style.left = (document.getElementById(objid).offsetLeft - 14) + 'px';
		// Set its display.
		document.getElementById(objid + '_subnav_case').style.display = 'block';
		// And fade it up.
		if (document.getElementById(objid + '_subnav_case').style.opacity < 1) {opacity(objid + '_subnav_case', 0, 100, 100);}
	}
}
function iesuckssubnavOff() {
	// Get the active subnav.
	var csn = document.getElementById('currsubnav');
	// And the current page.
	var cp = document.getElementById('currpage');
	// If the active subnav is not the current page and has a subnav case.
	if ((csn.value != (cp.value + '_lnk')) && (document.getElementById(csn.value + '_subnav_case'))) {
		// Fade it down.
		opacity(csn.value + '_subnav_case', 100, 0, 100);
		// And take away its display.
		setTimeout("document.getElementById('" + csn.value + '_subnav_case' + "').style.display = 'none';", 200);
	}
	// Set the active subnav to the calling link.
	csn.value = cp.value + '_lnk';
	// If the calling link has a subnav case...
	if (document.getElementById(cp.value + '_lnk_subnav_case')) {
		// Display it.
		document.getElementById(cp.value + '_lnk_subnav_case').style.display = 'block';
		// And fade it up.
		if (document.getElementById(cp.value + '_lnk_subnav_case').style.opacity < 1) {opacity(cp.value + '_lnk_subnav_case', 0, 100, 100);}
	}
}




// These arrays run from light to dark.
var ofade = ['#FEF7E9', '#FDEFD5', '#FCE7BF', '#FBDFAA', '#F9D695', '#F8CE80', '#F7C66B', '#F6BE55', '#F5B641'];
var bfade = ['#292E34', '#2C3743', '#2F4152', '#314A62', '#345472', '#385E82', '#3B6892', '#3F72A3', '#427CB2'];

function clrOn()   {fader(this.id, 'o');}
function clrOff()  {fader(this.id, 'o', 'rev');}
function clrSOn()  {fader(this.id, 'o');}
function clrSOff() {fader(this.id, 'o', 'rev');}


function fader(objid, clr, dir) {
	// Get the element.
	var obj = document.getElementById(objid);

	// Get the array.
	if (clr == 'o') {var fdr = ofade.slice(0);}
	else            {var fdr = bfade.slice(0);}

	// If it's going down, reverse the array.
	if (dir == 'rev') {fdr.reverse();}

	// Run through the array and fade the color.
	clrme(objid, fdr);
}

function clrme(objid, clrarr) {
	// Set the interval.
	var vtl = 15;
	timer = 0;

	//determine the direction for the blending, if start and end are the same nothing happens
	for (i = 0; i < clrarr.length; i++) {
		setTimeout("ppp('" + objid + "', '" + clrarr[i] + "')", (vtl * timer));
		timer++;
	}
}
function ppp(objid, clr) {document.getElementById(objid).style.color = clr; return true;}




/* Clipped this from Quirksmode: http://www.quirksmode.org/js/findpos.html */
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

