﻿Type.registerNamespace('mishcon.web.Controls.Related');

mishcon.web.Controls.Related.CollapsibleRelatedLinksBehavior = function(element) {
    mishcon.web.Controls.Related.CollapsibleRelatedLinksBehavior.initializeBase(this, [element]);

    this._toggleButtonID = null;
    this._showByDefault = null;
    
    this._toggleButton = null;
    this._visible = null;
}

mishcon.web.Controls.Related.CollapsibleRelatedLinksBehavior.prototype = 
{
    get_ToggleButtonID : function() 
    {
        return this._toggleButtonID;
    },

    set_ToggleButtonID : function(value) 
    {
        this._toggleButtonID = value;
    },
    
    get_ShowByDefault : function() 
    {
        return this._showByDefault;
    },

    set_ShowByDefault : function(value) 
    {
        this._showByDefault = value;
    },
    
    initialize : function() 
    {
        mishcon.web.Controls.Related.CollapsibleRelatedLinksBehavior.callBaseMethod(this, 'initialize');

        this._toggleButton = $get(this._toggleButtonID);
		$addHandler(this._toggleButton, 'click', Function.createDelegate(this, this._onToggleButtonClick));
		
        if(this._showByDefault)
        {
            this._show(true);
        }
        else
        {
            this._hide(true);
        }
    },

    dispose : function() 
    {

        mishcon.web.Controls.Related.CollapsibleRelatedLinksBehavior.callBaseMethod(this, 'dispose');
    },
    
    _show : function(bInstant)
    {
        $('#' + this._element.id + ' input').blur();
        if(bInstant)
        {
            $('#' + this._element.id + ' div.panel_body').show();
        }
        else
        {
            $('#' + this._element.id + ' div.panel_body').slideDown();
        }
        $('#' + this._element.id + ' input').attr("src", "/images/panels/pan_tog_dn.gif");
        this._visible = true;
    },
    
    _hide : function(bInstant)
    {
        $('#' + this._element.id + ' input').blur();
        if(bInstant)
        {
            $('#' + this._element.id + ' div.panel_body').hide();
        }
        else
        {
            $('#' + this._element.id + ' div.panel_body').slideUp();
        }
        $('#' + this._element.id + ' input').attr("src", "/images/panels/pan_tog_up.gif");
        this._visible = false;
    },
    
    _onToggleButtonClick : function(ev) 
    {
        if(this._visible)
        {
            this._hide(false);
        }
        else
        {
            this._show(false);
        }
        
	    ev.preventDefault();
    }
}

mishcon.web.Controls.Related.CollapsibleRelatedLinksBehavior.registerClass('mishcon.web.Controls.Related.CollapsibleRelatedLinksBehavior', AjaxControlToolkit.BehaviorBase);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();