var sWin = new Class({

	Implements: [Events, Options],

	options: {
		/*onShow: Class.empty,
		onHide: Class.empty,
		onClose: Class.empty,
		*/
		title: '',
		status: '',
		size:{
			width: 400,
			height: 0,
			left: 0,
			top: 0
		},
		klass: 'window',
		draggable: false,
		overlay: false
	},

	initialize: function(options){
		this.setOptions(options);
		this.open = false;
		if(this.options.overlay){this.overlay = new Element('div',{'class':'overlay hidden'}).setOpacity(0.5).inject(document.body);}
		this.window = new Element('div',{'class':this.options.klass}).setStyle('visibility','hidden').inject(document.body);
		this.title = new Element('div',{'class':'title'}).setHTML('<b>'+this.options.title+'</b>').inject(this.window);
		this.content = new Element('div',{'class':'content'}).inject(this.window);
		this.status = new Element('div',{'class':'status'}).setHTML('<em>'+this.options.status+'</em>').inject(this.window);
		this.close = new Element('span',{'class':'close','title':'Cerrar'}).addEvent('click',this.hide.bind(this)).inject(this.title);
		if(this.options.draggable) this.window.makeDraggable($merge({handle:this.title.addClass('draggable')},this.options.draggable));
		//
		if(this.options.size.width>0) this.window.setStyle('width',this.options.size.width+'px');
		if(this.options.size.height>0) this.content.setStyle('height',this.options.size.height+'px');
	},

	setTitle: function(title){
		this.title.getFirst().innerHTML = title;
		return this;
	},

	setContent: function(content){
		this.content.innerHTML = content;
		return this;
	},

	setStatus: function(status){
		this.status.innerHTML = '<em>'+status+'</em>';
		return this;
	},

	getContent: function(){
		return this.content.innerHTML;
	},

	show: function(){
		this.open = true;
		this.window.setStyles({'width':this.options.size.width+'px','left':this.options.size.left+'px','top':this.options.size.top+'px','visibility':'visible'});
		if(this.overlay){
			var overlay = this.options.overlay.getCoordinates();
			this.overlay.setStyles({'z-index':21,'width':overlay.width+'px','height':overlay.height+'px','left':overlay.left+'px','top':overlay.top+'px'});
			this.overlay.removeClass('hidden');
		}
		this.fireEvent('onShow');
		return this;
	},

	hide: function(){
		this.open = false;
		this.window.setStyle('visibility','hidden');
		if(this.overlay) this.overlay.addClass('hidden')
		this.fireEvent('onHide');
		return this;
	},

	toggle: function(){
		if(this.open){
			this.hide();
		}else{
			this.show();
		}
	},

	close: function(){
		this.window.remove();
		if(this.overlay) this.overlay.remove()
		this.fireEvent('onClose');
		return this;
	}
});