/*
 * Javascript that affects entire site 
 */

$(document).ready(function() {
	// Mousing over highlight box items
	$("#highlights ul li").bind('mouseenter', function() {
		// If we don't already have an overlay create one
		$('<div class="link-overlay"></div>').appendTo(this);
		
		var href = null;
		
		// get first <a>'s href attr value
		// use "find" because we don't assume it's a single descendent down
		$(this).find("a").each(function() {
			href = $(this).attr("href");
			return;
		});
		
		// add <a> tag to overlay
		$("#highlights .link-overlay").html('<a href="'+href+'"></a>');
		
		// when mouse moves away, remove overlay
		$(this).one('mouseleave', function() {
			$(this).children('.link-overlay').remove();
		});
	});
	
	// Mousing over drop down menu
	$("#header .nav ul#menu-main-menu li").hover(
			// mouse over
			function() { 
				// get drop down menu
				var children = $(this).children("ul.sub-menu:first");
				
				// if menu actually exists
				if (children.length > 0) {
					// flush out current event queue and then slide down
					children.stop(true, true).slideDown(250);
				}
			}, 
			// mouse leave
			function() { 
				// get drop down menu
				var children = $(this).children("ul.sub-menu:first");
				
				// if menu actually exists
				if (children.length > 0) {
					// flush out current event queue and then slide up
					children.stop(true, true).slideUp(125);
				}
			} 
			);
	
	
	
});

