//var lhs_color = "#9ea374";
var lhs_color_selected = "#ec008c";
function lhs_click(obj) {
	//if is a valid link then return
	if ($(obj).attr("href")!="#") return true;
	var id = obj.id.split("lhs")[1];
	//if has subitems, continue
	lhs_slide_item(id);
	return false;
}

function lhs_slide_item(id) {
	if ($("#sub"+id).children("a").length>0) {
		var slided = ($("#sub"+id).attr("slided")!="true") ? "true" : "false";
		//slide up all top level items
		if (slided=="true") $("#lhsmenu div").each(function() {
			if ($(this).attr("slided")=="true") {
				$(this).slideUp();
				//$(this).css("background", "url(/images/arr-dn.gif) no-repeat right");
			}
			$(this).attr("slided", "false");
			//$(".level0").css("color", lhs_color);
		});
		//slide it
		$("#sub"+id).slideToggle();
		$("#sub"+id).attr("slided", slided);
		$("#lhs"+id).css("color", (slided=="true") ? lhs_color_selected : "");
		if (slided=="true") {
			//$("#lhs"+id).css("background", "url(/images/arr-up.gif) no-repeat right");
		} else {
			//$("#lhs"+id).css("background", "url(/images/arr-dn.gif) no-repeat right");
		}
	}
}

$(function() {
	var found = false;
	var urlparts = document.URL.replace("http://","")
	var page = urlparts.substring(urlparts.indexOf("/"),urlparts.length);
	if (typeof (ui_page) != "undefined") page = ui_page;
	$("#lhsmenu a").each(function() {
		var id = ($(this).attr("className")=="level0") ? $(this).attr("id").split("lhs")[1] : $(this).parent().attr("id").split("sub")[1];
		//if ($("#sub"+id).children("a").length>0 && $(this).attr("className")=="level0") $(this).css("background", "url(images/arr-dn.gif) no-repeat right");
		if ($(this).attr("href")==page || (page=="programmes.php" && $(this).attr("href")=="programmes.php?id=32")) {
			lhs_slide_item(id);
			$(this).css("color", lhs_color_selected);
			found = true;
		}
	});
	//if (!found) {
	//	var id = $("#lhsmenu a").attr("id").split("lhs")[1];
	//	if ($("#sub"+id).children("a").length>0) {
	//		lhs_slide_item(id);
	//	}
	//}
	return;
});