//Author: At Large Graphic Design
//Contact: scott@atlargegraphicdesign.com

$(document).ready(function () {
	
	// -- This block will alternately assign class based on each individual ul.menubody in document. --- //
	
	//$('ul.menubody').filter(function() {
//		return $(this).find('li:odd').addClass('alt');
//	});


	// -- This block is used for the mouse hover behavior of the menus. --- //
	//$('.menuhead').hover(function () {
//		$(this).find('ul.menubody').slideToggle('fast');
//	});
	
	// -- This block is used for the mouse click behavior of the menus. --- //
	var prevMenu = null;

	$('.menuhead').click(function () {

		var openMenu = $(this).find('ul.menubody');
		
		if(openMenu.hasClass('open')) {
			// User clicked on menu that is currently open. Close menu, remove class indicator, and exit function.
			openMenu.slideUp('fast');
			openMenu.removeClass('open');
			return;
		} else if (prevMenu && prevMenu.hasClass('open')) {
			// Previous menu was left open. Close menu and remove class indicator.
			prevMenu.slideUp('fast');
			prevMenu.removeClass('open');
		};
		
		openMenu.slideDown('fast');
		openMenu.addClass('open');
		prevMenu = openMenu;
				
	});

	$('body').click(function() {
		if (prevMenu && prevMenu.hasClass('open')) {
			// Previous menu was left open. Close menu and remove class indicator.
			prevMenu.slideUp('fast');
			prevMenu.removeClass('open');
		};
	});
	
	$('#mainmenu').click(function(event) {
		event.stopPropagation();
	});

});
