$(document).ready( function() {

	// Show the menu that contains the link to the current page.
	showMenu( $("#siteLinks a[href=" + window.location.pathname + "]").parent().parent() );

	// Highlight the current menu item.
	$("#siteLinks a[href=" + window.location.pathname + "]").parent().addClass("currentPage");

	// Change the bullet for links which have children.
	$("#siteLinks li").each( function() {
		if ( $(this).find("ul").length > 0 ) {
			$(this).addClass("hasChildren");
		}
	});

	// Open/close the child menu if it has any. Otherwise allow the link to do it's default stuff.
	$("#siteLinks li a").click(
		function(e) {
			if ( $(this).parent().find("ul:first").length > 0 ) {
				e.preventDefault();
				$(this).parent().find("ul:first").slideToggle(200);
			}
		}
	);

});

/**
 * Show the ul and all it's parents (recursively), if hidden.
 */
function showMenu(elem) {
	if ( elem.is(":hidden") ) {
		elem.show();
		showMenu( elem.parent().parent() );
	}
}


