function pathToURL(path){
	var e = document.createElement('span');
	e.innerHTML = '<a href="' + path + '" />';
	return e.firstChild.href;
}


$(function() {
////////////////////////////////////////////////////////////

// smartRollover
$('img').each(function () {
	if($(this).attr("src").match("_off.")) {
		$(this).mouseover(function() {
			$(this).attr("src", $(this).attr("src").replace("_off.", "_on."));
		});
		$(this).mouseout(function() {
			$(this).attr("src", $(this).attr("src").replace("_on.", "_off."));
		});
	}
});
// current page (goals)
var url = document.URL.split("#");
if (url[0].match(/\/$/)) {
	url[0] += 'index.html';
}
$("ul.goals a").each(function () {
//alert(url[0]+"\n"+pathToURL($(this).attr("href")));
	if (url[0] == pathToURL($(this).attr("href")) || url[0] == pathToURL($(this).attr("href")) + '/index.html' || url[0] == pathToURL($(this).attr("href")) + 'index.html') {
		$(this).children("img").attr("src", $(this).children("img").attr("src").replace("_off.", "_on."));
	}
});

// current page (contents)
// ----
var divIdName = '#sidebar .index';
var activeClassName = 'active';
var parentFlag = 1;
// -----
var url = document.URL.split("#");
if (url[0].match(/\/$/)) {
	url[0] += 'index.html';
}
$(divIdName + " a").each(function () {
//alert(url[0]+"\n"+pathToURL($(this).attr("href")));
	if (url[0] == pathToURL($(this).attr("href")) || url[0] == pathToURL($(this).attr("href")) + '/index.html' || url[0] == pathToURL($(this).attr("href")) + 'index.html') {
		if (parentFlag) {
			$(this).parent("li").addClass(activeClassName);
		} else {
			$(this).addClass(activeClassName);
		}
	}
});
// current page (index)
// ----
var divIdName = '#sidebar .index h5';
var activeClassName = 'active';
// -----
var url = document.URL.split("#");
if (url[0].match(/\/$/)) {
	url[0] += 'index.html';
}
$(divIdName + " a").each(function () {
//alert(url[0]+"\n"+pathToURL($(this).attr("href")));
	if (url[0] == pathToURL($(this).attr("href")) || url[0] == pathToURL($(this).attr("href")) + '/index.html' || url[0] == pathToURL($(this).attr("href")) + 'index.html') {
		$(this).addClass(activeClassName);
	}
});

////////////////////////////////////////////////////////////
});


