$(function() {
	// Open the dropdown menu that is clicked, and close the others
	$('.nav-header').click(function() {
		var dropdown = $(this).children(":first-child");
		
		// Go through all the submenus and hide all but the one that was clicked
		$('.nav-submenu').each(function(index) {
			if ($(this).attr("id") != dropdown.attr("id")) {
				$(this).hide();
			}
		});
		
		dropdown.show(150);
	});
	
	// Close the menu if the user click somewhere outside the menu
	$(document).mouseup(function(e) {
		// To check if the user clicked outside the menu, 
		// check that neither the target nor its parents have .nav-header as a class.
		if(!$(e.target).hasClass('nav-header') && !$(e.target).parents().hasClass('nav-header')) {
			$('.nav-submenu').hide();
		}
	});
});
