﻿Type.registerNamespace('WM.WebControls.AJAX.ModalPopupAnimationExtender');

WM.WebControls.AJAX.ModalPopupAnimationExtender.ModalPopupAnimationBehavior = function(element) {
    
    WM.WebControls.AJAX.ModalPopupAnimationExtender.ModalPopupAnimationBehavior.initializeBase(this, [element]);
    // Generic animation behaviors that automatically build animations from JSON descriptions
    this._shown = new AjaxControlToolkit.Animation.GenericAnimationBehavior(element);
    this._hidden = new AjaxControlToolkit.Animation.GenericAnimationBehavior(element);
    
    this._shownHandler = null;
    this._hiddenHandler = null;
    this._modalPopupBehaviorID = null;
    this._modalPopupBehavior = null;
}
WM.WebControls.AJAX.ModalPopupAnimationExtender.ModalPopupAnimationBehavior.prototype = {    
    initialize : function() {
        WM.WebControls.AJAX.ModalPopupAnimationExtender.ModalPopupAnimationBehavior.callBaseMethod(this, 'initialize');
        
        // Initialize the generic animation behaviors
        this._shown.initialize();
        this._hidden.initialize();

        //  fetch the component
        this._modalPopupBehavior = $find(this.get_ModalPopupBehaviorID());

        //  create and attach the onShown handler
        this._shownHandler = Function.createDelegate(this, this._onShown);
        this._modalPopupBehavior.add_shown(this._shownHandler);

        //  create and attach the onHidden handler
        this._hiddenHandler = Function.createDelegate(this, this._onHidden);
        this._modalPopupBehavior.add_hidden(this._hiddenHandler);        
    },
    
    dispose : function() {
        //  detach events
        this._modalPopupBehavior.remove_shown(this._shownHandler);
        this._modalPopupBehavior.remove_hidden(this._hiddenHandler);
        
        this._shownHandler = null;
        this._hiddenHandler = null;
        
        WM.WebControls.AJAX.ModalPopupAnimationExtender.ModalPopupAnimationBehavior.callBaseMethod(this, 'dispose');
    },
    
    _onShown : function(sender, args) {
        this._hidden.quit();
        this._shown.play();
    },
    
    _onHidden : function(sender, args) {
        this._shown.quit();
        this._hidden.play();
    },    
    
    get_ModalPopupBehaviorID : function() {
        return this._modalPopupBehaviorID;
    },
    
    set_ModalPopupBehaviorID : function(value) {
        this._modalPopupBehaviorID = value;
    },

    get_OnShown : function() {
        return this._shown.get_json();
    },
    
    set_OnShown : function(value) {
        this._shown.set_json(value);
        this.raisePropertyChanged('OnShown');
    },
    
    get_OnShownBehavior : function() {
        return this._shown;
    },
    
    get_OnHidden : function() {
        return this._hidden.get_json();
    },
    
    set_OnHidden : function(value) {
        this._hidden.set_json(value);
        this.raisePropertyChanged('OnHidden');
    },
    
    get_OnHiddenBehavior : function() {
        return this._hidden;
    }    
}
WM.WebControls.AJAX.ModalPopupAnimationExtender.ModalPopupAnimationBehavior.registerClass('WM.WebControls.AJAX.ModalPopupAnimationExtender.ModalPopupAnimationBehavior', AjaxControlToolkit.BehaviorBase);

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();