//////////////////////////////////////////////////////////////////////////////////////
// activeState.js Copyright Mark Da Silva, Thinkweb Consulting, 2007
// www.thinkweb.com.au
// Licensed to Britt Ambrose Design for High Performance Golf
// 
// This script will find the menu list item object with an id that matches
// the file name of the current URL (with the file extension stripped.
// For example, if the page is named welcome.html this script will search for
// a list item <li id="welcome">
//
// If the list item is a top level navigation item, the script will set its
// class to be "mainnavactive".
//
// If the list item is a second level (sub-nav) item, the script will set its class
// to be "subnavactive" and it will set the parent (top level) navigation list item's
// class to be "mainnavactive".
//
// Version 3. 2007-07-02
//////////////////////////////////////////////////////////////////////////////////////
/* name of main nav (top level) ul id */
var mainnav = 'mainnav';

/* name of subnav ul class */
var subnav = 'subnav';

window.onload = function() {
   var thisPage = location.pathname.substring(location.pathname.lastIndexOf('/')+1, location.pathname.length);

   if (thisPage.length) {
	   var LiId = thisPage.substring(0, thisPage.lastIndexOf('.'));
   } else {
       var LiId = 'index';
   }
	var activeLi = document.getElementById(LiId);
	var liParent = activeLi.parentNode;
	// if this is a top level nav item we need to set it's class name to mainmenuactive.
	if(liParent.id.toUpperCase() == mainnav.toUpperCase() ) {
		activeLi.className = 'mainnavactive';
		return;
	}
	// if this is a subnav item we need to set it's class name to subnavactive
	// and the parent's class name to mainnavactive.
	grandParent = liParent.parentNode;
	greatGrandParent = grandParent.parentNode;
	if(greatGrandParent.id.toUpperCase() == mainnav.toUpperCase() ) {
		activeLi.className = 'subnavactive';
		grandParent.className = 'mainnavactive';
	}
}
