$(document).ready(function(){
 var showTarget =  $("#mainNav").find("ul li");
var addClose = $(showTarget).find("ul");

//$(addClose).css({height:"auto"});
$(addClose).append("<li style=\"background:none;\" class=\"close\"><a href=\"#\" title=\"Click to Close This Menu\">collapse</a></li>");
$(".close").click(function()
	{
		$(this).parent("ul").slideUp("slow");
		return false;
		//alert("you clicked here!");
	});
 
$("#mainNav").find("ul ul").slideUp("fast");
 $(showTarget).hover(function(){
	$(this).find("ul:hidden").slideDown("fast");
	//alert("You just hovered");
	},function(){
	//alert("You just removed your mouse");
	});
  
// set link current based on its href attribute.
if (location.pathname.substring(1)) {
	//alert (location.pathname.substring(1));
	$('#mainNav a[@href$="' + location.pathname.substring(1) + '"]').attr('class', 'current');
}else{
	$('#mainNav #navHome a').attr('class', 'current');	
}


// show navigation submenu if it or the immediate parent contains .current
var currentTarget =  $("#mainNav ul li a.current");
//alert ("Parent Element "+$(currentTarget).parents());
var addOpen = $(currentTarget).parents("li").children("ul");
$(addOpen).slideDown("slow");

});
