/* Board of Trustees Election Navigatoin */

Event.observe( window, 'load', navigationState, false );
	
function navigationState()
{
	var url 	= window.location.href; // get the current url
	url 		= url.split( '/' ); // split it up
	var page 	= "";
	
	for( var i = 3; i < url.length; i++ )
	{
		page += "/" + url[i];
	}
	
	page = page.split('&');
	page = page[0];
	
	
	var parentDirectory = page.split( '.' ); // knock off the file extension
	
	var pDirectory = parentDirectory[0].split( '/' ); // split on the forward slash
	var parDir = ""; // set up an empty string
	
	for( var i = 0; i < pDirectory.length-1; i++ )
	{
		parDir += pDirectory[i] + "/"; // concat the parts back into one string
	}
	
	var navLinks = $$( 'div#navigation ul li a' ); // get all the navigation links
	
	var subNavigationUL 	= $$( 'li.subNav' ); // get subNavigation list
	
	subNavigationUL.each( function( subNav )
							{
								subNav.hide();
							}
						); // hide each subNavigation list item
	
	// for each navigation link that we found check to see if we are on that page
	navLinks.each( function( navLink )
					{
						var url = navLink.getAttribute( 'href' );
						
						if( BrowserDetect.browser == "Explorer" )
						{
							url = url.split( '/' ); // split it up
							var href = "";
							
							for( var i = 3; i < url.length; i++ )
							{
								href += "/" + url[i];
							}
							href = href.split( '#' );
							href = href[0];
						} // end ie dectection clause
						else
						{
							var href = url;
							href = href.split( '#' );
							href = href[0];
						} // End broswer dectection else clause
						
						// blogs specific code
						

						var linkText = navLink.innerHTML;						
						
						// if we are, set the class name of that link to current
						if( 	(href == page) 
							 || (href + "index.shtml" == page) 
							 || (href + "default.aspx" == page) 
							 || (href + "blogs.aspx" == page) )
						{	
							var parentLI = navLink.up(); // get the parent list item of the link
							parentLI.update( linkText ); // update it to take out the link and add in text only
							parentLI.addClassName( 'current' ); // give it a class name of current to style it differently
							
							var nextLI = parentLI.next(); // get the next list item down from our current list item
							
							if( (nextLI) && ( nextLI.hasClassName('subNav') ) ) // check to see if it has subnavigation
							{
								nextLI.show();	// if so, then show that subnavigation
							}
							
							var grandParent 		= parentLI.up();
							var greatGrandParent 	= grandParent.up();
							
							if( greatGrandParent.hasClassName( 'subNav' ) )
							{
								greatGrandParent.show(); 
							}
							
						} // End href == page test
					}
				 );
} // end navigationState function