﻿/// <reference name="MicrosoftAjax.js"/>
Type.registerNamespace("aorta.playmeweb.webcontrols");

aorta.playmeweb.webcontrols.ControlePanels = function() {
    aorta.playmeweb.webcontrols.ControlePanels.initializeBase(this);

    this._controls = null;
    this._showHideDelegate = null;
    this._lockBackground = false;
    this._lockElement = null;
    this._cssClass = null;
}

aorta.playmeweb.webcontrols.ControlePanels.prototype = {
    initialize: function() {
        aorta.playmeweb.webcontrols.ControlePanels.callBaseMethod(this, 'initialize');

        //Cria os handler para os eventos dos controles
        this._showHideDelegate = Function.createDelegate(this, this._showHideHandler);
        var controles = this.get_controls();
        for(i=0; i<controles.length; i++){
            //Eventos para os gatilhos
            var eventArgShow = new aorta.playmeweb.webcontrols.ControlShowEventArgs();
            eventArgShow.set_control($get(controles[i].Panel));
            var c = $get(controles[i].Gatilho);
            if(c) $addHandler(c, 'click', Function.createCallback(this._showHideDelegate, eventArgShow));
            //Eventos para os botões de fechar
            var eventArgHide = new aorta.playmeweb.webcontrols.ControlShowEventArgs();
            eventArgHide.set_control($get(controles[i].Panel));
            eventArgHide.set_visible(false);
            c = $get(controles[i].BotaoFechar);
            if(c) $addHandler(c, 'click', Function.createCallback(this._showHideDelegate, eventArgHide));
        }

        //Cria a div para trancar o fundo quando o panel estiver visível
        if(this._lockBackground){
            this._lockElement = document.createElement("div");

            if(this.get_cssClass()){
                this._lockElement.className = this.get_cssClass();
            }else{
                this._lockElement.style.backgroundColor = 'black';
                //Opacity para safari e mozilla
                this._lockElement.style.opacity = 0.6;
                //filter para IE
                this._lockElement.style.filter = 'alpha(opacity=60)';
            }

            this._lockElement.style.zIndex = '999';
            this._lockElement.style.display = 'none';
            this._lockElement.style.width = '100%';
            this._lockElement.style.height = '100%';
            this._lockElement.style.position = 'absolute';
            this._lockElement.style.left = '0px';
            this._lockElement.style.top = '0px';
            document.body.appendChild(this._lockElement);
        }
    },

    _showHideHandler: function(sender, args){
        var controles = this.get_controls();
        for(i=0; i<controles.length; i++){
            var c = $get(controles[i].Panel);
            if(c) c.style.display = 'none';
        }

        if(args.get_control()){
            args.get_control().style.position = 'relative';
            args.get_control().style.zIndex = '1000';
            args.get_control().style.display = args.get_visible() ? 'block' : 'none';

            if(this._lockBackground == true && this._lockElement != null)
                this._lockElement.style.display = args.get_control().style.display;
        }
    },

    dispose: function() {
        aorta.playmeweb.webcontrols.ControlePanels.callBaseMethod(this, 'dispose');
    },

    get_controls : function(){
        /// <value type="Object" locid="P:J#aorta.playmeweb.webcontrols.ControlePanels.controls"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._controls;
    },
    set_controls : function(value){
        var e = Function._validateParams(arguments, [{name: "value", type: Object}]);
        if (e) throw e;
        this._controls = value;
    },

    get_lockBackground : function(){
        /// <value type="Boolean" locid="P:J#aorta.playmeweb.webcontrols.ControlePanels.lockBackground"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._lockBackground;
    },
    set_lockBackground : function(value){
        var e = Function._validateParams(arguments, [{name: "value", type: Boolean}]);
        if (e) throw e;
        this._lockBackground = value;
    },

    get_cssClass : function(){
        /// <value type="String" locid="P:J#aorta.playmeweb.webcontrols.ControlePanels.cssClass"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._cssClass;
    },
    set_cssClass : function(value){
        var e = Function._validateParams(arguments, [{name: "value", mayBeNull: true}]);
        if (e) throw e;
        this._cssClass = value;
    }
}

aorta.playmeweb.webcontrols.ControlePanels.registerClass('aorta.playmeweb.webcontrols.ControlePanels', Sys.Component);

aorta.playmeweb.webcontrols.ControlShowEventArgs = function() {
    /// <summary locid="M:J#aorta.playmeweb.webcontrols.ControlShowEventArgs.#ctor" />
    if (arguments.length !== 0) throw Error.parameterCount();
    aorta.playmeweb.webcontrols.ControlShowEventArgs.initializeBase(this);

    this._control = null;
    this._visible = true;
}

aorta.playmeweb.webcontrols.ControlShowEventArgs.prototype = {
    get_control: function() {
        /// <value type="Boolean" locid="P:J#aorta.playmeweb.webcontrols.ControlShowEventArgs.control"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._control;
    },
    set_control: function(value) {
        var e = Function._validateParams(arguments, [{name: "value", type: Object}]);
        if (e) throw e;
        this._control = value;
    },

    get_visible: function() {
        /// <value type="Boolean" locid="P:J#aorta.playmeweb.webcontrols.ControlShowEventArgs.visible"></value>
        if (arguments.length !== 0) throw Error.parameterCount();
        return this._visible;
    },
    set_visible: function(value) {
        var e = Function._validateParams(arguments, [{name: "value", type: Boolean}]);
        if (e) throw e;
        this._visible = value;
    }
}

aorta.playmeweb.webcontrols.ControlShowEventArgs.registerClass('aorta.playmeweb.webcontrols.ControlShowEventArgs', Sys.EventArgs);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();