/**include
//_javascript/js-wrapper.js;
*/

/**
 * Menu control
 */
var menuControl = newObject({
    id    : null,
    timer : null,
    curEl : -1,
    subMn : null,

    init : function (id) {
        this.id = "#" + id;
        this.$w0.createStyle(this.id + " .lev2", "position: absolute; display: none; z-index: 100;");
    },
    onready : function (a, b) {
        this.subMn = {};
        var al = this.$$(this.id + " a#menu_m*");
        for(var i = 0; i < al.length; i++) {
            al[i].onmouseover().i = i;
            al[i].onmouseout().i = i;
            this.subMn[i] = al[i].getNextSibling();
            if (this.subMn[i]) {
                this.subMn[i].addListener(this, "onmouseover").i = i;
                this.subMn[i].addListener(this, "onmouseout").i = i;
            }
        }
    },
    onmouseover : function(evtWr, dt)
    {
        var el_1, el_2;
        this.clearTimer();
        if (dt.i != this.curEl) {
            if (this.curEl >= 0) {
                this.hideMenu();
            }
            el_1 = evtWr.elmWr;
            el_2 = this.subMn[dt.i];
            if (el_2) {
                el_2.move(el_1.getX(), el_1.getY() + el_1.getHeight() + 0);
                el_2.show();
                this.curEl = dt.i;
            } else {
                this.curEl = -1;
            }
        }
    },
    onmouseout : function(evtWr, dt)
    {
        this.timer = this.$w0.setTimeout(this.config.delay, this, "hideMenu");
    },
    hideMenu : function()
    {
        this.clearTimer();
        if(this.curEl >=0 && this.subMn[this.curEl]) {
            this.subMn[this.curEl].hide();
            this.curEl = -1;
        }
    },
    clearTimer : function()
    {
        if(this.timer) {
            clearTimeout(this.timer);
            this.timer = null;
        }
    },
    config : {
        "delay"  : 500
    }
});
