$(function() {
	// If one of the left menu li's has a class "open", then it will be open by default
	$("#left-menu .open")
		.addClass("left-menu-open")
		.children("ul").show();
	
	
	
	
	$("#left-menu").children("li").children("a").click(function() {
		var this_parent = $(this).parent(); // Gets the parent of the linked that was clicked. This will be a <li> element
		var same_as_open = false; // Variable to track whether the menu that was clicked was the one menu that was already opened.
		
		if($(this_parent).hasClass("left-menu-open")) // If the <li> parent has the "opened" class, then this menu was already opened and was clicked again
			same_as_open = true;
			
		$("#left-menu li").removeClass("left-menu-open"); // Remove the menu "open" class. Changes the appearance of the menus
		$("#left-menu ul").slideUp('fast'); // Close all menus
		
		if(same_as_open) // If the parent was open, and then clicked, Just close it.
			return;
		
		$(this_parent).find("ul").slideToggle('fast'); // Open the clicked menu
		$(this_parent).toggleClass("left-menu-open"); // Give the clicked menu the "open" appearance
		
	});
	
	
	
	
	var url = document.location.toString();
	if (url.match('\\?')) { // the URL contains an variable
		var menu_open = url.split('?pane=')[1];
		
		if(menu_open == "contact-us")
			setTimeout('show_pane("contact-us");', 450); // Delay to let Google Map load before switching to it
		else {
			if($("#left-menu").find('#menu-' + menu_open).children("a").click().size() <= 0) {
				$("#left-menu").find('a[href*="'+menu_open+'"]').parent().parent().parent().children("a").click();
			}
		}
		
		if($("#" + menu_open).size() > 0) // If the pane exists, open it
			show_pane(menu_open);
	}
});
