var Msg = Class.create({
	types : ['success','error','info'],

	initialize : function(options) {
		// Default values
		this.type		= 'info';
		this.buttons	= [];
		
		// Remove created boxes if any
		if ($('msgBox')) {
			$('msgBox').remove();
		}
		
		// Check options
		options = options || {};
		for(option in options) {
			switch(option) {
				case 'text':
					this.text = options[option];
					break;
				
				case 'type':
					if (options[option] == 'success' || options[option] == 'error' || options[option] == 'info') {
						this.type = options[option];
					}
					break;
				
				case 'buttons':
					for (var i=0; i<options[option].length; i++) {
						this.buttons.push(this.createButton(options[option][i]));
					}
					break;
				
				default:
			}
		}
		
		this.createColorPlain();
		this.colorPlain.hide();
		
		this.createBox();
		$('msgBox').hide();
		
		this.display();
	},
	
	display : function() {
		var _width	= document.body.getWidth();
		var _height	= document.body.getHeight();
		
		var width	= this.box.getWidth();
		var height	= this.box.getHeight();
		
		var top		= Math.round((_height - height) / 2);
		var left	= Math.round((_width - width) / 2);
		
		//alert(_width+' / '+_height);
		//alert(top+' / '+left);
		
		this.box.style.top	= top+'px';
		this.box.style.left	= left+'px';
		
		this.box.show();
		$('msgColorPlain').show();
	},
	
	hide : function() {
		$('msgColorPlain').hide();
		$('msgBox').remove();
	},
	
	createButton : function(options) {
		var button = {};
		
		button.label	= options.label;
		button.action	= options.action;
		button.element	= document.createElement('button');
		
		button.element.innerHTML = options.label;
		
		return button;
	},
	
	createColorPlain : function() {
		if (!$('msgColorPlain')) {
			var msgColorPlain = document.createElement('div');
			Element.extend(msgColorPlain);
			msgColorPlain.id = 'msgColorPlain';
			msgColorPlain.className = 'msgColorPlain';
			msgColorPlain.style.height = Element.getPageHeight()+'px';
			document.body.appendChild(msgColorPlain);
		}
		
		this.colorPlain = $('msgColorPlain');
	},
	
	createBox : function() {
		this.box = document.createElement('div');
		this.box.id = 'msgBox';
		this.box.className = 'msgBox ajax_msg_'+this.type;
		
		var boxText = document.createElement('div');
		boxText.innerHTML = this.text;
		
		var buttonsDiv = document.createElement('div');
		buttonsDiv.className = 'buttons';
		for(var i=0; i<this.buttons.length; i++) {
			this.buttons[i].element.id = 'msgButton_'+i;
			buttonsDiv.appendChild(this.buttons[i].element);
		}
		
		boxText.appendChild(buttonsDiv);
		
		this.box.innerHTML = '<div id="msg" class="msg" ><h1>Zen Ambience</h1><div class="text">'+boxText.innerHTML+'</div></div>';

		document.body.appendChild(this.box);

		for(var i=0; i<this.buttons.length; i++) {
			$('msgButton_'+i).observe('click',this.buttons[i].action);
		}
	}
});
