/**include
//_javascript/js-wrapper.js;
*/

/**
 * Modal window control
 *
 */
var menuControl = {
    id     : null,
    id_key : null,
    winWr  : null,

    timer  : null,
    curId  : 0,

    init : function(id, id_key, winWr)
    {
        this.winWr = winWr ? winWr : _wrapper;

        this.id     = id;
        this.id_key = id_key;

        this.winWr.createStyle("#" + this.id + " .lev2", "position: absolute; display: none; z-index: 100;");
        this.winWr.setOnloadListener(this);
    },

    onload  : function(evtWr)
    {
        var i, idk, el_1, el_2;
        this.winWr.removeOnloadListener(this);

        for(var i in this.id_key) {
            idk = this.id_key[i];
            el_1 = this.winWr.getElement(this.config.main_id + idk);
            el_1.addListener(this, "onmouseover").idk = idk;
            el_1.addListener(this, "onmouseout").idk = idk;
            el_2 = this.winWr.getElement(this.config.add_id + idk);
            el_2.addListener(this, "onmouseover").idk = idk;
            el_2.addListener(this, "onmouseout").idk = idk;
        }
    },
    onmouseover : function(evtWr, dt)
    {
        var el_1, el_2;
        this.clearTimer();
		if (dt.idk != this.curId) {
			if (this.curId != 0) {
		        this.hideMenu();
			}
			el_1 = evtWr.elmWr;
			el_2 = this.winWr.getElement(this.config.add_id + dt.idk)
	        el_2.move(el_1.getX(), el_1.getY() + el_1.getHeight() + 0);
	        el_2.show();
		}
		this.curId = dt.idk;
    },

    onmouseout : function(evtWr, dt)
    {
		this.timer = this.winWr.setTimeout(this.config.delay,this,"hideMenu");
    },

    hideMenu : function()
    {
        this.clearTimer();
        this.winWr.getElement(this.config.add_id + this.curId).hide();
		this.curId = 0;
    },

    clearTimer : function()
    {
        if(this.timer) {
            clearTimeout(this.timer);
			this.timer = null;
        }
    },

    config : {
        "main_id" : "topMenu_m",
        "add_id"  : "topMenu_a",
        "delay"  : 500
    }

};