
function highlightMenu(menuDiv) {
	// highlight a link if it points directly to the current page
	var links = menuDiv.getElementsByTagName("a");
	var highlighted = false;
	for (var i=0; i<links.length; i++) {
		var l = links[i];
		if (l.className != 'navLink') {
			continue;
		}
		if (l.href == document.location.href) {
			l.className = l.className + ' selected';
			highlighted = true;
			break;
		}
	}
	
	// if there is no direct match, match on subfolder
	if (!highlighted) {
		// capture domain part of URL and optional first folder, e.g:
		// from http://foo.com/bar/baz/quux.html?xyz#lala capture "http://foo.com/bar/"
		// from http://foo.com/?quux#lala/bootleg capture "http://foo.com/"
		var urlParts = document.location.href.match(new RegExp("\\w+://[^/]+/([\\w-_]+/)?"));
		var urlPrefix = urlParts ? urlParts[0] : null;
		
		if (urlParts) {
			// highlight the first link starting with the above url prefix
			for (var i=0; i<links.length; i++) {
				var l = links[i];
				if (l.className != 'navLink') {
					continue;
				}
				if (l.href.indexOf(urlPrefix) == 0) {
					l.className = l.className + ' selected';
					break;
				}
			}
		}
	}
}