Ext.ux.DemonWindow = Ext.extend(Ext.Window, {

    closable: true,

    initComponent : function() {
		this.spotlight = new Ext.DemonSpotlight({duration:0.3});
        var defConfig = {};

        Ext.applyIf(this,defConfig);
        Ext.ux.DemonWindow.superclass.initComponent.call(this);

    },
	
    afterRender : function(){
        Ext.ux.DemonWindow.superclass.afterRender.call(this);
        this.addListeners();

    },
	
    addListeners : function() {
        this.on('move', function(window,x,y) {
            var width = Ext.getBody().getWidth()
            var height = Ext.getBody().getHeight()
            var headerHeight = window.header.getHeight()
            var headerWidth = window.header.getTextWidth() + 20
            var box = window.getBox(true)
            var update = false
            if( box.x < 0 ){
                box.x = 0;
                update = true;
            }
            else if( box.x + headerWidth > width ){
                box.x = width - headerWidth;
                update = true;
            }
            if( box.y < 0 ){
                box.y = 0;
                update = true;
            }
            else if( box.y + headerHeight > height ){
                box.y = height - headerHeight;
                update = true;
            }
            if( update ) {
                window.updateBox( box );
			}	
        });
    }
	
});

Ext.reg('DemonWindow', Ext.ux.DemonWindow);
