///////////////////////////////////////////////////////////////////////////////
// series of functions used to write the dynamic navigation using the        //
// navXML.js file                                                            //
///////////////////////////////////////////////////////////////////////////////

//for flyouts
	yCoord = -10 //150
	yCoordPlus = 24 //42
	xCoord = 105 //220
	strLayersList = ""
	subNavLength = 0

strLayerCode = ""

//strBreadCrumb = "<a href='/index.html' class='utility-link'>Home</a>"
strBreadCrumb = ""

var numOfMenus = 0; // Number of the Main menus
var numOfImages = 0; // Number of rollover button images
strLayersList = ""
strLinksList = ""	//used to track all links

//layersList = new Array("L1","L2","L2-1","L3","L4");
//layersList = strLayersList.split(",")
//alert(layersList[0])
var layerCount = 0; // Total number of the Main and the Sub menus
var linksCount = 0

var ns5 = ((navigator.userAgent.indexOf("Gecko")>-1) ) ? true: false;
var ns4 = (document.layers && !dom) ? true : false;






function navShowChildren(oNode,currentLevel){

	var i=0
	
	//get children of this node
	var oChildNode = oNode.getChildNodes()
	
	//number of children in this sub nav
	var nodeLength = oChildNode.getLength()
	
	numOfMenus = nodeLength
	
	//loop through navigation elements
	for (i=0;i<nodeLength;i++){
		var bHasChildren = false
		//get attributes
		var cNode = oChildNode.item(i)
		var cTitle = oChildNode.item(i).getAttributes().getNamedItem("title").getNodeValue();
		var cId = oChildNode.item(i).getAttributes().getNamedItem("id").getNodeValue();
		var cLevel = oChildNode.item(i).getAttributes().getNamedItem("level").getNodeValue();
		var cHeaderImage = oChildNode.item(i).getAttributes().getNamedItem("hdrImage").getNodeValue();
		var cFile = oChildNode.item(i).getAttributes().getNamedItem("file").getNodeValue();
		var cTarget = oChildNode.item(i).getAttributes().getNamedItem("target").getNodeValue();
		
		var cClass = "lnav_link"
		var cTdBgColor = "#FFFFF"	//default color
		var cSpacerImage = "spacer.gif"
		var cNavArrow = "lnav_arrow_off.gif"
		
		menuItem = i+1
		
		
		//width of left side buffer
		var spacerWidth = 9 * currentLevel
		
		
		//thisPageId used to determine if we are on page that is a child (or grand child etc), of this nav element
		thisPageId = ""
		for	(k=0;k <= cLevel; k++){
			if (k <= arrPageId.length){
				thisPageId = thisPageId + arrPageId[k] + "_"
			}	
		}	
		if (thisPageId != ""){
			thisPageId = thisPageId.slice(0, thisPageId.length-1)
		}	
		if (thisPageId == cId){
			cClass = "lnav_link_on"
			
			//spacerHeight = 6;
			cNavArrow = "lnav_arrow_on.gif"
			//header image for third level
			//if (cLevel == "1"){
				//document.images["subsection_img"].src = "/images/" + cHeaderImage 
				//document.images["subsection_img"].alt = cTitle
				
			//}
			
			strBreadCrumb += "<img src=\"/images/crumbArrow.gif\" width=\"5\" height=\"20\"><a href='" + cFile + "' class='crumb-link' style=\"padding-left:15px;padding-right:15px;\">" + cTitle + "</a>"

		}
		
		
		//see if this nav element has children
		bHasChildren = oChildNode.item(i).hasChildNodes()
		
		if(bHasChildren && thisPageId == cId){
		    spacerHeight = 6;
		} else {
		    spacerHeight = 12;
		}
		
		//write this level if it is level 1
		if (currentLevel == 1){
			document.write("<div name=\"div" + i + "\" >")
			document.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"190\">")
			document.write("    <tr id=\"rowL" + cId + "\" style=''>");
			document.write("        <td valign=\"top\">");
			document.write("            <table width=\"190\" cellpadding=0 cellspacing=0 border=\"0\">");
			document.write("                <tr>");
			document.write("		            <td valign=top>")
			document.write("			            <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"190\">");
			document.write("                            <tr class=\"nav\">");
			document.write("                                <td valign=\"top\" width=\"16\"><img src=\"/images/spacer.gif\" width=\"16\" height=\"1\"></td>");
			document.write("				                <td valign=\"top\" width=\"99%\" style=\"padding:10px 0px 0px 0px;\"><a id=\"mainLinkL" + cId + "\" class=" + cClass + " href=\"" + cFile + "\" onclick=\"return true;\">"+ cTitle +"</td>");
			document.write("                            </tr>");
			document.write("                        </table>");
			document.write("		            </td>");
			document.write("                </tr>");
			document.write("            </table>");
			document.write("        </td>");
			document.write("    </tr>");
			document.write("    <tr id=\"rowBottomL" + cId + "\" style=''>");
			document.write("        <td valign=\"top\"><img src=/images/spacer.gif width=1 height=" + spacerHeight + "></td>");
			document.write("    </tr>");
			document.write("</table>")
			
			
		} 
		
		//set up layers for flyouts
			thisL = "L" + cId
			aIndex	= 3 + currentLevel 
			bIndex = currentLevel -1
			if(bIndex > 1){
				//bIndex = 1
			}
			strLinksList = strLinksList + thisL + ","
			if (currentLevel > 1){
				xCoord = 10
				yCoord = 5
			} else {
				xCoord = 105
				yCoord = -5
			} 
			
			if (currentLevel > 1){
				thisYCoord = yCoord + (yCoordPlus * i)
			} else {
				thisYCoord = yCoord
			}
			
		
			eval("var l = new Layer(\"" + thisL + "\", 0, " + aIndex + ", " + bIndex + ", " + xCoord + ", " + thisYCoord + ");")
			
			
		//write out child layers
			if (bHasChildren)	{
				
				strLayersList += thisL + ","
				//get children of this node
				var lChildNode = oChildNode.item(i).getChildNodes()
	
				//number of children in this sub nav
				var lnodeLength = lChildNode.getLength()

				//loop through navigation elements
				//var z=0;
				for (j=0;j<lnodeLength;j++){
				//alert("hi there");
					var lTitle = lChildNode.item(j).getAttributes().getNamedItem("title").getNodeValue();
					var lId = lChildNode.item(j).getAttributes().getNamedItem("id").getNodeValue();
					var lLevel = lChildNode.item(j).getAttributes().getNamedItem("level").getNodeValue();
					var lFile = lChildNode.item(j).getAttributes().getNamedItem("file").getNodeValue();
					var lTarget = lChildNode.item(j).getAttributes().getNamedItem("target").getNodeValue();
					var lClass= "lnav_sub_link"
					lNavArrow = "lnav_divot_off"
					
					if(pageId==lId){
					    //alert("dopey");
					    lClass= "lnav_sub_link_on"
					    lNavArrow = "lnav_divot_on"
					} else {
					    lClass= "lnav_sub_link"
					    lNavArrow = "lnav_divot_off"
					}
					
					lThisL = "L" + lId
					
					thisNodeChildNode = lChildNode.item(j).getChildNodes()
					//these are the third levels 
					
					if(lLevel < 3) {
					    if(pageId == cId) {
						    document.write("<div name=\"div" + j + "\">")
						    document.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"190\">")
						    document.write("    <tr id=\"rowL" + lId + "\" style=''>");
						    document.write("        <td valign=\"top\">");
						    document.write("            <table cellpadding=0 cellspacing=0 width=\"190\" border=\"0\"><tr><td>");
						    document.write("	            <tr>");
						    document.write("		            <td valign=top>");
						    document.write("			            <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"190\">");
						    document.write("                            <tr>");
						    document.write("                                <td valign=top width=\"36\"><img src=\"/images/spacer.gif\" width=\"36\" height=\"1\"></td>");
						    document.write("				                <td valign=\"top\" width=\"9\" style=\"padding:4px 5px 0px 0px;\"><img src=\"/images/" + lNavArrow + ".gif\" width=\"5\" height=\"4\" name=\"imgL" + lId + "\"></td>");
						    document.write("				                <td valign=\"top\" width=\"100%\" style=\"padding:0px 6px 6px 0px;\"><a id=\"mainLinkL" + lId + "\" class=" + lClass + " href=\"" + lFile + "\" onclick=\"return true;\">"+ lTitle +"</td>");
						    document.write("                                <td valign=top width=\"18\"><img src=\"/images/spacer.gif\" width=\"18\" height=\"1\"></td>");
						    document.write("		                    </tr>");
						    document.write("                        </table>");
						    document.write("	            </tr>");
						    document.write("            </table>");
						    document.write("        </td>");
						    document.write("    </tr>");
						    document.write("    <tr id=\"rowBottomL" + lId + "\" style=''>");
						    document.write("        <td valign=\"top\"><img src=/images/spacer.gif width=1 height=6></td>");
						    document.write("    </tr>");
						    document.write("</table>");
					    } else {
					        //only write out the subs for the selected parent section
					        //the parent section id is cId
					        //lId is the third level page Id, so if the cId exists in the Lid, and the cId exists in the PageId, write it
					        if(lId.indexOf(cId)!= -1 && pageId.indexOf(cId) != -1){
					            document.write("<div name=\"div" + j + "\">")
						        document.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"190\">")
						        document.write("    <tr id=\"rowL" + lId + "\" style=''>");
						        document.write("        <td valign=\"top\">");
						        document.write("            <table cellpadding=0 cellspacing=0 width=\"190\" border=\"0\"><tr><td>");
						        document.write("	            <tr>");
						        document.write("		            <td valign=top>");
						        document.write("			            <table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"190\">");
						        document.write("                            <tr>");
						        document.write("                                <td valign=top width=\"36\"><img src=\"/images/spacer.gif\" width=\"36\" height=\"1\"></td>");
						        document.write("				                <td valign=\"top\" width=\"9\" style=\"padding:4px 5px 0px 0px;\"><img src=\"/images/" + lNavArrow + ".gif\" width=\"5\" height=\"4\" name=\"imgL" + lId + "\"></td>");
						        document.write("				                <td valign=\"top\" width=\"100%\" style=\"padding:0px 6px 6px 0px;\"><a id=\"mainLinkL" + lId + "\" class=" + lClass + " href=\"" + lFile + "\" onclick=\"return true;\">"+ lTitle +"</td>");
						        document.write("                                <td valign=top width=\"18\"><img src=\"/images/spacer.gif\" width=\"18\" height=\"1\"></td>");
						        document.write("		                    </tr>");
						        document.write("                        </table>");
						        document.write("	            </tr>");
						        document.write("            </table>");
						        document.write("        </td>");
						        document.write("    </tr>");
						        document.write("    <tr id=\"rowBottomL" + lId + "\" style=''>");
						        document.write("        <td valign=\"top\"><img src=/images/spacer.gif width=1 height=6></td>");
						        document.write("    </tr>");
						        document.write("</table>");
						    }
					    }
					}
					
					    document.write("</div>")
					    
					
					
				}
				if(pageId == cId || lId.indexOf(cId)!= -1 && pageId.indexOf(cId) != -1){
				    document.write("<br>");
				}
			}
			
			strLayerCode += "l.fl();\n"
			l.fl();
			
			
		
		//yCoord = yCoord + yCoordPlus
		
		
		if (thisPageId == cId){
			newLevel = currentLevel + 1
			
			if (bHasChildren){
				navShowChildren(oChildNode.item(i), newLevel)
			}
		}	
			
			
			
		if(currentLevel ==1){	//close out second level table
			document.write("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" width=\"100%\">")
			document.write("	<tr>")
			document.write("		<td colspan=\"2\" width=\"100%\"><img src=\"/images/spacer.gif\" height=\"0\" width=\"1\"></td>")
			document.write("	</tr>")
			document.write("</table>")
			document.write("</div>")
		}	
		
	}
}

