// Global variables
var xMousePos       = 0; // Horizontal position of the mouse on the screen
var yMousePos       = 0; // Vertical position of the mouse on the screen

var timeout		    = 400; // menu hide time out 
var opentimer       = 0; //open timer
var closetimer	    = 0; //close timer
var menuItem        = 0; //menu item
var overtimer       = 100; //timer to increase the timeout

// open hidden layer
function mopen(id) {
    // cancel close timer
    mcancelclosetime();

    // close old layer
    if (menuItem) {
        if (menuItem.id == id) {
            return false;
        }
        if(!menuItem.className.match(/active/)) {
            Element.addClassName(menuItem, 'inactive');
        }
    }

    // get new layer and show it
    opentimer = window.setTimeout(function() {
								  		menuItem = $(id);
								  		Element.removeClassName(menuItem, 'inactive');
								  },
								  overtimer
			    );
}

// close showed layer
function mclose() {
    if (menuItem && !menuItem.className.match(/active/)) {
        Element.addClassName(menuItem, 'inactive');
        menuItem = null;
    }
}

// go close timer
function mclosetime() {
    window.clearTimeout(opentimer);
    closetimer = window.setTimeout(mclose, timeout);
}

// cancel close timer
function mcancelclosetime() {
    if(closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}
