$(document).ready(function() {

	// Hide sub menus on load

		$('#nav ul').hide();

	
	// sub menu function

		$('#nav li a').hover(

		function() 

		{

		
	// Highlight Active tab ONLY

		if ($(this).next().is(':hidden')) 

			{

			$('#nav li a').removeClass("selected");

			$(this).addClass("selected");

			}



	// Hide Sub-menu if Parent menu is clicked and the sub menu is Visible

		if($(this).next().is(':visible')) 

			{

			$(this).next().hide();

			$('#nav li a').removeClass("selected");

			return false;

			} 
			else {



	// Continue...

		if( ($(this).next().is('ul')) && ($(this).next().is(':visible')) ) 

			{

			$('#nav li a').removeClass("selected");

			return false;

			}



			if( ($(this).next().is('ul')) && (!$(this).next().is(':visible')) ) 

			{

			$('#nav ul:visible').slideUp(1);

			$(this).next().slideDown(1);

			return false;

			}

		}

		},

		function()

		{

     //no action

		});

});





