Window = Class.create();
Object.extend(Window.prototype, WebControl.prototype);

Object.extend(Window.prototype,
    {
        initialize : function(config)
        {
            WebControl.prototype.initialize.call(this, config);
            var thisClass = this;
            
            // Show
            this.config.Show = function()
            {
                $(thisClass.config.container).update("");
                
                // HEADER
                var windowHeader = new Element("div");
                windowHeader.addClassName("windowHeader");
                
                var title = new Element("h1");
                title.update(thisClass.config.title);
                windowHeader.insert(title);
                
                // CLOSE LINK
                var link = new Element("a");
                link.id = link.identify();
                link.href = "close";
                
                var close = new Element("img");
                close.src = "Themes/DefaultImages/windowClose.png";
                close.title = "bezárás";
                
                link.insert(close);
                thisClass.config.closeLink = link;
                windowHeader.insert(link);
                
                // CONTENT
                var windowContent = new Element("div");
                windowContent.addClassName("windowContent");
                windowContent.id = "windowContent";
                windowContent.update(thisClass.config.content);
                
                // FOOTER
                var windowFooter = new Element("div");
                windowFooter.addClassName("windowFooter");
                
                $(thisClass.config.container).insert(windowHeader);
                $(thisClass.config.container).insert(windowContent);
                $(thisClass.config.container).insert(windowFooter);
                
                if(thisClass.config.contentURL != null)
                {
                    new Ajax.Updater( "windowContent", thisClass.config.contentURL, { parameters: thisClass.config.parameters, asynchronous : false });
                }
                
                if(thisClass.config.width != null)
                {
                    $(thisClass.config.container).setStyle({width: thisClass.config.width + "px" });
                }
                
                thisClass.AfterShow();
                
                Utils.CenterScreen($(thisClass.config.container));
                
                $(thisClass.config.container).setStyle({display: 'block'});
                
                //thisClass.WindowDrag = new Draggable(thisClass.config.container);
            };
            
            // Add Events
            this.config.AddEvents = function() {
                Event.observe(thisClass.config.closeLink.identify(), 'click', thisClass.CloseClick.bindAsEventListener(thisClass));
                Event.observe(thisClass.config.container, "keypress", thisClass.KeyPressed.bindAsEventListener(thisClass));
            };
        },
        
        //WindowDrag : null,
        
        CloseClick : function(event)
        {
            Event.stop(event);
            this.Close();
        },
            
        Close : function()
        {
            //this.WindowDrag.destroy();
            $(this.config.container).update("");
            $(this.config.container).setStyle({display: 'none'});
        },
        
        SetContent : function(element)
        {
            this.config.content = element;
        },
        
        GetWidth : function()
        {
            return this.config.width;
        },
        
        AfterShow : function () {},
        
        KeyPressed : function(event)
        {
            switch(event.keyCode)
            {
                case 27 :
                    this.Close();
                    break;
            }
        }
    }
);

