Ext.ux.PanelBlind = Ext.extend(Ext.Panel, {

	
	
    constructor: function(config) {
        config = Ext.apply({
            floating: true,
            cls: 'x-blind',
            bodyStyle: {
                'border-width': '0px',
				'padding':'8px',
				'overflow':'auto'
            }
        }, config);
        Ext.ux.PanelBlind.superclass.constructor.call(this, config);
		
	 
    },

    init: function(client) {
        this.client = client;
	 
        if (!this.client.blinds) {
            this.client.blinds = new Ext.util.MixedCollection();
        }
        client.blinds.add(this);
        this.client.constructor.prototype.showBlind = this.clientShowBlind;
        this.client.constructor.prototype.dismissBlind = this.clientDismissBlind;
		 
        this.client.on({
            destroy: this.destroy,
            resize: this.syncSizeWithClient,
            scope: this
        });
    },

    syncSizeWithClient: function() {
		this.setWidth(this.client.body.getSize(true).width+16);
		this.setHeight(this.client.body.getSize(true).height+16);
		//sync the grids width with the blind
	 
		//this.items.items[0].syncSize();
	 
    },

    clientShowBlind: function(id) {
        var b = this.blinds.get(id);
        if (b) {
            b.show();
			
        }
    },

    clientDismissBlind: function(id) {
        var b = this.blinds.get(id);
        if (b) {
            b.dismiss();
	
        }
    },

 
    
    show: function() {
 		 
        var mask = this.client.getEl().mask();
		
        if (!this.rendered) {
            this.render(this.client.getEl());
        }

//		Synchronize this blind's z-index to be one above the client Element's mask
       	this.el.setZIndex(Number(mask.getStyle('z-index')) + 1);        	

        this.el.disableShadow();
        this.syncSizeWithClient();
        this.el.alignTo(this.client.body, 'bl-bl');
        this.el.slideIn('b', {
            callback: function() {
                this.el.visible = true; // Ext bug. Flag not set causes enableShadow to fail.
                this.el.enableShadow(true);
            },
            scope: this
        });
 
	 
    },

    dismiss: function() {
 
	 
        if (this.destroyOnDismiss) {
            this.destroy();
            delete this.client.blinds[this.id];
        } else {
            this.el.disableShadow();
            this.el.slideOut('b');
            this.client.getEl().unmask();
        }
		 
    }

});