﻿/*
Main menu script.
*******************************************************/
YAHOO.util.Event.onContentReady("mainMenu", function() {
    var ua = YAHOO.env.ua;
    var oAnim;
    var oMainMenu = new YAHOO.widget.MenuBar("mainMenu", {
        autosubmenudisplay: true,
        hidedelay: 750,
        lazyload: false
    });
    oMainMenu.render();

    function onSubmenuBeforeShow(p_sType, p_sArgs) {
        var oBody;
        var oElement;
        var oShadow;
        var oUL;
        if (this.parent) {
            oElement = this.element;
            oShadow = oElement.lastChild;
            oShadow.style.height = "0px";
            if (oAnim && oAnim.isAnimated()) {
                oAnim.stop();
                oAnim = null;
            }
            oBody = this.body;
            if (this.parent && !(this.parent instanceof YAHOO.widget.MenuBarItem)) {
                if (ua.gecko) {
                    oBody.style.width = oBody.clientWidth + "px";
                }
                if (ua.ie == 7) {
                    oElement.style.width = oElement.clientWidth + "px";
                }
            }
            oBody.style.overflow = "hidden";
            oUL = oBody.getElementsByTagName("ul")[0];
            oUL.style.marginTop = ("-" + oUL.offsetHeight + "px");
        }
    }

    function onSubmenuShow(p_sType, p_sArgs) {
        var oElement;
        var oShadow;
        var oUL;
        if (this.parent) {
            oElement = this.element;
            oShadow = oElement.lastChild;
            oUL = this.body.getElementsByTagName("ul")[0];
            oAnim = new YAHOO.util.Anim(oUL,
                { marginTop: { to: 0} },
                .5, YAHOO.util.Easing.easeOut);
            oAnim.onStart.subscribe(function() {
                oShadow.style.height = "100%";
            });
            oAnim.animate();
            if (YAHOO.env.ua.ie) {
                oShadow.style.height = oElement.offsetHeight + "px";
                oAnim.onTween.subscribe(function(functionp_sType, p_aArgs, p_oShadow) {
                    if (this.cfg.getProperty("iframe")) {
                        this.syncIframe();
                    }
                    if (p_oShadow) {
                        p_oShadow.style.height = this.element.offsetHeight + "px";
                    }
                }, oShadow, this);
            }
            oAnim.onComplete.subscribe(function(p_sType, p_aArgs, p_oShadow) {
                var oBody = this.body;
                var oUL = oBody.getElementsByTagName("ul")[0];
                if (p_oShadow) {
                    p_oShadow.style.height = this.element.offsetHeight + "px";
                }
                oUL.style.marginTop = "";
                oBody.style.overflow = "";
                if (this.parent && !(this.parent instanceof YAHOO.widget.MenuBarItem)) {
                    if (ua.gecko) {
                        oBody.style.width = "";
                    }
                    if (ua.ie == 7) {
                        this.element.style.width = "";
                    }
                }
            }, oShadow, this);
        }
    }
    oMainMenu.subscribe("beforeShow", onSubmenuBeforeShow);
    oMainMenu.subscribe("show", onSubmenuShow);
});