﻿/// <reference name="MicrosoftAjax.debug.js" />
/// <reference name="MicrosoftAjaxWebForms.debug.js" />
/// <reference path="../ExtenderBase/BaseScripts.js" />
/// <reference path="../Common/Common.js" />

(function () {
    var scriptName = "RoundedPanel";

    function execute() {

        Type.registerNamespace('Movielocker.Web.Controls');

        Movielocker.Web.Controls.RoundedPanelBehavior = function (element) {
            /// <summary>
            /// The RoundedPanelBehavior applies a rounded corners to a textbox
            /// </summary>
            /// <param name="element" type="Sys.UI.DomElement" domElement="true">
            /// Textbox associated with the behavior
            /// </param>
            Movielocker.Web.Controls.RoundedPanelBehavior.initializeBase(this, [element]);

            // Properties
            this._leftImageUrl = null;
            this._topImageUrl = null;
            this._rightImageUrl = null;
            this._bottomImageUrl = null;
            this._centerImageUrl = null;
            this._className = '';
            this._hasGrip = false;

            this._targetClassName = null;
            this._divContainer = null;

        }
        Movielocker.Web.Controls.RoundedPanelBehavior.prototype = {
            initialize: function () {
                /// <summary>
                /// Initialize the behavior
                /// </summary>
                Movielocker.Web.Controls.RoundedPanelBehavior.callBaseMethod(this, 'initialize');

                var e = this.get_element();

                this._targetClassName = e.className;

                //Create a new parent for TextBox
                this._divContainer = document.createElement('DIV');
                if (this._className) this._divContainer.className = this._className;
                else if (this._targetClassName)
                    this._divContainer.className = this._targetClassName + '_rp';
                else
                    this._divContainer.className = 'rp';
                e.parentNode.insertBefore(this._divContainer, e);

                var _divLT = document.createElement('DIV');
                _divLT.className = 'rp_lt';
                this._divContainer.appendChild(_divLT);
                var _divRT = document.createElement('DIV');
                _divRT.className = 'rp_rt';
                _divLT.appendChild(_divRT);
                var _divCT = document.createElement('DIV');
                _divCT.className = 'rp_ct';
                _divRT.appendChild(_divCT);
                if (this._topImageUrl) {
                    var _topImg = document.createElement('IMG');
                    _topImg.src = this._topImageUrl;
                    _divCT.appendChild(_topImg);
                }
                //var _divCTi = document.createElement('DIV');
                //_divCTi.style.height = '0px';
                //_divCT.appendChild(_divCTi);

                var _divLC = document.createElement('DIV');
                _divLC.className = 'rp_lc';
                this._divContainer.appendChild(_divLC);
                if (this._leftImageUrl) {
                    var _leftImg = document.createElement('IMG');
                    _leftImg.src = this._leftImageUrl;
                    _divLC.appendChild(_leftImg);
                }
                var _divRC = document.createElement('DIV');
                _divRC.className = 'rp_rc';
                _divLC.appendChild(_divRC);
                if (this._rightImageUrl) {
                    var _rightImg = document.createElement('IMG');
                    _rightImg.src = this._rightImageUrl;
                    _divRC.appendChild(_rightImg);
                }
                var _divCC = document.createElement('DIV');
                _divCC.className = 'rp_cc';
                //_divCC.style.position = 'relative';
                _divRC.appendChild(_divCC);
                if (this._centerImageUrl) {
                    var _centerImg = document.createElement('IMG');
                    _centerImg.src = this._centerImageUrl;
                    _divCC.appendChild(_centerImg);
                }
                if (this._hasGrip) {
                    var _gripPanel = document.createElement('DIV');
                    _gripPanel.className = 'rp_grip';
                    _gripPanel.style.position = 'absolute';
                    _gripPanel.style.left = '100%';
                    _divCC.appendChild(_gripPanel);
                }
                e.parentNode.removeChild(e);
                _divCC.appendChild(e);

                var _divLB = document.createElement('DIV');
                _divLB.className = 'rp_lb';
                this._divContainer.appendChild(_divLB);
                var _divRB = document.createElement('DIV');
                _divRB.className = 'rp_rb';
                _divLB.appendChild(_divRB);
                var _divCB = document.createElement('DIV');
                _divCB.className = 'rp_cb';
                _divRB.appendChild(_divCB);
                if (this._bottomImageUrl) {
                    var _bottomImg = document.createElement('IMG');
                    _bottomImg.src = this._bottomImageUrl;
                    _divCB.appendChild(_bottomImg);
                }
                //var _divCBi = document.createElement('DIV');
                //_divCBi.style.height = '0px';
                //_divCB.appendChild(_divCBi);
            },

            dispose: function () {
                /// <summary>
                /// Dispose the behavior
                /// </summary>
                var e = this.get_element();

                Movielocker.Web.Controls.RoundedPanelBehavior.callBaseMethod(this, 'dispose');
            },

            get_LeftImageUrl: function () {
                return this._leftImageUrl;
            },
            set_LeftImageUrl: function (value) {
                this._leftImageUrl = value;
            },

            get_TopImageUrl: function () {
                return this._topImageUrl;
            },
            set_TopImageUrl: function (value) {
                this._topImageUrl = value;
            },

            get_RightImageUrl: function () {
                return this._rightImageUrl;
            },
            set_RightImageUrl: function (value) {
                this._rightImageUrl = value;
            },

            get_BottomImageUrl: function () {
                return this._bottomImageUrl;
            },
            set_BottomImageUrl: function (value) {
                this._bottomImageUrl = value;
            },

            get_CenterImageUrl: function () {
                return this._centerImageUrl;
            },
            set_CenterImageUrl: function (value) {
                this._centerImageUrl = value;
            },

            get_CssClass: function () {
                return this._className;
            },
            set_CssClass: function (value) {
                this._className = value;
            },

            get_HasGrip: function () {
                return this._hasGrip;
            },
            set_HasGrip: function (value) {
                this._hasGrip = value;
            }
        }

        Movielocker.Web.Controls.RoundedPanelBehavior.registerClass('Movielocker.Web.Controls.RoundedPanelBehavior', Sys.Extended.UI.BehaviorBase);

    } // execute

    if (window.Sys && Sys.loader) {
        Sys.loader.registerScript(scriptName, ["ExtendedBase", "ExtendedCommon"], execute);
    }
    else {
        execute();
    }

})();

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();