/**
 * This decoratot adds buttons to your window.
 * 
 * Example:
 *   var win = new NetronautUI_Window();
 *   new NetronautUI_WindowDecorator(win, {'closeButton':{events:{'click':win.close.bind(win)}}});
 * 
 * ----
 * 
 * LICENCE
 * 
 * This work is licensed under Creative Commons Attribution-Share Alike 3.0 (Germany).
 * For details on this licence visit http://creativecommons.org/licenses/by-sa/3.0/de/
 * 
 * All rights reserved
 * 
 * @author Jakob Hohlfeld | http://www.netronaut.de
 * @copyright 2010 by Jakob Hohlfeld
 * 
 */
var NetronautUI_WindowDecorator = new Class
({
	Extends: NetronautUI_Widget,
	
	initialize: function ( el, options ) {
		this.parent(el, options);
		this.dom.object.addEvent('open', this.open.bind(this));
		this.dom.object.addEvent('close', this.close.bind(this));
	},
	
	render: function () {
		this.dom.el.addClass('netronautui-windowdecorator');
		if(this.options.closeButton) {
			var options = this.options.closeButton;
			options.offset = options.offset||{x:0,y:0}
			var closeButton = new Element('button', {
				'class':'close',
				'events':this.options.closeButton.events,
				'styles':{'position':'relative'}
			}).inject(this.dom.container);
			var placeButton = function(){
				closeButton.setStyles({
					'left': this.getSize().x-parseInt(closeButton.getStyle('width'))/2+options.offset.x,
					'top': -(this.getSize().y-parseInt(closeButton.getStyle('height'))/2)+options.offset.y
				});
			}.bind(this.dom.object);
			this.dom.object.addEvent('open', placeButton);
			this.dom.object.addEvent('resize', placeButton);
		}
	}
})
