// JavaScript Document

	/////////////////////////////////////////////////////////////////////////////
	// Class : can_shm_top_nav_static_inc
	// Comments : 
	/////////////////////////////////////////////////////////////////////////////

	var HttpRelativeFragmentsRoot = g_HttpRelativeWebRoot + "fragments/"
		
	function NavImage(source,width,height)
	{
		this.width = width;
		this.height = height;
		this.source = source;
	}
			
	function getHeight()
	{
		return this.height;
	}

	function getWidth()
	{
		return this.width;
	}

	function getSource()
	{
		return this.source;
	}
	
		
	NavImage.prototype.getHeight = getHeight;
	NavImage.prototype.getWidth = getWidth;
	NavImage.prototype.getSource = getSource;
	
	function can_shm_top_nav_static_inc ()		
	{
		this.m_HomeLevel = 2;
		this.m_StartLevel = 3;
		this.m_NumLevels = 10;
		this.m_EndLevel = 0;
		this.m_DefaultNumColumns = 3;
		this.m_ShowHome  = true;
		this.m_ShowSectionHeading = false;
		this.childMenus = "";
		this.navIndex = 0;
		this.ImageMap = new Array();
		
		if(typeof(g_navNode_Path) != 'undefined'){
			this.m_NavPath  = g_navNode_Path;
		}
		else
		{
			/*NavPath doesn't exist on static site, set to empty array*/
			this.m_NavPath  = new Array();
		}
		

		this.m_EndLevel = this.m_StartLevel + this.m_NumLevels - 1 ;
		this.m_HomeLevel = this.m_StartLevel - 1;
	}

	function Display (node)
	{
		document.write("<div id=\"navcontainer\">");
		document.write("<ul id=\"navbox\">");
		//document.write("<ul>");
		this.DisplayNode(node);
		document.write("</ul>");
		//document.write("<div class=\"spacer\"></div>");
		//document.write("<div id=\"nav-border\"></div>");
		document.write("</div>");
		document.write(this.childMenus);

		document.write("<script type=\"text/javascript\">");
		document.write("window.onload=function(){");

			for(var i=1; i<=this.navIndex; i++){
				var position;
				position = "right-bottom";
				document.write("var navitem" + i + " = new navElement(\"menuItem" + i + "\", \"" + position + "\", 250);");
			}	

		document.write("}");
		document.write("</script>");
	}

	function DisplayNode (node)
	{
		var bSelected = false;
		var activeTopElement = false;
		var nodeColor = "";
		var nodeClass = "";
		var nodeId = "";
		var nodeLevel = node.m_level;
		var nodeHref = node.m_href;
		var nodeLabel = node.m_label;
		var xchildren = node.m_subNodes;
		var numChildNodes = node.m_subNodes.length;
		
		var columnNum = this.m_DefaultNumColumns;		
		excSubSections = false;
		excSection = false;
		
		
		/*Perform a count of sub nodes to include. We have to check for excludes*/
		if (node.m_subNodes.length > 0 && (nodeLevel == this.m_StartLevel))
		{
			if(customSectionPropertyExists(node.cp_ExcludeTopNavSubSections) && (getCustomSectionProperty(node.cp_ExcludeTopNavSubSections).toLowerCase() == "true"))
			{
				numChildNodes = 0;
			}
			else
			{
				childCount = 0;
				for(i = 0; i < node.m_subNodes.length; i++)
				{
					curNode = curNode = xchildren[i];;

					if(!(customSectionPropertyExists(curNode.cp_ExcludeInTopNav) && (getCustomSectionProperty(curNode.cp_ExcludeInTopNav).toLowerCase() == "true")))
					{
						childCount++;
					}
				}

				numChildNodes = childCount;
			}
		}
		
		
		if(customSectionPropertyExists(node.cp_AltLabel))
		{		
			var altLabel = getCustomSectionProperty(node.cp_AltLabel);
			if(altLabel.length > 0)
			{
				nodeLabel = altLabel;
			}
		}
		if(customSectionPropertyExists(node.cp_ExcludeTopNavSubSections))
		{		
			getCustomSectionProperty(node.cp_ExcludeTopNavSubSections).toLowerCase() == "true" ? excSubSections = true : excSubSections = false;
		}
		if(customSectionPropertyExists(node.cp_ExcludeInTopNav))
		{		
			getCustomSectionProperty(node.cp_ExcludeInTopNav).toLowerCase() == "true" ? excSection = true : excSection = false;
		}
		if(customSectionPropertyExists(node.cp_TopNavPanelColumns))
		{		
			var colNum = parseInt(getCustomSectionProperty(node.cp_TopNavPanelColumns));
			if(!isNaN(colNum))
			{
				columnNum = colNum;
			}
		}
		if(customSectionPropertyExists(node.cp_LinkToExtURL))
		{		
			var extURL = getCustomSectionProperty(node.cp_LinkToExtURL);
			if(extURL.length > 0)
			{
				nodeHref = extURL;
			}
		}
		
	
		if(!excSection)
		{
			//if (nodeLevel > 6)
			//	nodeLevel = 6;

			/*The code below is never executed on a static site*/
			if (this.m_NavPath.length > 0 && node.m_level < this.m_NavPath.length)
			{
				if (this.m_NavPath[node.m_level] == (node.m_id))
				{
					//top nav classes
					if (node.m_level <= this.m_StartLevel)
						{
						//if Home node
						if (node.m_level == this.m_HomeLevel)
						{
							//only the home node is selected
							if((this.m_NavPath.length - this.m_HomeLevel) == 1)
							{
								bSelected = true;
								nodeClass += "activelist";
								nodeId += "activelist";
								activeTopElement = true;
							}
							else
							{
								bSelected = true;
							}
						}
						//start level node as active when active or lower child node is selected
						else if (node.m_level == this.m_StartLevel)
						{
							bSelected = true;
							//nodeClass += "currentSection";
							nodeClass += "off activelist";
							activeTopElement = true;
						}
						else
						{
							bSelected = true;
						}
					}
					//panel nav classes
					else if (node.m_level > this.m_StartLevel)
					{
						//last node selected mark as active
						if (node.m_level == (this.m_NavPath.length-1))
						{
							bSelected = true;
							nodeClass += "active";
							nodeId += "activelist";
						}
						//else mark current node as selected so child nodes are included
						else
						{
							bSelected = true;
						}
					}
				}
			}


			/*mark everything under start level as selected so all the nav is built out or mark all if home node is website root*/
			if((this.m_HomeLevel == 0 || nodeLevel >= this.m_StartLevel) && nodeLevel <= this.m_EndLevel)
			{
				bSelected = true;
			}


			//add top level arrows to non-selected nodes
			if(!bSelected && (nodeLevel == this.m_HomeLevel || nodeLevel == this.m_StartLevel))
			{
				nodeClass += "notcurrent";
			}

			//nodeClass += "-" + var.valueOf(nodeLevel);

			if ((nodeLevel > this.m_StartLevel && nodeLevel <= this.m_EndLevel))
			{				
				this.childMenus += "<li class=\""+nodeId+"\">";

				var navLink = "";

				//lowest selected node
				/*
				if (nodeLevel == (this.m_NavPath.length-1) && this.m_NavPath[node.m_level] == (node.m_id))
				{
					navLink += "<a";
				}
				else
				{
					navLink += "<a href=\"" + nodeHref + "\"";
				}
				*/

				navLink += "<a href=\"" + nodeHref + "\"";

				if(nodeClass.length>0){
					navLink += " class=\"" + nodeClass + "\"";
				}
				
				if(customSectionPropertyExists(node.cp_OpenInNewWindow) && (getCustomSectionProperty(node.cp_OpenInNewWindow).toLowerCase() == "true"))
				{
					navLink += " target =\"_blank\" ";
				}
				
				if(customSectionPropertyExists(node.cp_LinkAttributes) && (getCustomSectionProperty(node.cp_LinkAttributes).length > 0))
				{
					navLink += " " + getCustomSectionProperty(node.cp_LinkAttributes) + " ";
				}

				navLink += "><span>" + nodeLabel + "</span></a>";

				this.childMenus += navLink;
			}
			else if ((nodeLevel == this.m_HomeLevel && this.m_ShowHome && bSelected)  || nodeLevel == this.m_StartLevel) 
			{
				if (numChildNodes > 0 && nodeLevel != this.m_HomeLevel && !excSubSections)
				{
					this.navIndex++;
				}

				//document.write("<li class=\""+nodeId+"\">");
				//if (activeTopElement) {
				//	document.write("<li class=\""+nodeId+"\">");
				//	}
				//	else {
				//	document.write("<li class=\"off\" id=\"menuItem" + this.navIndex + "\" rel=\"menuPanel" + this.navIndex + "\">");
				//	}
					
				document.write("<li class=\"" + nodeClass + "\" id=\"menuItem" + this.navIndex + "\" rel=\"menuPanel" + this.navIndex + "\">");

				var navLink = "";
				
				//lowest selected node
				/*
				if (nodeLevel == (this.m_NavPath.length-1) && this.m_NavPath[node.m_level] == (node.m_id))
				{
					navLink += "<a";
				}
				else
				{
					navLink += "<a href=\"" + nodeHref + "\"";
				}
				*/

				if (numChildNodes > 0 && nodeLevel != this.m_HomeLevel && !excSubSections)
				{
					//navLink += "<a class=\"off\" id=\"menuItem" + this.navIndex + "\" rel=\"menuPanel" + this.navIndex + "\" href=\"" + nodeHref + "\"";
					if (activeTopElement) { 
						navLink += "<a class=\"off\" id=\"menuItem" + this.navIndex + "\" rel=\"menuPanel" + this.navIndex + "\" href=\"" + nodeHref + "\"";			   
						}
						else {
						navLink += "<a href=\"" + nodeHref + "\"";
						}
				}
				else
				{
					navLink += "<a href=\"" + nodeHref + "\"";
				}
				
				if(customSectionPropertyExists(node.cp_OpenInNewWindow) && (getCustomSectionProperty(node.cp_OpenInNewWindow).toLowerCase() == "true"))
				{
					navLink += " target =\"_blank\" ";
				}
				
				if(customSectionPropertyExists(node.cp_LinkAttributes) && (getCustomSectionProperty(node.cp_LinkAttributes).length > 0))
				{
					navLink += " " + getCustomSectionProperty(node.cp_LinkAttributes) + " ";
				}

				//navLink += " class=\"" + nodeClass + "\"";
				navLink += "><span class=\"navLabel\">";
				
				//navLink += nodeLabel + "</a>";
				navLink += nodeLabel + "</span></a>";
				//Add in text for printing only
				
				
				

				document.write(navLink);

			}

			//If home node close li
			if (nodeLevel == this.m_HomeLevel && (this.m_ShowHome || this.m_ShowSectionHeading) && bSelected)
			{
				document.write("</li>");
			}

			if (bSelected)
			{	// expand sub-levels (if any)
				
				if(numChildNodes > 0 && nodeLevel < this.m_EndLevel && !excSubSections){
					// if this is the top level, build out divs for child nodes
					if ((nodeLevel) == this.m_StartLevel)
					{
						/*If there is not enough top level panel nodes for number of columns, decrease it to number availible*/
						if(columnNum > numChildNodes)
						{
							columnNum = numChildNodes;
						}
						
						var numLinksPerCol = Math.floor(numChildNodes/columnNum);
						var actualNumLinksPerCol = numLinksPerCol;
						var remainingLinks = numChildNodes % columnNum;
						var columnNodeCount = 0;
						var columnWidth = 150;
						var columnWidthDivider = 3;
						var totalNodeCount = 0;

						var totalWidth = columnNum * (columnWidth + ((columnNum - 1) * columnWidthDivider));

						//set width on container and append to front
						this.childMenus += "<div id=\"menuPanel" + this.navIndex + "\" style='width:" + totalWidth + "px; background-color:#FFFFFF; padding:0px;'><div class='shadow-container'><div class='shadow1'><div class='shadow2'><div class='shadow3'><div class='container'><div class='blackLinesTopNavTop'></div><table style='width:" + totalWidth + "px; margin: 0px; padding:0px;' border='0' cellspacing='0' cellpadding='0'>\n";
						this.childMenus += "<tr><td style='height:10px;'></td></tr>";
						this.childMenus += "<tr>";

						//this.childMenus += "<div id=\"menuPanel" + this.navIndex + "\" style='border:solid #999 1px; background-color:#FFFFFF; margin: 0px; padding:0px;'><table style='margin: 0px; padding:0px;' border='0' cellspacing='0' cellpadding='0'><tr>\n";
						/*We need to use the whole array size, even though some nodes may not be included*/
						for (var i = 0; i < node.m_subNodes.length; i++)
						{
							curNode = xchildren[i];

							if(!(customSectionPropertyExists(curNode.cp_ExcludeInTopNav) && (getCustomSectionProperty(curNode.cp_ExcludeInTopNav).toLowerCase() == "true")))
							{
								columnNodeCount++;
								totalNodeCount++;
								if (columnNodeCount==1)
								{
									this.childMenus += "<td valign='top' style='width:"+ columnWidth + "px;'>\n";
									this.childMenus += "<ul class='dropDownList'>\n";
								}

								this.DisplayNode(curNode);

								if(remainingLinks > 0)
								{
									actualNumLinksPerCol = numLinksPerCol + 1;
								}
								else
								{
									actualNumLinksPerCol = numLinksPerCol;
								}

								//if new column or end of child nodes close column
								if (columnNodeCount >= actualNumLinksPerCol || totalNodeCount == numChildNodes)
								{
									this.childMenus += "</ul>\n";
									this.childMenus += "</td>\n";
									//If not the last column add line
									if (totalNodeCount != numChildNodes)
									{
										this.childMenus += "<td valign='top' class='panelDivider' style='width:"+ columnWidthDivider + "px;'></td>\n";
									}
									columnNodeCount = 0;
									remainingLinks--;
								}
							}
						}

						this.childMenus += "<tr><td style='height:10px;'></td></tr>";
						this.childMenus += "</tr>";
						this.childMenus += "</table><div class='blackLinesTopNavBot'></div></div></div></div></div></div>";

						/*Add in iframe to fix select layer issues in ie6 and below*/
						this.childMenus += "<!--[if lte IE 6.5]><iframe id='menuPanel" + this.navIndex + "Layer' class='layerMenuPanel' src='" + HttpRelativeFragmentsRoot + "can_agw_top_nav/iframe_layer.html' scrolling='no' frameborder='0'></iframe><![endif]-->";

						this.childMenus += "</div>\n";

					}
					//if this is the above start level or below, just build out child nodes as normal nested lists
					else
					{
						if (nodeLevel >= this.m_StartLevel){
							this.childMenus += "<ul>";
						}

						for (var i = 0; i < numChildNodes; i++)
						{
							this.DisplayNode(xchildren[i]);	
						}

						if (nodeLevel >= this.m_StartLevel){
							this.childMenus += "</ul>";
						}
					}
				}
			}

			//If greater than home node close after children
			if (nodeLevel == this.m_StartLevel)
			{
				document.write("</li>");
			}
			else if (nodeLevel > this.m_StartLevel && nodeLevel <= this.m_EndLevel)
			{
				this.childMenus += "</li>";
			}
		}
	}


	can_shm_top_nav_static_inc.prototype.Display=Display;
	can_shm_top_nav_static_inc.prototype.DisplayNode=DisplayNode;
	
	top_nav = new can_shm_top_nav_static_inc();
	top_nav.Display(g_navNode_Root);

