function menuInit(defaultItem) {
	// Set up mouse in/out functions on all menu items
	// to set color to the same as the main content and then back to nothing
	$("#sidebar").bind("mouseenter", function() {
		$("[id|=mnu]").css("opacity", 0.8);
	});
	$("#sidebar").bind("mouseleave", function() {
		$("[id|=mnu]").css("opacity", 1.0);
	});
	$("[id|=mnu]").bind("mouseenter", function() {
		$(this).css("opacity", 1.0);
		$(this).addClass('over');
	});
	$("[id|=mnu]").bind("mouseleave", function() {
		$(this).css("opacity", 0.8);
		$(this).removeClass('over');
	});
	$("[id|=mnu]").click(function(event) {
		loadContent($(this).attr("id"));
	});
	
	// Finally... Load the menu provided as default (main?)
	loadContent(defaultItem);
}
function loadContent(id) {
	// Deal with menu item(s);
	$("[id|=mnu]").removeClass("selected");
	$("#" + id).addClass("selected");

	var parts = id.split("-");
	hideAllSubs(parts[0] + "-" + parts[1]);
	showSubs(parts[0] + "-" + parts[1]);
	var url = "";
	var subid = "";
	// build up path to contents using the ID of the menu item
	// Example mnu-test-sub-example.html
	// This would go the url ./content/test/sub/example.html
	for (var i = 0; i < parts.length; i++) {
		if (i > 0) url += "/";
		url += parts[i];
	}
	$('#content').hide();
	$('#content').load("./content/" + url + ".html", function(txt,stat,xhr) {
		if (stat=="error") {
			$("#content").html(xhr.status + " " + xhr.statusText);
			$("#content").show();
		} else {
			$("#content").fadeIn(500);
		}
	});
}
function hideAllSubs(except) {
	$('[id|=mnu').each(function(i) {
		var thisId = $(this).attr("id");
		if (thisId.split("-").length == 2) {
			if (thisId != except) {

				$("[id|=" + thisId + "]").each(function(i) {
					var anId = $(this).attr("id");
					if (anId != thisId) { $(this).hide(); }
				});
			}
		}
	});
}

function showSubs(id) {
	$('[id|=' + id + ']').fadeIn(200);
}

// =============================================================
// Cookie functions from other site
function setCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	} else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function getCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function deleteCookie(name) { setCookie(name,"",-1); }


