
onload = SetLinks;

// Uses the url to find the link to the current page and select it
function SetLinks()
{
	var links = document.getElementsByTagName( "a" );
	
	for( var i = 0; i < links.length; i++ )
	{
		var link = links[ i ];
		
		if( link.href == window.location || link.href.replace( "default.aspx", "" ) == window.location )
		{
			link.className += " Selected";
			ToggleDepartment( link );
		}
	}

}
// When clicking a department link, this opens up the child menu of lines
function ToggleDepartment( link )
{
	var item = null;
	var departmentLink = null;
	
	// Find the lines div and department link to be highlighted
	if( link.parentNode.className == "Department" )
	{
		// The link clicked was department, so look at child nodes to find lines 
		var list = link.parentNode.childNodes;
		departmentLink = link;
		
		for( var i = 0; i < list.length; i++ )
		{
			if( list[ i ].className == "SubDepartment" )
			{
				item = list[ i ];
				break;
			}
		}
	}
	else if( link.parentNode.parentNode.parentNode.className == "SubDepartment" )
	{
		// The link clicked was sub-department, so look at parent nodes to find department
		item = link.parentNode.parentNode.parentNode;		
		var department = item.parentNode;
		
		for( var i = 0; i < department.childNodes.length; i++ )
		{
			if( department.childNodes[ i ].nodeName == "A" )
			{
				departmentLink = department.childNodes[  i ];
				break;
			}
		}
	}
	
	if( item )
	{
		// Toggle display property
		if( item.style.display != "block" )
		{
			item.style.display = "block";
			departmentLink.className = "Selected";
		}
		else
		{
			item.style.display = "none";
			departmentLink.className = "";
		}
		return true;
	}
	
	return false;
}


