jQuery(document).ready(function($) {
	$("#leftnav>ul>li").css({"padding-left" : "0px", "width" : "200px"});
	var oe = $("li.currentPage:eq(0)"); //Sets the old element to the li of the currentPage
	$(oe).find("ul").slideToggle(0);
	$("#leftnav>ul>li").prepend("<img src='/images/blank.gif' width='9' height='9'/>"); //Adds an image before the menu text
  	$("li.currentPage img").attr("class", "down"); //Assigns the currentpage image as having a default class of down
  	$("#leftnav>ul>li>img").click(function() { // Function for when an arrow image is clicked
		var ee = $(this).closest("li"); //The parent LI of the image that was clicked
		var ec = $(ee).attr("id");  //The ID value of the parent LI that was clicked
		var os = $(this).attr("class"); // The class of the image that was clicked
		if ($(ee).closest("ul").attr("id") != "flights") { //Do nothing if the image clicked is within the flights menu, ie arrivals/depatures
		
			if ($(oe).attr("title") != $(ee).attr("title")) {	// If the previously clicked element parent LI is different than the currently clicked element parent LI
				$(oe).removeAttr("id"); //Removes the ID attribute from the previously clicked element
				$(oe).find("img").attr("class", "up"); //Assigns the class "up" to the previously clicked image
				$(oe).find("ul").slideUp("normal"); //Toggles (up) the previous clicked element up
				$(ee).find("ul").slideDown("normal"); //Toggles (down) the currently clicked child UL down
				$(this).attr("class", "down"); //Assign the class down to the currently clicked image
				$(ee).attr("id", "expanded"); //Assigns the ID "expanded" to the clicked element
			}
			
			else { // If the previously clicked element parent LI IS THE SAME as the currently clicked element
				$(ee).find("ul").slideToggle("normal"); //Toggle the child ul of the LI clicked
				if (os == "up") { // If the image has a class of "up"
					$(this).attr("class", "down"); // Set the class of the element to "down"
					$(ee).attr("id", "expanded"); //Assigns the ID "expanded" to the clicked element
				}
				else {	 // If the image has a class of "down"	
					$(this).attr("class", "up"); // Set the class of the element to "up"
					$(ee).removeAttr("id"); //Remove the "expanded" ID from the clicked element
				}
			}
			oe = ee; //Assigns the currently clicked element as the old element clicked
		}
	//Fini
  });
});
