$(function(){
	$("#major_nav").children("li").each(function() {
		var current = "active";
		var parentClass = $(this).attr('id');
		var thisClass = $(this).attr('class');
		$(this).children("a").css({backgroundImage:"none"});
		
		if (parentClass == current) {
			$(this).before('<div class="nav_' + thisClass + '_active"></div>');
		}
		
	});
				
	$.each(['home', 'programs', 'coastal_monitoring', 'events', 'support', 'about'], function (i, val) {
		attachNavEvents("#major_nav", val);	
	});
	
	function hoverOver() {
		myClass = $(this).attr('class');
		$(this).before('<div class="nav_' + myClass + '"></div>');
		$("div.nav_" + myClass).css({display:"none"}).fadeIn(300);
	}
	
	function hoverOut() {
		myClass = $(this).attr('class');
		
		$("div.nav_" + myClass).fadeOut(300, function() {
			$(this).remove();
		});
		
	}
			
	function attachNavEvents(parent, myClass) {
		
		
		var config = {    
			 sensitivity: 10, // number = sensitivity threshold (must be 1 or higher)    
			 interval: 50, // number = milliseconds for onMouseOver polling interval    
			 over: hoverOver, // function = onMouseOver callback (REQUIRED)    
			 timeout: 0, // number = milliseconds delay before onMouseOut    
			 out: hoverOut // function = onMouseOut callback (REQUIRED)    
		};
		
		$(parent + " ." + myClass).hoverIntent(config); 
		
	}
});