﻿$(document).ready(function() {

	var inputDelayer = delayTimer(500);
	$('.nav-flyout-submenu').hide();
	$('.nav-flyout-submenu a').click(function() { $('.nav-flyout-submenu').hide('slow'); });
	$('.nav-flyout-header').click(function() { inputDelayer(); HideDisplaySubMenu(this.id, 'header click'); });
	$('.nav-flyout-header, .nav-flyout-submenu').mouseout(function() { inputDelayer(function() { HideDisplaySubMenu(null, 'mouseout'); }) });
	$('.nav-flyout-submenu').mouseover(function() { inputDelayer(); });

});

function HideDisplaySubMenu(thisId, from) {
	var subMenu = $('#' + thisId + 'Sub');
	if (subMenu) { $('#' + thisId + 'Sub').toggle('slow'); }
	$('#' + thisId).toggleClass('nav-flyout-header-on');
	$('.nav-flyout-header').each(function() { if (this.id != thisId) { $('#' + this.id).removeClass('nav-flyout-header-on'); if ($('#' + this.id + 'Sub')) { $('#' + this.id + 'Sub').hide('slow'); } } });
}

function delayTimer(delay) {
	var timer;
	return function(fn) {
		timer = clearTimeout(timer);
		if (fn) timer = setTimeout(function() { fn(); }, delay);
		return timer;
	}
}

