// JavaScript Document
function seek(ele,type) {
return (type) ? document.getElementById(ele):document.getElementById(ele).style;	
}

//Refers to active flyoutX when flyout is displayed
var current=0;

//Refers to the total height of the Hold Div
totalHeight=0;

//So we can have drop shadows in browsers that aren't IE6
var flyout_pic_ext = ".png";
if (isIE6()) flyout_pic_ext=".gif";

function activestate(div) {
	//Universal variable so we know which nav is open
	current=div;
	
	//Set the on state for the main nav so it stays active
	seek("link"+div, 1).className="link_leftnav_on";
	
	//Set the span to the full width so it connects with the subnav
	seek("trigger"+div).width="140px";
	
	//Find the number of links in the subnav
	numOfLinks=0;
	for (i=0; i<seek("flyout"+div, 1).childNodes.length; i++)
		if (seek("flyout"+div, 1).childNodes[i].nodeName=="A") numOfLinks++;
	numOfLinks--;
	
	//Position the bottom of the flyout
	seek("flyout_buttom").top=numOfLinks*13.8+34+"px";
	
	//Set the height of the hold div so we know where the bottom is
	totalHeight=numOfLinks*13.8+57;
	
	//Choose the correct type of flyout to use, set correct background image and change in height
	if (div<4 || numOfLinks<4) {
		imageBoxType="top";
		seek("flyout"+div).background='url("/graphics/flyout_top'+flyout_pic_ext+'")';
		if (isFF()) deltaHeight=-13;
		else deltaHeight=-27;
	} else if(div<numOfTrigers-4 || numOfLinks<10) {
		//note that the middle box type is used if there are only 3 links and the box would be too short for a bottom type.
		imageBoxType="middle";
		seek("flyout"+div).background='url("/graphics/flyout_middle'+flyout_pic_ext+'")';
		if (isFF()) deltaHeight=-48;
		else deltaHeight=-62;
	} else {
		imageBoxType="bottom";
		seek("flyout"+div).background='url("/graphics/flyout_bot'+flyout_pic_ext+'")';
		if (isFF()) deltaHeight=-141;
		else deltaHeight=-155;
	}
	
	//Set correct change in width for container
	widthString = seek("link"+div, 1).innerHTML;
	if (widthString.length > 17) deltaWidth = widthString.length*6.3+8;
	else deltaWidth = 112;
	if (isIE() && div == 0) deltaWidth -= 9;
	
	//Set the correct position for the hold div based on change in width and height previously calcualted
	holdTop = getRealTop(seek("trigger"+div,1))+deltaHeight;
	holdLeft = getRealLeft(seek("trigger"+div,1))+deltaWidth;
	seek("hold").top=holdTop+"px";
	seek("hold").left=holdLeft+"px";
	
	//Display the flyout
	seek("flyout_buttom").display="block";
	seek("flyout"+div).display="block";
	seek("hold").height=totalHeight+"px";
}

function holdstate(div) {

	if (div==-1)div=current;
	else current=div;
	
	//Display the flyout
	seek("flyout_buttom").display="block";
	seek("flyout"+current).display="block";
	seek("hold").height=totalHeight+"px";
	
	//Set the on state for the main nav so it stays active
	seek("link"+div, 1).className="link_leftnav_on";
}

function inactivestate(div) {

	if (div==-1)div=current;
	else current=div;
	
	//Hide the flyout
	seek("flyout_buttom").display="none";
	seek("flyout"+div).display="none";
	seek("hold").height="0px";
	
	//Set the off state for the main nav so it goes inactive
	seek("link"+div, 1).className="link_leftnav";
}

function getRealLeft(obj) { 
    xPos = obj.offsetLeft; 
    tempEl = obj.offsetParent; 
      while (tempEl != null) { 
          xPos += tempEl.offsetLeft; 
          tempEl = tempEl.offsetParent; 
      } 
    return xPos; 
} 

function getRealTop(obj) {
    yPos = obj.offsetTop; 
    tempEl = obj.offsetParent; 
    while (tempEl != null) { 
          yPos += tempEl.offsetTop; 
          tempEl = tempEl.offsetParent; 
      } 
    return yPos; 
}

function isIE6() {
	return navigator.appVersion.indexOf("MSIE 6.")>=0;
}

function isFF() {
	return navigator.userAgent.indexOf("Firefox")>=0;
}

function isIE() {
	return navigator.appName.indexOf("Internet Explorer")>=0;
}