Type.registerNamespace('DHCControlToolkit');
DHCControlToolkit.DHCHoverMenuBehavior = function(element) {
    DHCControlToolkit.DHCHoverMenuBehavior.initializeBase(this, [element]);
    this._hoverBehavior = null;
    this._hoverHandler = null;
    this._unhoverHandler = null;
    this._hoverAnimation = null;
    this._unhoverAnimation = null;
    this._endRequestHandler = null;
    
    this._parentID = null;
    this._labelWidth = null;
    this._contentWidth = null;
    this._labelBackgroundColor = null;
    
    this._open = false;
}

DHCControlToolkit.DHCHoverMenuBehavior.prototype = {
    initialize : function() {
        DHCControlToolkit.DHCHoverMenuBehavior.callBaseMethod(this, 'initialize');
        
        this._hoverHandler = Function.createDelegate(this, this._onHover);
        this._unhoverHandler = Function.createDelegate(this, this._onUnhover);
        
        this._hoverBehavior = $create(AjaxControlToolkit.HoverBehavior, { "id":this.get_id()+"_HoverBehavior", "unhoverDelay":500, "hoverElement": this.get_element() }, null, null, this.get_element());
        this._hoverBehavior.add_hover(this._hoverHandler);
        this._hoverBehavior.add_unhover(this._unhoverHandler);
        
        this._endRequestHandler = Function.createDelegate(this, this._endRequest);
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(this._endRequestHandler);
    },
    
    dispose : function() {
        var elem = this.get_element();
        
        if (this._hoverBehavior) {
            if (this._hoverHandler) {
                this._hoverBehavior.remove_hover(this._hoverHandler);
                this._hoverHandler = null;
            }
            if (this._unhoverHandler) {
                this._hoverBehavior.remove_hover(this._unhoverHandler);
                this._unhoverHandler = null;
            }
            this._hoverBehavior.dispose();
            this._hoverBehavior = null;
        }
        if(this._endRequestHandler)
            this._endRequestHandler = null;
        DHCControlToolkit.DHCHoverMenuBehavior.callBaseMethod(this, 'dispose');
    },
    
    _endRequest : function()
    {
        if( this._open )
        {
            this._hoverBehavior._hoverCount = 0;
            this._onHover();
        }
    },
    
    _onHover : function()
    {
        //var behavior = $find("animateReplyPanesBehavior");
        //behavior.get_OnClickBehavior().play();
        //behavior.get_OnClickBehavior().get_animation()
        if( !this._hoverAnimation )
        {
            this._hoverAnimation = new AjaxControlToolkit.Animation.SequenceAnimation($get(this._parentID), 0, 0, 
                                        new Array(
                                            new AjaxControlToolkit.Animation.ParallelAnimation($get(this._parentID+'_Label'), .01, 0, 
                                                new Array( 
                                                    new AjaxControlToolkit.Animation.StyleAction($get(this._parentID+'_LabelTopBorder'), .01, 0, "backgroundColor", "#000000"),
                                                    new AjaxControlToolkit.Animation.StyleAction($get(this._parentID+'_LabelLeftBorder'), .01, 0, "backgroundColor", "#000000"),
                                                    new AjaxControlToolkit.Animation.StyleAction($get(this._parentID+'_LabelRightBorder'), .01, 0, "backgroundColor", "#000000"),
                                                    new AjaxControlToolkit.Animation.StyleAction($get(this._parentID+'_Label'), .01, 0, "backgroundColor", this._labelBackgroundColor)
                                                )
                                            ),
                                            new AjaxControlToolkit.Animation.StyleAction($get(this._parentID+'_Box'), .01, 0, "display", "block"),
                                            new AjaxControlToolkit.Animation.ScriptAction($get(this._parentID+'_Box'), .01, 0, "AjaxControlToolkit.Animation.ResizeAnimation.play($get('"+this._parentID+"_Box'), .2, 25, null, $get('"+this._parentID+"_BoxBorder').clientHeight+2, 'px')")
                                        )
                                    );
        }
        if( this._unhoverAnimation )
        {
            this._unhoverAnimation.stop();
        }
        this._hoverAnimation.play();
        this._open = true;
    },
    
    _onUnhover : function()
    {
        if( !this._unhoverAnimation )
        {
            this._unhoverAnimation = new AjaxControlToolkit.Animation.SequenceAnimation($get(this._parentID), 0, 0, 
                                new Array(
                                    new AjaxControlToolkit.Animation.ResizeAnimation($get(this._parentID+'_Box'), .2, 25, null, 0, "px"),
                                    new AjaxControlToolkit.Animation.StyleAction($get(this._parentID+'_Box'), .01, 0, "display", "none"),
                                    new AjaxControlToolkit.Animation.ParallelAnimation($get(this._parentID+'_Label'), .01, 0, 
                                        new Array(
                                            new AjaxControlToolkit.Animation.StyleAction($get(this._parentID+'_LabelTopBorder'), .01, 0, "backgroundColor", "Transparent"),
                                            new AjaxControlToolkit.Animation.StyleAction($get(this._parentID+'_LabelLeftBorder'), .01, 0, "backgroundColor", "Transparent"),
                                            new AjaxControlToolkit.Animation.StyleAction($get(this._parentID+'_LabelRightBorder'), .01, 0, "backgroundColor", "Transparent"),
                                            new AjaxControlToolkit.Animation.StyleAction($get(this._parentID+'_Label'), .01, 0, "backgroundColor", "Transparent")
                                        )
                                    )
                                )
                            );
        }
        if( this._hoverAnimation )
        {
            this._hoverAnimation.stop();
        }
        this._unhoverAnimation.play();
        this._open = false;
    },
    
    get_parentID : function()
    {
        return this._parentID;
    },
    
    set_parentID : function(value)
    {
        this._parentID = value;
    },
    
    get_labelWidth : function()
    {
        return this._labelWidth;
    },
    
    set_labelWidth: function( value )
    {
        this._labelWidth = value;
    },
    
    get_contentWidth : function()
    {
        return this._contentWidth;
    },
    
    set_contentWidth: function( value )
    {
        this._contentWidth = value;
    },
    
    get_labelBackgroundColor : function()
    {
        return this._labelBackgroundColor;
    },
    
    set_labelBackgroundColor: function( value )
    {
        this._labelBackgroundColor = value;
    }
}
DHCControlToolkit.DHCHoverMenuBehavior.registerClass('DHCControlToolkit.DHCHoverMenuBehavior', AjaxControlToolkit.BehaviorBase);