﻿if(!Controls)
{
    var Controls = {};
}

if(!Controls.DropDownMenuItem)
{
    Controls.DropDownMenuItem = function(elmSubMenu, elmSubMenuContent)
    {
        this._elmSubMenu = elmSubMenu;
        this._elmSubMenuContent = elmSubMenuContent;
        
        if(this._elmSubMenu)
        {
            this._elmSubMenu.style.display = "block";
            this._elmSubMenu.style.visibility = "visible";
        
            this._nSubMenuHeight = this._elmSubMenu.offsetHeight;
            
            this._elmSubMenu.style.height = "0px";
            this._elmSubMenuContent.style.marginTop = (-1 * this._nSubMenuHeight) + "px";
        }
    }
    
    Controls.DropDownMenuItem.Duration = 0.5;
    
    Controls.DropDownMenuItem.prototype.Animate = function(bHide)
    {
        var nHeightStart;
        var nHeightEnd;
        var nMarginStart;
        var nMarginEnd;
        
        if(!bHide)
        {
            nHeightStart = this._elmSubMenu.offsetHeight;
            nHeightEnd = this._nSubMenuHeight;
            nMarginStart = this._elmSubMenu.offsetHeight - this._nSubMenuHeight;
            nMarginEnd = 0;
        }
        else
        {
            nHeightStart = this._elmSubMenu.offsetHeight;
            nHeightEnd = 0;
            nMarginStart = this._elmSubMenu.offsetHeight - this._nSubMenuHeight;
            nMarginEnd = -1 * this._nSubMenuHeight;
        }
        
        if(this._oHeightAnimation)
        {
            this._oHeightAnimation.dispose();
        }
        if(this._oMarginAnimation)
        {
            this._oMarginAnimation.dispose();
        }
        
        if(bHide)
        {
            this._elmSubMenu.style.zIndex = 90;
        }
        else
        {
            this._elmSubMenu.style.zIndex = 100;
        }
        
        this._oHeightAnimation = new AjaxControlToolkit.Animation.LengthAnimation(this._elmSubMenu, Controls.DropDownMenuItem.Duration, 20, "style", "height", nHeightStart, nHeightEnd, "px");
        this._oMarginAnimation = new AjaxControlToolkit.Animation.LengthAnimation(this._elmSubMenuContent, Controls.DropDownMenuItem.Duration, 20, "style", "marginTop", nMarginStart, nMarginEnd, "px");
    
        this._elmSubMenu.style.display = "block";
        this._elmSubMenu.style.visibility = "visible";
    
        this._oHeightAnimation.play();
        this._oMarginAnimation.play();
    }
}