function writeFlyoutNavigation(){
	strLayersList = ""
	
	
	//set to true if we are showing first level in left hand navigation
	//set to false to only show second level and beyond (this would be if first level
	//was horizontal on top for example
	var showFirstLevel = false
	
	//instantiate the W3C DOM Parser
	var parser = new DOMImplementation();

	//load the XML into the parser and get the DOMDocument
	navXML = arrNavXML[arrPageId[0]]
	var objDocument = parser.loadXML(navXML);

	//get the root node (in this case, it is ROOTNODE)
	var docRoot = objDocument.getDocumentElement();
	
	//get first level navigations
	var firstLevel = docRoot.getChildNodes()
	
	//number of first level navigation elements
	maxValue = firstLevel.getLength()
	
	//loop through first level and get attributes
	for (i=0;i<maxValue;i++){
		var bHasChildren = false
		//get attributes
		var cNode = firstLevel.item(i)
		var cTitle = firstLevel.item(i).getAttributes().getNamedItem("title").getNodeValue();
		var cId = firstLevel.item(i).getAttributes().getNamedItem("id").getNodeValue();
		var cLevel = firstLevel.item(i).getAttributes().getNamedItem("level").getNodeValue();
		var cHeaderImage = firstLevel.item(i).getAttributes().getNamedItem("hdrImage").getNodeValue();
		var cFile = firstLevel.item(i).getAttributes().getNamedItem("file").getNodeValue();
		var cTarget = firstLevel.item(i).getAttributes().getNamedItem("target").getNodeValue();

		var cClass = "lnav_link"
		var cTdBgColor = "#FFFFF"	//default color
		var cSpacerImage = "spacer.gif"
		
		//check to see if this first level should be expanded
		if (arrPageId[0] == cId){
			bHasChildren = firstLevel.item(i).hasChildNodes()
			cClass = "lnav_link_on"
			strBreadCrumb += "<a href='" + cFile + "' class='crumb-link' style=\"padding-right:15px;\">" + cTitle + "</a>"
			//alert("hi");
		}
		
		//set up banner image
		//document.images["section_img"].src = "/images/" + cHeaderImage
		//document.images["section_img"].alt = cTitle
		
		
		//write this level
		if (showFirstLevel){
			document.write("<table width=200 cellpadding=0 cellspacing=0><tr>")
			document.write("<tr><td width=1 valign=top><img src=images/spacer.gif width=1 height=1></td>")
			document.write("<td width=100% valign=top><a class=" + cClass + " href=\"" + cFile + "\" onclick=\"return true;\" onmouseout=\"hideMenu(\'\');\" onmouseover=\"showMenu(\'L' + cId + '\', \'I' + cId + '\');\">"+ cTitle +"</td>")
			document.write("</tr></table>")
		}	
		
		if (bHasChildren ) {	//get sub navigations
			navShowChildren(cNode, 1)
		}
	}
layersList = strLayersList.split(",")
layerCount = layersList.length - 1

linksList = strLinksList.split(",")
linksCount = linksList.length -1
	
//alert(strBreadCrumb)
document.getElementById("breadcrumb").innerHTML = strBreadCrumb

} 


