function preSelectNav() {
	var navigationId = 'secondary_navigation';
	var highlightClass = 'selected_nav';
	var domainName = 'http://www.serendipitydirect.com';
	var selectedColour = '#663300;';

	/* Locate the navigation unordered list	 */
	var elNav = document.getElementById(navigationId);
	var elLi = elNav.getElementsByTagName('li');

	/* Identify the current page */
	var curWinLoc = window.location.toString();
	
	/* Step through each li item in the nav and check if the href for this
		is in the current path */

		for (var i = 0; i < elLi.length; i++) {
			
			/* Assume element is not in the current path */
			var elementIsSelected = false;
			
			/* Get the A tag href for the next LI item */
			var elATag = getFirstChild(elLi[i]);
			var elATagHref = elATag.getAttribute('href').toString();
			
			/* If the href contains the domain name of the site, remove it - this is 
			for consistency so we know we are always dealing with relative links */
			if (elATagHref.indexOf(domainName) == 0) elATagHref = elATagHref.substring(domainName.length +1, elATagHref.length);
			
			/* Split the A tag into its component parts */
			var arATagHref = elATagHref.split('/');
			
			/* Assuming this nav is sitecatalogue and urls are seo friendly, remove the last 3 elements of the url */ 
			var partialUrl = '';
			if (arATagHref.length > 4){
				for (var j=0; j < arATagHref.length -3; j++){
					partialUrl = partialUrl + arATagHref[j] + '/';
				}
			}
			
			/* if the partialUrl is in the current url, this nav element is selected */
			if (partialUrl.length > 0 && curWinLoc.indexOf(partialUrl) > -1) elementIsSelected = true;
			
			/* As the element is selected, the color can now be set */
			if (elementIsSelected) {
			
				elATag.className = highlightClass;
			}
		}

}

function getFirstChild(f) { 

	f = f.firstChild;
	while (f && !f.tagName) {
		f = f.nextSibling;
	} 
	return f;
} 

