String.prototype.endsWith = function (match) {
	if (match.length > this.length) return false;
	return match == this.slice(~match.length + 1);
}

function addClassSubMenu() {
	var sub = document.getElementById('sub');
	if (!sub) return;
	var links = sub.getElementsByTagName('a'),
	    url = location.href.replace(/index.html?/g, "").replace(/#.*$/g, "");
	if (!links) return;
	for (var i = 0, len = links.length; i < len; ++i)
		if (url.endsWith(links[i].href))
			links[i].className = 'current';
}

function addLoadEvent(func) {
	var oldOnLoad = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldOnLoad();
			func();
		}
	}
}

addLoadEvent(addClassSubMenu);

