var sWin = new Class({

	Implements: [Options],

	options: {
		title: '',
		width: 360,
		height: 0,
		klass: 'window',
		draggable: false,
		overlay: false,
		opacity: 0.5,
		noSelects: true
	},

	initialize: function(options){
		this.open = false;
		this.setOptions(options);

		this.overlay = this.options.overlay ? new Element('div',{'class':'overlay hidden'}).setStyle('z-index',21).setOpacity(this.options.opacity).inject(document.body) : false;
		this.container = new Element('div',{'class':this.options.klass+' hidden'}).setStyle('z-index',22).inject(document.body);
		this.title = new Element('div',{'class':'title'}).set('html','<b>'+this.options.title+'</b>').inject(this.container);
		this.content = new Element('div',{'class':'content'}).inject(this.container);
		this.status = new Element('div',{'class':'status'}).inject(this.container);
		this.bclose = new Element('span',{'class':'close','title':'Cerrar'}).addEvent('click',this.close.bind(this)).inject(this.title);

		if(this.options.draggable) this.container.makeDraggable($merge({handle:this.title.addClass('draggable')},this.options.draggable));
		if(this.options.width>0) this.container.setStyle('width',this.options.width+'px');
		if(this.options.height>0) this.content.setStyle('height',this.options.height+'px');
	},

	setTitle: function(title,klass){
		var btitle = this.title.getFirst();
		if(klass){
			btitle.className = klass;
		}
		btitle.innerHTML = title;
		return this;
	},

	setContent: function(content){
		if(typeof content == 'string'){
			this.content.innerHTML = content;
		}else{
			this.content.adopt(content);
		}
		return this;
	},

	setPosition: function(x,y){
		this.container.setStyles({'left':x+'px','top':y+'px'});
		window.scroll(0,y-100);
		return this;
	},

	show: function(){
		this.open = true;
		this.container.removeClass('hidden');
		if(this.overlay){
			if(this.options.noSelects){
				noSelects(true);
			}
			var overlay = this.options.overlay.getCoordinates();
			var height = Browser.Engine.trident4 ? overlay.height+document.body.scrollTop : overlay.height;
			this.overlay.setStyles({'width':overlay.width+'px','height':height+'px','left':overlay.left+'px','top':overlay.top+'px'});
			this.overlay.removeClass('hidden');
		}
		return this;
	},

	close: function(){
		this.open = false;
		this.container.addClass('hidden');
		if(this.options.noSelects){
			noSelects(false);
		}
		if(this.overlay){
			this.overlay.addClass('hidden');
		}
		if(this.onClose){
			this.onClose();
		}
	},

	toggle: function(){
		if(this.open){
			this.close();
		}else{
			this.show();
		}
	}
});
