function preSelectNav() {
	var navigationId = 'top_nav';
	var highlightClass = 'page_selected';
	var domainName = 'http://inps.ikosdev.co.uk/';
	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]);
			if (elATag != null){
				var atElATagHref = elATag.getAttribute('href');
				var elATagHref = "";
				if (atElATagHref != null) elATagHref = atElATagHref.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 > 0){
			 			for (var j=0; j < arATagHref.length -1; 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 && partialUrl.length > 2) elementIsSelected = true;
			
			/* As the element is selected, the color can now be set */
			if (elementIsSelected) {
						elLi[i].className = highlightClass;
			}
		}
		}

}

function getFirstChild(f) { 

	f = f.firstChild;
	while (f && !f.tagName) {
		f = f.nextSibling;
	} 
	return f;
} 

