function Window(title)
{
	this.title = title;
	extend(this, Container);
	
	this.setMinimumSize({width:100, height:100});
}

Window.prototype = new Container;

// public String getWidgetName();
Window.prototype.getWidgetName = function()
{
	return "window";
};

// protected void initialize();
Window.prototype.initialize = function()
{
	this.titlebar		= new Titlebar();
	this.clientPane		= new Container();
	this.contentPane	= new Container();
	this.menuBar		= null;
	
	this.setUpdateSuspended(true);
	
	Widget.prototype.initialize.apply(this);
	
	if(!this.contentPaneInsets)
	{
		this.setContentPaneInsets({top:0, right:0, bottom:0, left:0});
	}

	this.clientPane.add(this.contentPane);
	
	this.add(this.titlebar);
	this.add(this.clientPane);
	
	this.setUpdateSuspended(false);
};

// public String getTitle();
Window.prototype.getTitle = function()
{
	return this.title;
};

// public void setContentPaneInsets({top:int, right:int, bottom:int, left:int});
Window.prototype.setContentPaneInsets = function(insets)
{
	this.contentPaneInsets = insets;
	
	if(!this.updateSuspended)
	{
		this.update();
	}
};

// public {top:int, right:int, bottom:int, left:int} getContentPaneInsets();
Window.prototype.getContentPaneInsets = function()
{
    return this.contentPaneInsets;
};

// public void doLayout();
Window.prototype.update = function()
{
	var width = this.getWidth(), height = this.getHeight(), offset = 0;
	
	this.titlebar.setBounds(0, 0, width, this.titlebar.getPreferredSize().height);
	offset += this.titlebar.getHeight();

	this.clientPane.setBounds(0, offset, width, this.getHeight() - offset);
	
	with(this.contentPaneInsets)
	{
		offset = top;
		
		if(this.menubar)
		{
			this.menubar.setBounds(left, offset, this.clientPane.getWidth() - left - right, this.menubar.getPreferredSize().height);
			offset += this.menubar.getHeight();
		}
		
		height -= offset;
		this.contentPane.setBounds(left, offset, width - left - right, height - top - bottom);
	}
};

/* Window.prototype.getPreferredSize = function()
{
	var preferredSize = this.titlebar.getPreferredSize();
	var clientSize = this.clientPane.getPreferredSize();
	
	preferredSize.width = Math.max(preferredSize.width, clientSize.width);
	preferredSize.height += clientSize.height;
	
	return preferredSize;
} */

// public Container getClientPane();
Window.prototype.getClientPane = function()
{
	return this.clientPane;
};

// public Container getContentPane();
Window.prototype.getContentPane = function()
{
	return this.contentPane;
};

// public Titlebar getTitlebar();
Window.prototype.getTitlebar = function()
{
	return this.titlebar;
};

// public void setMenubar(Menubar menubar);
Window.prototype.setMenubar = function(menubar)
{
	this.setUpdateSuspended(true);
	
	if(this.menubar)
	{
		this.remove(this.menubar);
	}
	
	this.menubar = menubar;
	
	if(this.menubar)
	{
		this.clientPane.add(this.menubar);
	}
	
	this.setUpdateSuspended(false);
	this.update();
}

