
var hideTimer = null;
var curMenu = '';
function RestoreNavMenu() {
    $('.subMenu').hide();
    $('div.navOverItem').attr('class', 'navItem');
    if (curMenu != '')
        $('#' + curMenu).attr('class', 'navCurrentItem');
}

$(function() {

    $('div.subMenu').hover(
        function() {
            if (hideTimer != null)
                clearTimeout(hideTimer);

        },
        function() {
            RestoreNavMenu();
        }
    )

    $('div.navItem, div.navCurrentItem').hover(
        function() {

            if (curMenu == '')
                curMenu = $('div.navCurrentItem').attr('id');

            if (hideTimer != null)
                clearTimeout(hideTimer);

            var menuID = $(this).attr('name');
            if ($('#' + menuID).is(':visible'))
                return;

            RestoreNavMenu();

            $(this).attr('class', 'navOverItem');
            var top = $(this).position().top + $(this).height() + 3;
            var left = $(this).position().left;

            var menuID = $(this).attr('name');
            $('#' + menuID).css({
                'top': top + 'px',
                'left': left + 'px'
            });

            $('#' + menuID).show();
        },
        function() {
            hideTimer = setTimeout(function() {RestoreNavMenu();}, 300)
        }
    )
})
