
$(function(){
	var rootPath = absolutePath($('a.rootLink').attr('href'));
	var rootDirPath = rootPath.replace(/index\.html$/, '');
	$('#nav a[href]').each(function(){
		var a = $(this);
		var href = a.attr('href');

		if (isCurrentPage(href) || isParentDir(href)) { 
			a.find('img').each(function(){
				var img = $(this);
				var src = img.attr('src');
				var currentSrc = src.replace('_off.', '_on.');
				img.attr('src', currentSrc);
			});
		}
	});
	function absolutePath(path){
		var e = document.createElement('span');
		e.innerHTML = '<a href="' + path + '" />';
		return e.firstChild.href;
	}
	function isCurrentPage(path){
		return absolutePath(path) === location.href;
	}
	function isParentDir(path){
		var dirPath = absolutePath(path).replace(/index\.html$/, '');
		return 0 <= location.href.search(dirPath) && rootDirPath !== dirPath;
	}
});

