//	ZWindow - class for Z Desktop Windows

var ZWindow = Class.create();

ZWindow.prototype = 
{
	panelControl: new TopPanelController([]),
	
	initialize: function (window_id, windowpane_id) 
	{
		this.options = arguments[2] || {};
		this.window_id = window_id;
		this.windowpane_id = windowpane_id;
		this.autohide = this.options.autohide || false;
	
		this._initWindowBar();
		this._initCloseWidget();
		this._initShadeWidget();
		
		this.panelControl.addPanel(this.window_id);
		if (this.options.promote)
		{
			this.panelControl.promotePanel(this.window_id);
		}
		
		if (this.autohide)
		{
			Element.hide(this.window_id);
		}
	},
	
	_initWindowBar: function ()
	{
		this.hbar = (document.getElementsByClassName('handlebar', 
			this.window_id))[0];
		this.draggable = new Draggable(this.window_id, {handle: this.hbar});
	},
	
	_initCloseWidget: function ()
	{
		var closeWidget = ((document.getElementsByClassName('close', 
			this.hbar))[0]).parentNode;
		Event.observe(closeWidget, 'mousedown', 
			this.closeWindow.bind(this), false);
	},
	
	_initShadeWidget: function ()
	{
		var shadeWidget = ((document.getElementsByClassName('shade', 
			this.hbar))[0]).parentNode;
		
		this.shadeToggle = new Toggler(shadeWidget.id, 
			(function () { Effect.SlideUp($(this.windowpane_id), 
				{queue: 'end'}); }).bind(this),
			(function () { Effect.SlideDown($(this.windowpane_id), 
				{queue: 'end'}); }).bind(this),
			{invert: true});
	},
	
	setOptions: function (options)
	{
		Object.extend(this.options, options);
	},
		
	openWindow: function ()
	{
		Effect.Appear(this.window_id, {duration: 0.5, queue: 'front'});
	},
	
	closeWindow: function ()
	{
		Effect.Fade(this.window_id, {duration: 0.5, queue: 'end'});
	}
}