﻿var currentUl = null;
var closeTimer = 0;
var timeOut = 1000;

function Menu() {
    $('#menu ul li').bind('mouseover', function() {
        open(this);
    });
    $('#menu ul li').bind('mouseout', function() {
        startTimer();
    });
    $('#menu ul li ul li').unbind('mouseover');
    $('#menu ul li ul li').unbind('mouseout');
}

function open(li) {
    close();
    cancelTimer();
    currentUl = $(li).find('ul').css({ display: "block" });
}

function close() {
    if (currentUl) {
        $(currentUl).css({ display: "none" });
    }
}

function startTimer() {
    closeTimer = window.setTimeout(close, timeOut)
}

function cancelTimer() {
    if (closeTimer) {
        window.clearTimeout(closeTimer);
        closeTimer = null;
    }
}