var subNavTransitionTimer = null;
var hideDestinationId = null;
function show_sub_nav(id){
	clear_subNav_transition_timer();
	subNavTransitionTimer = setTimeout(function(){show_sub_nav_timer(id)}, 150);
}
function show_sub_nav_timer(navId){
	var visibleSubNav = $(".subnav:visible");
	if (visibleSubNav.length != 0){
		clearNavHoverArrow();
		$("#" + navId).addClass("navHover");
		visibleSubNav.hide();
		$("#sub" + navId).show();
	}else{
		$("#" + navId).addClass("navHover");
		$("#sub" + navId).slideDown("fast");
	}
};
function clear_subNav_transition_timer(){
	if (subNavTransitionTimer != null){
		clearTimeout(subNavTransitionTimer);
		subNavTransitionTimer = null;
	}
};
function clearNavHoverArrow(){
	$('#nav a.navHover').removeClass("navHover");
}
function register_hideDestination(id){
	hideDestinationId = id;
	show_sub_nav_timer(id);
}
function hide_sub_nav(){
	clear_subNav_transition_timer();
	subNavTransitionTimer = setTimeout(function(){
	if (hideDestinationId != null){
		show_sub_nav_timer(hideDestinationId);
    }else{
		clearNavHoverArrow(); $(".subnav:visible").slideUp("fast");
    }
	}, 500);
};
$(function () {
	$('#nav a').each(function () {
		if (this.id != ''){
			this.onmouseover = function(){show_sub_nav(this.id);};
			this.onmouseout = function(){hide_sub_nav();};
		}
	});
	$('.subnav').each(function () {
		this.onmouseover = function(){clear_subNav_transition_timer();};
		this.onmouseout = function(){hide_sub_nav();};
	});
});
