var i = 0;
var nodeList  = new Array();

nodeList[i++] = new Node(10356,"Home","/home.html",0,1,0,"_self"); 
nodeList[i++] = new Node(00100,"Company Home","/about/company/company_home.html",1,10,0,"_self");
/*nodeList[i++] = new Node(00200,"Corporate Profile","/about/company/company_overview.html",2,0,0,"_self");*/
nodeList[i++] = new Node(00300,"Management Team","/about/company/company_team.html",2,0,0,"_self");
nodeList[i++] = new Node(00400,"Investors","/about/company/company_investors.html",2,0,0,"_self");
//nodeList[i++] = new Node(00800,"Customers","/about/customers.html",2,0,0,"_self");
nodeList[i++] = new Node(00500,"Industry Associations","/about/company/company_affil.html",2,0,0,"_self");

//Contact and child
nodeList[i++] = new Node(00600,"Contact IP Infusion","/about/contact/contact_home.html",2,1,0,"_self");
//nodeList[i++] = new Node(00601,"Maps & Directions","/about/contact/contact_directions_tosj.html",3,0,0,"_self");

//Careers and children
nodeList[i++] = new Node(00700,"Careers (ACCESS Website)","http://www.access-company.com/about/jobs/careers.html",2,3,0,"_self");
//nodeList[i++] = new Node(00701,"Opportunities in Sales","/about/careers/careers_joblistings_sales.html",3,0,0,"_self");
//nodeList[i++] = new Node(00702,"Opportunities in Engineering","/about/careers/careers_joblistings_engineering.html",3,0,0,"_self");
//nodeList[i++] = new Node(00703,"Opportunities in IT","/about/careers/careers_joblistings_it.html",3,0,0,"_self");


//nodeList[i++] = new Node(00800,"Legal","/about/legal.html",2,0,0,"_self");
nodeList[i++] = new Node(00900,"Site Map","/about/sitemap.html",2,0,0,"_self");

 


// *******************************************************************
// *******************************************************************

// This function creates asset Node objects
function Node(id, name, url, level, children, parent, target) 
{
	this.id = id;
	this.name = name;
	this.url = url;
	this.level = level;
	this.children = children;
	this.parent = parent;
	this.target = target;
}
		
function getNodeById(id) {
	for (x=0; x < nodeList.length; x++)
		if (nodeList[x].id == id) return nodeList[x];
		
	return null;
}

function getNodeByName(name) {
	for (x=0; x < nodeList.length; x++)
		if (nodeList[x].name == name) return nodeList[x];
	
	return null;
}	

function setParentNode(x) { 
	for(p = x - 1; p > 0; p--) 
	{																					
		if ((nodeList[p].children > 0) && (nodeList[p].level < nodeList[x].level)) 		
		{
			nodeList[x].parent = nodeList[p].id;										
			nodeList[p].children--;														
			break;																		
		}

	}
}


function buildSiteNav(id,section) 
{
	for(x = 0; x < nodeList.length; x++)
	{
		if (nodeList[x].level > 1) {
			setParentNode(x);
		}
	}

	var currentNode = getNodeById(id);
	if (currentNode != null)
	{
		while (currentNode.level > 3)
		{
			currentNode = getNodeById(currentNode.parent);
			id = currentNode.id;
		}
		
		var parentId = currentNode.parent;
		var topId = parentId;
		var shtml = "";
		var ihtml = "";

		if (currentNode.level >= 1) 
		{
			
			if (currentNode.level == 1)
			{
				topId = id;
			}
				
			if (currentNode.level >= 3) 
				topId = getNodeById(parentId).parent;

			for (x = 0; x < nodeList.length; x++) 
			{
				if (nodeList[x].level == 1)
				{
					if (topId == id)
						shtml += "<tr><td class=\"leftcell\"><a href=\""  + nodeList[x].url + "\" class=\"leftnav-selected\" target=\"" + nodeList[x].target + "\">About IP Infusion</a></td></tr>";
					else
						shtml += "<tr><td class=\"leftcell\"><a href=\""  + nodeList[x].url + "\" class=\"leftnav\" target=\"" + nodeList[x].target + "\">About IP Infusion</a></td></tr>"; 
				}

				if (nodeList[x].parent == topId) 
				{
					if ((nodeList[x].id == id) || (nodeList[x].id == parentId)) 
					{ 
						var childSelected = false;
						
						for (y = x + 1; y < nodeList.length; y++)
						{
							if (nodeList[y].parent == nodeList[x].id) 

							{
								if (nodeList[y].id == id) 
								{
									ihtml += "<tr><td class=\"leftcell\"><a href=\""  + nodeList[y].url + "\" class=\"leftnavsub-selected\" target=\"" + nodeList[y].target + "\">" + nodeList[y].name + "</a></td></tr>";
									childSelected = true;
								}
								else 
								{
									ihtml += "<tr><td class=\"leftcell\"><a href=\""  + nodeList[y].url + "\" class=\"leftnavsub\" target=\"" + nodeList[y].target + "\">" + nodeList[y].name + "</a></td></tr>";
								}
							}
						}
						
						if (childSelected)
							shtml += "<tr><td class=\"leftcell\"><a href=\""  + nodeList[x].url + "\" class=\"leftnav\" target=\"" + nodeList[x].target + "\">" + nodeList[x].name + "</a></td></tr>";
						else
							shtml += "<tr><td class=\"leftcell\"><a href=\""  + nodeList[x].url + "\" class=\"leftnav-selected\" target=\"" + nodeList[x].target + "\">" + nodeList[x].name + "</a></td></tr>"; 

						if (ihtml != "")
							shtml +=  ihtml;
					}
					else 
					{
						shtml += "<tr><td class=\"leftcell\"><a href=\""  + nodeList[x].url + "\" class=\"leftnav\" target=\"" + nodeList[x].target + "\">" + nodeList[x].name + "</a></td></tr>";
					}
				}
			}
		}
		
		return shtml; 
	}
	
	return "";
}