scms.namespace("ext");

scms.ext.customNavigation = {
    pool:{},
    timeout:null,
    triggered:false,

    open:function(handler, cntId)
    {
        var cnt = document.getElementById(cntId);

        $D = YAHOO.util.Dom;

        // hide others
        for (i in this.pool) {
            $D.setStyle(this.pool[i], "display", "none");
        }

        $D.setStyle(cnt, "display", "block");

        this.pool[cntId] = cnt;

        this.triggered = false;

        // x
        var x = $D.getX(handler);

        // y
        var y = $D.getY(handler) + handler.offsetHeight;

        if (YAHOO.env.ua.ie > 0 && YAHOO.env.ua.ie <= 6) {
            y += 2;
        }

        $D.setXY(cnt, [x, y]);
    },

    registerOpenTimeout:function(cntId)
    {
        var inst = this;
        setTimeout(function() { if (!inst.triggered) inst.close(cntId); }, 1000);
    },

    triggerIn:function(cntId)
    {
        if (!this.pool[cntId]) {
            return;
        }

        this.triggered = true;

        if (this.timeout) {
            clearTimeout(this.timeout);
            this.timeout = null;
        }
    },

    triggerOut:function(cntId)
    {
        if (!this.pool[cntId]) {
            return;
        }

        if (!this.timeout) {
            var inst = this;
            this.timeout = setTimeout(function() { inst.close(cntId); }, 500);
        }
    },

    close:function(cntId)
    {
        $D = YAHOO.util.Dom;

        if (this.pool[cntId]) {
            $D.setStyle(this.pool[cntId], "display", "none");
        }
    },

    hoverIn:function(li)
    {
        if (li.className.indexOf("hover") == -1) {
            li.className += " hover";
        }
    },

    hoverOut:function(li)
    {
        if (li.className.indexOf("hover") != -1) {
            li.className = li.className.replace("hover", "");
        }
    }
};

