//trims a string like 'http://www.example.com/page1.html' to 'page1.html'
function filterURL(urlStr) {
	return urlStr.substring(urlStr.lastIndexOf('/') + 1);
}

window.onload = function() {
	//gets current page
	var thisPage = filterURL(window.location.pathname);

	//get elements we're interested in
	var myNav = document.getElementById('menu');
	var navItems = myNav.getElementsByTagName('li');
	var navLinks = myNav.getElementsByTagName('a');

	//cycle through the links until we find a match,
	//apply our selected class to the matching parent LI
	for (var i = 0; i < navLinks.length; i++) {
		if (filterURL(navLinks[i].href) == thisPage) {
				navLinks[i].className += ' selected';
		}
	}
}




