// JavaScript Document
var active = false;

$(document).ready (function () {
	var primNav = $('.nav li');
	
	primNav.mouseover (function () {
		active = true;
		var index = primNav.index (this);
		
		// The corresponding drop down menu
		var dd = $('.drop-down').eq (index);
		
		var others = $('.drop-down').not(dd);
		
		// Hide the others (when any playing animations have finished
		// and slide out the correct dd
		others.each (function () {
			if ($(this).queue ().length > 0) {
				$(this).queue (function () { $(this).css ('display', 'none'); $(this).dequeue (); });
			} else {
				$(this).css ('display', 'none');
			}
		});

		dd.slideDown ();
	});
	primNav.mouseout (function () {
		active = false;
		setTimeout ('checkHover()', 1000);
	});
	
	// Don't hide the menus if a drop down has the mouse over it
	$('.drop-down').hover (
		function () { active = true; },
		function () { active = false; setTimeout ('checkHover()', 1000); }
	);
});
	
function checkHover () {
	if (!active) {
		$('.drop-down').slideUp ();
	}
}