var MessageWindow = new Class({            
	Implements: [Options, Events],
	initialize: function(options) {
		this.setOptions({
			"useViewPort": true,
			"travelDistance": 100,
			"containerWidth": 350,
			"containerHeight": "auto",
			"containerTop": 300,
			"containerLeft": "auto",
			"containerClass": "messageWindow",
			"timeout": null,
			"onShow": $empty,
			"onHide": $empty
		}, options);
	
		this.timer = 0;
		
		if(this.options.useViewPort){
			this.options.containerTop = (window.getHeight() / 2) + window.getScrollTop();
		}
		
		this.container = new Element('div', { 
			"opacity": 0,
			"styles": {
				"display": "none",
				"position": "absolute",
				"z-index": 999,
				"width": this.options.containerWidth,
				"height": this.options.containerHeight,
				"top": this.options.containerTop,
				"left": this.options.containerLeft
			},
			"events": {
				"click": this.hide.bind(this)
			},
			"class": this.options.containerClass
		}),
		
		this.message = new Element('div').injectInside(this.container),
		
		this.fx = new Fx.Morph(this.container, {
			"link": "cancel",
			"duration": 400
		});

		this.fx.set({
			"opacity": 0,
			"top": this.options.containerTop
		});
		
		this.container.injectInside($(document.body));
	},
	
	setup: function(bShow){
		var elements = $A(document.getElementsByTagName('object'));
		if (window.ie6) elements.extend(document.getElementsByTagName('select'));
		elements.each(function(el){ el.style.visibility = bShow ? 'hidden' : ''; });
	},

	show: function(text) {
		this.fireEvent("onShow");
		this.setup(true);
		
		if(this.options.useViewPort){
			this.options.containerTop = (window.getHeight() / 2) + window.getScrollTop();
		}
	
		$clear(this.timer);
		this.container.setStyles({
			"top": this.options.containerTop,
			"display": "block",
			"left": this.options.containerLeft == "auto" ? (window.getWidth() / 2) - (this.options.containerWidth / 2) : this.options.containerLeft
		});
		this.message.set("html", text);
		if(this.container.getStyle("opacity") != 1){
			this.fx.start({ 
				"opacity": [0, 1] 
			});
		}
		if(this.options.timeout){
			this.timer = this.hide.delay(this.options.timeout, this);
		}
	},

	hide: function() {
		this.fireEvent("onHide");
		this.setup(false);
		
		$clear(this.timer);
		this.fx.start({
			"opacity": 0,
			"top": this.options.containerTop - this.options.travelDistance
		});
	}

});