// adds activeClassName to nav <li> if the <li>'s <a> matches the current page url
function activateNav(navId, activeClassName) {
	var nav          = $(navId); if (!nav) return;	
	var current_page = parsePath(document.URL);
	var navlis       = nav.getElementsByTagName('li');
	
	// add class of active to li if li has an <a> tag with
	// an href that matches the current document's url
	forEach(navlis, function(li) {
		var href = parsePath(li.getElementsByTagName('a')[0].href);
		if (href == current_page) { li.className += activeClassName; }
	});
}

// 	converts things like: http://nd.edu/some/crazy/path.html to /some/crazy/path.html
function parsePath(url) 						{ return removeIndexFilenames(removeProtocolAndDomain(url)); }

// removes any index.shtml or index.cfm files from a url (ie: /thing/index.shtml => /thing/)
function removeIndexFilenames(url) 	{ 
	url = url.replace('index.shtml', '');
	url = url.replace('index.cfm', '');
	return url;
}

// removes the http:// and domain from url
function removeProtocolAndDomain(url) {
	var domain = document.domain;
	if (url.indexOf(domain) == -1) {
		var pathStart = url.indexOf(domain) + domain.length;
		url       		= url.substring(pathStart);
	}
	return url.replace('http://', '');
}

function init() { activateNav('subnav', 'active'); }
Event.onDOMReady(init);