/*---------------------------------------------------------------------------
This is the script file that will generate all the navigation.
---------------------------------------------------------------------------*/
var xmlDoc;
var xmlDoc2;

function importXML(xmlFile, callback)
{
	if(document.implementation && document.implementation.createDocument)
	{
		xmlDoc = document.implementation.createDocument("", "", null);
		xmlDoc.onload = callback;
	}
	else if(window.ActiveXObject)
	{
		xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc.onreadystatechange = function ()
		{
			if(xmlDoc.readyState == 4) callback()
		};
	}
	else
	{
		alert('Your browser can\'t handle this script');
		return;
	}
	xmlDoc.load(xmlFile);
}

function importXML2(xmlFile, callback)
{
	if(document.implementation && document.implementation.createDocument)
	{
		xmlDoc2 = document.implementation.createDocument("", "", null);
		xmlDoc2.onload = callback;
	}
	else if(window.ActiveXObject)
	{
		xmlDoc2 = new ActiveXObject("Microsoft.XMLDOM");
		xmlDoc2.onreadystatechange = function ()
		{
			if(xmlDoc2.readyState == 4) callback()
		};
	}
	else
	{
		alert('Your browser can\'t handle this script');
		return;
	}
	xmlDoc2.load(xmlFile);
}

function drawNavDropDown()
{
	var xmlNavigation = xmlDoc.documentElement;
	var navigationDiv = document.getElementById("navDropDown");
	var strOutput = "";
	var tempMenuSrc;
	var tempMenuName;
	var tempDropDownBoxId;
	var tempRootMenuId;
	var tempMenuItemId;
	var isIE = (navigator.appName.indexOf("Microsoft")!=-1) ? 0 : 1;

	strOutput += "<div id=\"navDropDownDiv\" class=\"navigationDropDownSystem\">";

	for(var i=0;i<xmlNavigation.childNodes.length;i++)
	{
		if(xmlNavigation.childNodes[i].nodeName == "dropdownmenu")
		{
			for(var n=0;n<xmlNavigation.childNodes[i].childNodes.length;n++)
			{
				if(xmlNavigation.childNodes[i].childNodes[n].nodeName == "ddurl")
				{
					tempMenuSrc = xmlNavigation.childNodes[i].childNodes[n].getAttribute("src");
					tempMenuName = xmlNavigation.childNodes[i].childNodes[n].firstChild.nodeValue;

					tempDropDownBoxId = tempMenuName.replace(/\W/gi, "r") + "_dropdownbox";
					tempRootMenuId = tempMenuName.replace(/\W/gi, "r") + "_rootmenu";
					tempMenuItemId = tempMenuName.replace(/\W/gi, "r") + "_menuitem";

					if(n == isIE)
					{
						strOutput += "<span class=\"rootLink\" ";
						strOutput += "id=\""+tempRootMenuId+"\" ";
						strOutput += "onMouseOver=\"showDropDownMenu('"+tempRootMenuId+"', '"+tempDropDownBoxId+"');\" ";
						strOutput += "onMouseOut=\"hideDropDownMenu('"+tempRootMenuId+"', '"+tempDropDownBoxId+"');\" ";
						strOutput += "onClick=\"window.location.href='"+tempMenuSrc+"'\">";
						strOutput += tempMenuName;
						strOutput += "</span>";
						strOutput += "<div id=\""+tempDropDownBoxId+"\" class=\"dropDownBox\" ";
						strOutput += "onMouseOver=\"showDropDownMenu('"+tempRootMenuId+"', '"+tempDropDownBoxId+"');\" ";
						strOutput += "onMouseOut=\"hideDropDownMenu('"+tempRootMenuId+"', '"+tempDropDownBoxId+"');\">";
					}
					else
					{
						strOutput += "<div id=\""+tempMenuItemId+"\" ";
						strOutput += "class=\"dropDown\" ";
						strOutput += "onMouseOver=\"highlightSubMenu('"+tempMenuItemId+"');\" ";
						strOutput += "onMouseOut=\"unhighlightSubMenu('"+tempMenuItemId+"');\" ";
						strOutput += "onClick=\"window.location.href='"+tempMenuSrc+"'\">";

						strOutput += tempMenuName;

						strOutput += "</div>";
					}

					if(n == (xmlNavigation.childNodes[i].childNodes.length - 1 - isIE))
					{
						strOutput += "</div>";
					}
				}
			}
		}
	}
	
	strOutput += "</div>";
	navigationDiv.innerHTML = strOutput;
}

function getElementLeft(Elem)
{
	if(navigator.appVersion >= 4 && navigator.appName == "Netscape")
	{
		var elem = getObjNN4(document, Elem);
		return elem.pageX;
	}
	else
	{
		var elem;
		if(document.getElementById)
		{
			var elem = document.getElementById(Elem);
		}
		else if (document.all)
		{
			var elem = document.all[Elem];
		}
		xPos = elem.offsetLeft;
		tempEl = elem.offsetParent;
		while (tempEl != null)
		{
			xPos += tempEl.offsetLeft;
			tempEl = tempEl.offsetParent;
		}
		return xPos;
	}
}

function getElementTop(Elem)
{
	if(navigator.appVersion >= 4 && navigator.appName == "Netscape")
	{
		var elem = getObjNN4(document, Elem);
		return elem.pageY;
	}
	else
	{
		if(document.getElementById)
		{
			var elem = document.getElementById(Elem);
		}
		else if (document.all)
		{
			var elem = document.all[Elem];
		}
		yPos = elem.offsetTop;
		tempEl = elem.offsetParent;
		while (tempEl != null)
		{
			yPos += tempEl.offsetTop;
			tempEl = tempEl.offsetParent;
		}
		return yPos;
	}
}

