$(document).ready(function() {
	var EXPAND = "+";
	var COLLAPSE = "-";
	$(".navigation_menu").find("ul").each(function() {
		$(this).hide();
		$(this).parent().addClass("hassub");
		$("<a class='expand' href='#'>"+EXPAND+"</a>").prependTo($(this).parent()).click(function() {
			var ul = $(this).parent().find("ul:first");
			if($(ul).is(":hidden")) {
				$(".hassub").each(function() {
					var hide = true;
					$(this).find("a").each(function() {
						if($(this).hasClass("active")) {
							hide = false;
							return;
						}
					});
					if(hide) {
						$(this).find("a:first").html(EXPAND);
						$(this).find("ul:first").hide();
					}
				});
				expandParentElements($(this));
			}
			else {
				$(ul).hide();
				$(this).html(EXPAND);
			}
			return false;
		});
	});
	$("body:first").each(function() {
		if($(this).attr("id") == "") {
			return;
		}
		if($(".navigation_menu").length > 0) {
			var a = $("#"+$(this).attr("id").replace(/^page-/, ""));
			if($(a).attr("id") == "indexpage" || $(a).length <= 0) {
				return;
			}
			$(a).addClass("active");
			expandParentElements($(a));
		}
	});
	function expandParentElements(a) {
		var lis = new Array();
		while($(a).attr("id") != "navigation") {
			if($(a).get(0).tagName.toUpperCase() == "LI") {
				lis.push($(a));
			}
			a = $(a).parent();
		}
		$(lis).each(function() {
			$(this).find(".expand:first").html(COLLAPSE);
			$(this).find("ul:first").show();
		});
	}
});
