﻿Type.registerNamespace("Alumni.Web.UI");

Alumni.Web.UI.ModalWindow = function(element)
{
    this._pin = null;
    this._close = null;
    this._allowDrag = null;
    this._dragHandle = null;
    this._panel = null;
    this._skinPath = null;
    this._skin = null;
    this._appPath = null;
    this._controlId = null;
    this._behaviorId = null;
    
    this._pinMouseOverHandler = null;
    this._pinMouseOutHandler = null;
    this._pinClickHandler = null;
    this._closeMouseOverHandler = null;
    this._closeMouseOutHandler = null;
    this._closeClickHandler = null;
    
    Alumni.Web.UI.ModalWindow.initializeBase(this, [element]);
}

Alumni.Web.UI.ModalWindow.prototype =
{
    get_close : function()
    {
        return this._close;
    },
    set_close : function(value)
    {
        if (this._close != value)
        {
            this._close = value;
            this.raisePropertyChanged("close");
        }
    },
    
    get_pin : function()
    {
        return this._pin;
    },
    set_pin : function(value)
    {
        if (this._pin != value)
        {
            this._pin = value;
            this.raisePropertyChanged("pin");
        }
    },
    
    get_allowDrag : function()
    {
        return this._allowDrag;
    },
    set_allowDrag : function(value)
    {
        if (this._allowDrag != value)
        {
            this._allowDrag = value;
            this.raisePropertyChanged("allowDrag");
        }
    },
    
    get_dragHandle : function()
    {
        return this._dragHandle;
    },
    set_dragHandle : function(value)
    {
        if (this._dragHandle != value)
        {
            this._dragHandle = value;
            this.raisePropertyChanged("dragHandle");
        }
    },
    
    get_panel : function()
    {
        return this._panel;
    },
    set_panel : function(value)
    {
        if (this._panel != value)
        {
            this._panel = value;
            this.raisePropertyChanged("panel");
        }
    },
    
    get_skinPath : function()
    {
        return this._skinPath;
    },
    set_skinPath : function(value)
    {
        if (this._skinPath != value)
        {
            this._skinPath = value;
            this.raisePropertyChanged("skinPath");
        }
    },
    
    get_skin : function()
    {
        return this._skin;
    },
    set_skin : function(value)
    {
        if (this._skin != value)
        {
            this._skin = value;
            this.raisePropertyChanged("skin");
        }
    },
    
    get_appPath : function()
    {
        return this._appPath;
    },
    set_appPath : function(value)
    {
        if (this._appPath != value)
        {
            this._appPath = value;
            this.raisePropertyChanged("appPath");
        }
    },
    
    get_controlId : function()
    {
        return this._controlId;
    },
    set_controlId : function(value)
    {
        if (this._controlId != value)
        {
            this._controlId = value;
            this.raisePropertyChanged("controlId");
        }
    },
    
    get_behaviorId : function()
    {
        return this._controlId;
    },
    set_behaviorId : function(value)
    {
        if (this._behaviorId != value)
        {
            this._behaviorId = value;
            this.raisePropertyChanged("behaviorId");
        }
    },
    
    initialize : function()
    {
        Alumni.Web.UI.ModalWindow.callBaseMethod(this, "initialize");
        
        var pinImage = $get(this._pin);
        var closeImage = $get(this._close);
        
        closeImage.src = this._appPath + "/" + this._skinPath + this._skin + "/modalwindow/closebutton.png";  
        
        if (this._allowDrag) { pinImage.src = this._appPath + "/" + this._skinPath + this._skin + "/modalwindow/unpinbutton.png"; }
        else { pinImage.src = this._appPath + "/" + this._skinPath + this._skin + "/modalwindow/pinbutton.png"; }
        
        this._pinMouseOverHandler = Function.createDelegate(this, this._pinOnMouseOver);
        this._pinMouseOutHandler = Function.createDelegate(this, this._pinOnMouseOut);
        this._pinClickHandler = Function.createDelegate(this, this._pinOnClick);
        this._closeMouseOverHandler = Function.createDelegate(this, this._closeOnMouseOver);
        this._closeMouseOutHandler = Function.createDelegate(this, this._closeOnMouseOut);
        this._closeClickHandler = Function.createDelegate(this, this._closeOnClick);
        
        $addHandlers(pinImage, {"mouseover" : this._pinMouseOverHandler, "mouseout" : this._pinMouseOutHandler, "click" : this._pinClickHandler}, this);
        $addHandlers(closeImage, {"mouseover" : this._closeMouseOverHandler, "mouseout" : this._closeMouseOutHandler, "click" : this._closeClickHandler}, this);
    },
    
    dispose : function()
    {
        $clearHandlers(this.get_element());
        
        delete this._pinOnMouseOver;
        delete this._pinOnMouseOut;
        delete this._pinOnClick;
        delete this._closeClick;
        
        Alumni.Web.UI.ModalWindow.callBaseMethod(this, "dispose");
    },
    
    _pinOnMouseOver : function()
    {
        var pin = $get(this._pin);
        
        if (this._allowDrag)
        {
            pin.src = this._appPath + "/" + this._skinPath + this._skin + "/modalwindow/unpinbutton_over.png";
        }
        else
        {
            pin.src = this._appPath + "/" + this._skinPath + this._skin + "/modalwindow/pinbutton_over.png";
        }
    },
    
    _pinOnMouseOut : function()
    {
        var pin = $get(this._pin);
        
        if (this._allowDrag)
        {
            pin.src = this._appPath + "/" + this._skinPath + this._skin + "/modalwindow/unpinbutton.png";
        }
        else
        {
            pin.src = this._appPath + "/" + this._skinPath + this._skin + "/modalwindow/pinbutton.png";
        }      
    },

    _pinOnClick : function()
    {
        var pin = $get(this._pin);
        
        if (this._allowDrag == false)
        {
            this._allowDrag = true;
            
            $create(AjaxControlToolkit.FloatingBehavior, {"handle" : $get(this._dragHandle), "id" : "ModalWindowDragHandle_" + this._controlId}, null, null, $get(this._panel));
            pin.src = this._appPath + "/" + this._skinPath + this._skin + "/modalwindow/unpinbutton_over.png";
        }
        else
        {
             this._allowDrag = false;
             
            var drag = $find("ModalWindowDragHandle_" + this._controlId);
            
            drag.dispose();
            pin.src = this._appPath + "/" + this._skinPath + this._skin + "/modalwindow/pinbutton_over.png";
        }
    },
    
     _closeOnMouseOver : function()
    {
        var close = $get(this._close);
        close.src = this._appPath + "/" + this._skinPath + this._skin + "/modalwindow/closebutton_over.png";
    },
    
    _closeOnMouseOut : function()
    {
        var close = $get(this._close);
        close.src = this._appPath + "/" + this._skinPath + this._skin + "/modalwindow/closebutton.png";   
    },
    
    _closeOnClick : function()
    {
        var modal = $find(this._behaviorId);
        modal.hide();
    }
}

Alumni.Web.UI.ModalWindow.registerClass("Alumni.Web.UI.ModalWindow", Sys.UI.Control);

if (typeof (Sys) != "undefined") { Sys.Application.notifyScriptLoaded(); }