
$(function() {
	// Helper function to get clean filename
	var stripLocation = function(href) {
			if (typeof href !== "string") {
				href = window.location.href;		
			}
			var domain = window.location.protocol + '//' + window.location.hostname;
			if ((window.location.port) && (window.location.port.length > 0)) {
				domain += ":" + window.location.port;
			}
			if (href.indexOf(domain) === 0) {
				return href.substr(domain.length);
			} else {
				return href;
			}
	};
	
	var setHighlight = function()
	{
		var currentUrl = stripLocation().toLowerCase();
		$("ul#nav a").each(function() {
			var href = stripLocation(this.href).toLowerCase();
			if (href === currentUrl) {
				$(this).addClass("selected");			
				return;	// There can only be one current page!
			}
		});
	};
	
	setHighlight();	// Sync menu to current page
});