$(function(){
	var timeToOpen = 400; // 1500 = 1.5 seconds this is the time that a user needs to sit on the nav link before drop down menus open.
	var timeToClose	= 250; // 750= 0.75 seconds this is the time after a user rolls off a menu before it closes.
	var hoverTimer = {};
	var fadeTimer = {};
	
	$('#topNavLinks > li').hover(function(){
		$(this).addClass('hoverIt');
		if($(this).hasClass('closeIt') == true){
			$(this).removeClass('closeIt');
			$.clearTimer(fadeTimer);	
		};
		hoverTimer = $.timer(timeToOpen, function(){
			$('#topNavLinks li.hoverIt').children('div').css('visibility','visible');							 
		});
	},function(){
		$.clearTimer(hoverTimer);
		$('#topNavLinks li.hoverIt').addClass('closeIt');
		fadeTimer = $.timer(timeToClose, function(){
			$('#topNavLinks li.closeIt').removeClass('hoverIt').removeClass('closeIt').children('div').css('visibility','hidden');
		});
	});
	
	$(window).unload( function () {
		$('#topNavLinks li.hoverIt').children('div').css('visibility','hidden');				
		$('#topNavLinks li').removeClass('hoverIt').removeClass('closeIt')
		$.clearTimer(fadeTimer);
		$.clearTimer(hoverTimer);
	});
});

jQuery.timer = function(time,func,callback){
	var a = {timer:setTimeout(func,time),callback:null}
	if(typeof(callback) == 'function'){a.callback = callback;}
	return a;
};

jQuery.clearTimer = function(a){
	clearTimeout(a.timer);
	if(typeof(a.callback) == 'function'){a.callback();};
	return this;
};