function getElementHeight(Elem) 
{
	if (navigator.appVersion >= 4 && navigator.appName == "Netscape")
	{
		var elem = getObjNN4(document, Elem);
		return elem.clip.height;
	}
	else
	{
		if(document.getElementById)
		{
			var elem = document.getElementById(Elem);
		}
		else if(document.all)
		{
			var elem = document.all[Elem];
		}
		if(navigator.userAgent.indexOf('Opera') != -1)
		{ 
			var xPos = elem.style.pixelHeight;
		}
		else
		{
			var xPos = elem.offsetHeight;
		}
		return xPos;
	} 
}

var hideDropDownInterval = new Array();
function showDropDownMenu(rootId, menuId)
{
	clearInterval(hideDropDownInterval[rootId]);

	var menuObject = document.getElementById(menuId);

	document.getElementById(rootId).className = "rootLinkOver";

	if(menuObject.innerHTML.length > 5)
	{
		menuObject.style.top = getElementTop(rootId) + getElementHeight(rootId);
		menuObject.style.left = getElementLeft(rootId);
		menuObject.style.visibility = "visible";
	}
}

function hideDropDown(rootId, menuId)
{
	document.getElementById(menuId).style.visibility = "hidden";
	document.getElementById(rootId).className = "rootLink";
}

function hideDropDownMenu(rootId, menuId)
{
	clearInterval(hideDropDownInterval[rootId]);
	document.getElementById(rootId).className = "rootLink";
	hideDropDownInterval[rootId] = setInterval("hideDropDown('"+rootId+"', '"+menuId+"')", 1000);
}

function highlightSubMenu(itemId)
{
	document.getElementById(itemId).className = "dropDownOver";
}

function unhighlightSubMenu(itemId)
{
	document.getElementById(itemId).className = "dropDown";
}

function initNavDropDown()
{
	document.write("<div id=\"navDropDown\"></div>");
	importXML("navigation.xml", drawNavDropDown);
}

function initNavFooter()
{
	document.write("<div id=\"navFooter\"></div>");
	importXML2("navigation.xml", drawNavFooter);
}

function initNavIndexNav()
{
	document.write("<div id=\"navIndexNav\"></div>");
	importXML("navigation.xml", drawIndexNav);
}

function drawNavFooter()
{
	var xmlNavigation = xmlDoc2.documentElement;
	var navigationDiv = document.getElementById("navFooter");
	var tempMenuName;
	var tempMenuSrc;
	var strOutput = "";
	var isIE = (navigator.appName.indexOf("Microsoft")!=-1) ? 0 : 1;

	strOutput += "<div>";

	for(var i=0;i<xmlNavigation.childNodes.length;i++)
	{
		if(xmlNavigation.childNodes[i].nodeName == "dropdownmenu")
		{
			for(var n=0;n<xmlNavigation.childNodes[i].childNodes.length;n++)
			{
				if(xmlNavigation.childNodes[i].childNodes[n].nodeName == "ddurl")
				{
					tempMenuSrc = xmlNavigation.childNodes[i].childNodes[n].getAttribute("src");
					tempMenuName = xmlNavigation.childNodes[i].childNodes[n].firstChild.nodeValue;

					strOutput += "<a href=\""+tempMenuSrc+"\" class=\"footerNav\">";
					strOutput += tempMenuName;
					strOutput += "</a>";
					strOutput += "";
					strOutput += "";

					strOutput += "<span class=\"footerNav\">&nbsp;|&nbsp;</span>";
				}
			}
		}
	}
	
	strOutput += "</div>";
	navigationDiv.innerHTML = strOutput;
}

function drawIndexNav()
{
	var xmlNavigation = xmlDoc.documentElement;
	var navigationDiv = document.getElementById("navIndexNav");
	var tempMenuName;
	var tempMenuSrc;
	var tempMenuItemId;
	var strOutput = "";
	var tableCounter = 0;
	var isIE = (navigator.appName.indexOf("Microsoft")!=-1) ? 0 : 1;

	strOutput += "<div>";
	strOutput += "<table><tr>";

	for(var i=0;i<xmlNavigation.childNodes.length;i++)
	{
		if(xmlNavigation.childNodes[i].nodeName == "dropdownmenu")
		{
			for(var n=0;n<xmlNavigation.childNodes[i].childNodes.length;n++)
			{
				if(xmlNavigation.childNodes[i].childNodes[n].nodeName == "ddurl")
				{
					tempMenuSrc = xmlNavigation.childNodes[i].childNodes[n].getAttribute("src");
					tempMenuName = xmlNavigation.childNodes[i].childNodes[n].firstChild.nodeValue;
					tempMenuItemId = tempMenuName.replace(/\W/gi, "r") + "_menuitem";

					strOutput += "<td align=\"left\">";
					strOutput += "<a href=\""+tempMenuSrc+"\" class=\"indexNav\" ";
					strOutput += "onMouseOver=\"document.images['"+tempMenuItemId+"'].src='images/mouseOverIndexNav.gif'\" ";
					strOutput += "onMouseOut=\"document.images['"+tempMenuItemId+"'].src='images/mouseOffIndexNav.gif'\" >";
					
					strOutput += "<img align=\"absmiddle\" id=\""+tempMenuItemId+"\" border=\"0\" src=\"images/mouseOffIndexNav.gif\" />&nbsp;";
					strOutput += tempMenuName;

					strOutput += "</a>";
					strOutput += "";
					strOutput += "</td>";
					
					//if((tableCounter++)%2) strOutput += "</tr><tr>";
					strOutput += "</tr><tr>";
				}
			}
		}
	}
	strOutput += "</tr></table>";
	strOutput += "</div>";
	navigationDiv.innerHTML = strOutput;
}