// JavaScript Document
jQuery(document).ready(function($) {
	$('#menu ul').hide(); //This hides all submenus when the page loads
	$('#menu li.current_page_parent ul').show(); //If the current page has submenus, they are shown on load
	
	$('#menu>li>a').click(function(){ //if a main menu is clicked do the following:
		var $nextUL = $(this).next(); //find the next tag after the clicked item and store it in a variable
		var $visibleSubmenus = $('#menu>li>ul:visible').not($nextUL);	//check for visible submenus, ignoring the next ul and store it in a variable
		if ($visibleSubmenus.length ) { //if there are visible submenus (length returns how many there are so if there is 1 or more)
		  $visibleSubmenus.slideUp('fast', function() { //hide all visible submenus then do the following
			$nextUL.slideToggle('fast'); //show the next ul tag
		  });
		} else { //if there are no other visible submenus do the following:
			$nextUL.slideToggle('fast'); //show the next ul tag
		}
		if( $nextUL.is('ul') ){  //if there is submenu
			return false; //ignore the url of the parent menu
		}
	});
});
