function idArray(checkId) {
	
	//build array of all IDs in the menu
	var id = new Array("index","about-us","about-us-sub", "environment", "bluechip", "services", "services-sub", "custom-built", "workforce", "supply-chain", "health-safety", "IT-equipment", "confidentiality", "quality", "products", "contact-us");	
	
	//convert the array to a searchable string and search for the passed ID name
	var searchforid = id.toString().search(checkId);
	
	if (searchforid != -1) {
		//if the passed ID is found in the ID string return true
		return true;
	} else {
		
		//if the passed ID is NOT found in the ID string return false
		return false;	
	}
}

function subMenu(idName) {
	
	//find the ID name of the submenu's parent
	var subId = document.getElementById(idName).parentNode.id;
	
	//check to see if there is a parent, if there is, store it in a variable
	if (document.getElementById(idName).parentNode.id) {
		var rootMenuItem = document.getElementById(subId).parentNode.id;
	}
	
	//style the parent menu item
	if (rootMenuItem) {
		document.getElementById(rootMenuItem).firstChild.style.background = "#336633";
		document.getElementById(rootMenuItem).firstChild.style.color = "#fff";	
	}
}

function menuDetection() {
	
	//get url
	var str = document.location.toString();
	
	//split and take last part of the url
	var splitstr = str.split("/");
	var count = splitstr.length-1;
	var pageName = splitstr[count];
	
	//if there is a file extension remove it
	var splitstr = pageName.split(".");
	
	
	//count the length of splitstr and store in a variable
	var splitstrlength = splitstr.length;
	
	
	//if splitstrlength is greater than 1 the visitor is not on the landing page
	if (splitstrlength > 1) {
		
		//use the first value in the  splitstr array to create the ID name
		var idName = splitstr[0];
		
		//if idName exists in the idArray then style the menu item
		if (idArray(idName)) {
			
			//render the select menu title
			document.getElementById(idName).firstChild.style.background = "#336633";
			document.getElementById(idName).firstChild.style.color = "#fff";
			
			//check to see if the menu item has a submenu - if it has both the main menu item and child will be highlighted
			subMenu(idName);
		}
	} else {
		
		//style the home link as the visitor is on the landing page
		document.getElementById('index').firstChild.style.background = "#336633";
		document.getElementById('index').firstChild.style.color = "#fff";
	}
}