// Javascript Dropdown Navigation
// version 1.1 - 9/11/2008
// Courtesy of Orlando Marin
var ddStatus = 0;
var lastDD;
var curDD;
var openTimer;
var collapseTimeout;
var delay = 17; //smaller is faster
var deltapx = 1000; //smaller is smoother and slower
var re = /(\d+)px/i
var expandNav;
var contractNav
var nc;
var idc;
var alphaSet = false; //true to enable opacity fade, false to disable
var openUnder = true; //true to enable the dropdown opening under its respective trigger.  Not fully developed.
var macFF;
var macFFre = new Array(/Gecko\/[\d]+/i,/Macintosh/i);

if(navigator.userAgent.match(macFFre[0]) && navigator.userAgent.match(macFFre[1])) {
	macFF = true;
}
else { macFF = false; }

function ddOpen(id, IEleft) {
	nc=document.getElementById("navContent");
	if (id == "navContent") { 
		idc = document.getElementById(lastDD+"DropNav");
		curDD = lastDD;
	}
	else {
		idc = document.getElementById(id.toString()+"DropNav");
		curDD = id.toString();
	}
	nc.innerHTML = idc.innerHTML;
	clearInterval(expandNav);
	clearInterval(contractNav);
	ddStatus = 1;
	lastDD = curDD;
	if (openUnder == true && IEleft) {
		//if(navigator.appName == "Microsoft Internet Explorer"){
			nc.style.left = IEleft + "px";
		//} else {
		//	nc.style.left = document.getElementById(id).offsetLeft + "px";
		//}
	}

	expandNav=setInterval('if (!nc.style.height.toString().match(re)) { nc.style.height="0px"; } ncSize = nc.style.height.toString().match(re);if (ncSize.length > 0 && ((parseInt(ncSize[1]) + deltapx) < nc.scrollHeight) ) { nc.style.height = (parseInt(ncSize[1]) + deltapx) + "px";  if (alphaSet == true) {  if (macFF == false) {    nc.style.opacity=parseFloat((parseInt(ncSize[1])/nc.scrollHeight),2);    nc.style.filter="alpha(opacity = "+Math.round(parseFloat((parseInt(ncSize[1])/nc.scrollHeight),2)*100,0)+")";  }  else {   nc.childNodes[0].style.background = \'url("/images/85trans.png") repeat\';  } }}else {  nc.style.height = nc.scrollHeight + "px";  if (alphaSet == true && macFF == false) {   nc.style.opacity=1;   nc.style.filter="alpha(opacity = 100)"; } clearInterval(expandNav); ddStatus = 2;}',delay);
}
function ddClose(id) {
	nc=document.getElementById("navContent");
	if (id == "navContent") { 
		idc = document.getElementById(lastDD+"DropNav");
	}
	else {
		idc = document.getElementById(id.toString()+"DropNav");
	}
	ddStatus = 3;
	clearInterval(expandNav);
	clearInterval(contractNav);
	contractNav=setInterval('ncSize = nc.style.height.toString().match(re);if (ncSize.length > 0 && ((parseInt(ncSize[1]) - deltapx) > 0) ) {  nc.style.height = (parseInt(ncSize[1]) - deltapx) + "px"; if (alphaSet == true) {  if (macFF == false) {    nc.style.opacity=parseFloat((parseInt(ncSize[1])/nc.scrollHeight),2);   nc.style.filter="alpha(opacity = "+Math.round(parseFloat((parseInt(ncSize[1])/nc.scrollHeight),2)*100,0)+")";  }  else {   nc.childNodes[0].style.background = \'url("/images/85trans.png") repeat\';  } }} else { nc.style.height = "0px"; if (alphaSet == true && macFF == false) {   nc.style.opacity=0;  nc.style.filter="alpha(opacity = 0)"; }  ddStatus = 0; clearInterval(contractNav);}',delay);
}
function ddToggle(id,direction, IEleft) {
	this.id = id;
	if (this.id.toString() == "navContent") {
		if (direction == "open") {
			if (ddStatus == 3) {
				clearTimeout(collapseTimeout);
				clearInterval(contractNav);
				ddOpen(lastDD, IEleft);
			}
			else if (ddStatus == 1) {
				clearTimeout(collapseTimeout);
			}
			else if (ddStatus == 2) {
				clearTimeout(collapseTimeout);
			}
		}
		else if (direction == "close") {
			if (ddStatus == 2) {
				clearInterval(openTimer);
				collapseTimeout=ddClose(this.id);
			}
			else if (ddStatus == 1) {
				collapseTimeout=ddClose(this.id);
			}
			else {
				clearInterval(openTimer);
				ddClose(this.id);
			}
		}
	}
	else {
		if (direction == "open") {
			clearInterval(openTimer);
			document.getElementById('navContent').style.background = 'url(/images/2010_spring/topnav/'+this.id+'_bg.gif) no-repeat';
			if (ddStatus == 2) {
				if (lastDD != this.id.toString()) {
					clearTimeout(collapseTimeout);
					ddClose(lastDD);
					openTimer=setInterval(function() {
						if (ddStatus == 0) { ddOpen(this.id.toString(),IEleft);clearInterval(openTimer); }
					},50);
				}
				else {
					clearTimeout(collapseTimeout);
					clearInterval(contractNav);
					ddOpen(this.id.toString(),IEleft);
				}
			}
			else if (ddStatus == 1) {
				if (lastDD != this.id.toString()) {
					clearInterval(expandNav);
					clearTimeout(collapseTimeout);
					clearInterval(openTimer);
					ddClose(curDD);
					openTimer=setInterval(function() {
						if (ddStatus == 0) { ddOpen(this.id.toString(),IEleft);clearInterval(openTimer); }
					},50);
				}
				else {
					clearInterval(contractNav);
					clearTimeout(collapseTimeout);
					clearInterval(openTimer);
					ddOpen(id.toString(),IEleft);
				}
			}
			else if (ddStatus == 3) {
				if (lastDD != this.id.toString()) {
					clearTimeout(collapseTimeout);
					openTimer=setInterval(function() {
						if (ddStatus == 0) { ddOpen(this.id.toString(),IEleft);clearInterval(openTimer); }
						},50);
				}
				else {
					clearTimeout(collapseTimeout);
					clearInterval(contractNav);
					ddOpen(this.id.toString(),IEleft);
				}
			}
			else if (ddStatus == 0) {
				ddOpen(this.id.toString(),IEleft);
			}
		}
		else if (direction == "close") {
			clearInterval(openTimer);
			collapseTimeout=setTimeout('ddClose(this.id);',500);
		}
	}
}