﻿var timeout = 200;
var timer = null;
var parent = null;
var dropdown = null;


function menuOpen(id) {
    menuClose();

    parent = document.getElementById(id);
    parent.className = 'menuSelected';

    dropdown = document.getElementById(id + 'Dropdown');
    dropdown.style.visibility = 'visible';
}


function menuClose() {
    menuCancelTimer();
    
    if (dropdown)
        dropdown.style.visibility = 'hidden';
    dropdown = null;
    
    if (parent)
        parent.className = 'menuUnselected';
    parent = null;    
}


function menuSetTimer() {
    timer = window.setTimeout(menuClose, timeout);
}


function menuCancelTimer() {
    if (timer) {
        window.clearTimeout(timer);
        timer = null;
    }
}


