// JavaScript Document

/*----------------------------------------------------------------*/
/*	Loads the contents of the current top-level nav item into the
/*	sidebar navigation menu
/*----------------------------------------------------------------*/
function initSideNav(navid){
	var sidenav = $("#nav>li.current>ul").html();
	if(sidenav == null || sidenav == ""){
		if(navid != null && navid != ""){
			sidenav = $("#"+navid+">ul").html();	
		}else{
			sidenav = $("#nav_welcome>ul").html();
		}
	}
	$("#sidenav").html("<ul id='subnav'>" + sidenav + "</ul>");
	initEmptyNavs();
}

/*----------------------------------------------------------------*/
/*	Configures any 'empty' nav items (does not link to any page) in
/*	the sidebar navigation menu to expand their child <ul> on click
/*----------------------------------------------------------------*/
function initEmptyNavs(){
	$("#subnav li").each(function(i,elem){
		var id = $(elem).attr("id");
		var a = $("#subnav #"+id+" a:first");
		var href = $(a).attr("href");
		if(href == "#"){
			$(a).attr("nav_id", id);
			$(a).unbind("click");
			$(a).click(function(){
				var id = $(this).attr("nav_id");
				$("#subnav #"+id+" ul:first").slideToggle("fast");
			});
		}
	});
}