ie=false; ns4=false; ns6=false;
if 		(document.all)		{ie=true;}
else if	(document.layers)	{ns4=true;}
else	{ns6=true;}

target=null;
nav=null;
subnav=null;
globalid=null;

document.onmousemove=getTarget;

function getTarget(e)	{
	if (ie)	{
		target=event.srcElement;
	}
	else	{
		target=e.target;
	}
	
	if(subnav) {
		//constantly scanning to see what the mouse's target is
		// if it's not the current nav or the current subnav, then hide the last menu that was open
		if(target != nav && target != subnav && target.parentNode != subnav) {
			subnav = null;
			setTimeout("hideMenu("+globalid+")",500);
		}
	}
}

function dropDown(myid) {
	
	globalid=myid;
	nav = document.getElementById("nav"+myid);
	subnav = document.getElementById("subnav"+myid);
	
	//check to see if any others are down, if they are, hide them
	if(nav) {
		i = 0;
		//will cycle through all possible nav ids. could fail if any integers are skipped when id'ing the nav items
		while(document.getElementById("nav"+i) != null) {
			if("nav"+i != nav.id) {
				hideMenu(i);
			}
			i++;
		}
	}

	//if it has a subnav, then show it
	if(subnav) {
		//goofy thing for positioning the dropdown menu with dynamic values rather than absolute
		offset_x = nav.offsetLeft+nav.offsetParent.offsetLeft+nav.offsetParent.offsetParent.offsetLeft;
		offset_y = nav.offsetTop+nav.offsetHeight+nav.offsetParent.offsetTop+nav.offsetParent.offsetParent.offsetTop+nav.offsetParent.offsetParent.offsetParent.offsetTop;

		//setting the subnav className to dropDown will make it visible
		subnav.className = "dropDown";

		//put it at the right x,y coords
		subnav.style.top = offset_y+"px";
		subnav.style.left = offset_x+"px";	
	}
}
function hideMenu(myid) {
	//get the target
	my_target = document.getElementById("subnav"+myid);

	//make sure the target actually exists
	if(my_target) {
		my_target.className = '';
	}
}