//	autonav.js -- Auto-highlighting script
//	Version 1.6.2
//	Requires yahoo-dom-event.js
//
//	CHANGELOG
//	2008-12-09	Fixed templateParentPage index page bug
//	2008-11-04	Removed short variables pointing to YAHOO namespaces 
//				(causing variable naming conflict with Prototype)
//  2008-10-30  Fixed violently broken regex in extractPageName() -- Damien
//  2008-10-29	Added IE6 / IE7 bug fix for templateParentPage
//  2008-10-23	Added style block that hides navigation until classes are added.
//	2008-09-16	Re-introduced navigationList variable, fixed invalid href bug
//				Replaced the replace with a regular expression


var templateParentPage;
var navigationList = 'sidebar-inner';
	
document.write('<style type="text/css"> #' + navigationList + ' { display: none; } </style> ');

YAHOO.util.Event.onAvailable(navigationList, function() {
		menuItems = YAHOO.util.Dom.getElementsBy(function() { return true; },'a',navigationList);
		if (!templateParentPage) {
			setActiveMenu(menuItems, extractPageName(document.URL));
		}
		else {
			var link = document.createElement('a');
			link.setAttribute('href', templateParentPage);
				
			if(link.href) {
				var newLink = '';
				if(link.href.indexOf(document.domain) == -1) {
					if(link.href.indexOf('https://') != -1)
						newLink = 'https://' + document.domain + link.href;
					else
						newLink = 'http://' + document.domain + link.href;
				}
				else
					newLink = link.href;
				setActiveMenu(menuItems, extractPageName(newLink));
			}

		}
		sublists = YAHOO.util.Dom.getElementsBy(function() { return true; },'ul',navigationList);
		setActiveList(sublists);
		
		YAHOO.util.Dom.get(navigationList).style.display = 'block';
		
		buildBreadcrumbs();
});

	function extractPageName(uStr) {
		var currentPage = uStr;
		if (currentPage.indexOf('#') > -1) {
			currentPage = currentPage.substr(0,currentPage.indexOf('#'));
		}
		if (currentPage.indexOf('?') > -1) {
			currentPage = currentPage.substr(0,currentPage.indexOf('?'));
		}
		currentPage = currentPage.replace(/(default|index)\.(htm|html|asp|aspx|php)/g, '');
		
		return currentPage;
	}
	

	function setActiveList(arr) {
		var topNode = YAHOO.util.Dom.get(navigationList);
		for(var i=0; i < arr.length; i++) {
			if (arr[i].id != navigationList) {
				if(!YAHOO.util.Dom.hasClass(arr[i],'active')) {
					YAHOO.util.Dom.addClass(arr[i],'inactive');	
				}
				YAHOO.util.Dom.addClass(YAHOO.util.Dom.getAncestorByTagName(arr[i],'LI'),'more');
			}
		}
	}
	// search through all the links in array, if one points to
	// the same file, apply the class .active to it and to all its parents
	// until it reaches the top node

	function setActiveMenu(arr, crtPage) {
		var topNode = YAHOO.util.Dom.get(navigationList);
		for(var i=0; i < arr.length; i++) {
			  if((arr[i].href) && (extractPageName(arr[i].href) == crtPage)) {
				YAHOO.util.Dom.addClass(arr[i],'active');
				currNode = arr[i];
				while(currNode != topNode) {
					YAHOO.util.Dom.addClass(currNode,'active');
					if (currNode.tagName=='LI') {
						YAHOO.util.Dom.addClass(YAHOO.util.Dom.getFirstChild(currNode),'active');
					}
					currNode = currNode.parentNode;
				}
			  }
	  }
	}

	