var messageBoxId = 0;

function createMessageBox() {
	messageBoxId++;
		
	return {
		id:messageBoxId,
	    floatingBox : false,
	    transparentBox : false,
	    messageBox : false,
	    autoResize:true,

		initialize: function() { 
	       	var objBody = $$('body')[0];	
			
	       	var floatingBox_div = document.createElement('div');
	   		floatingBox_div.style.visibility = 'hidden';
	   		if(navigator.appVersion.match("MSIE")) 
	   		{
				floatingBox_div.style.position = 'absolute';
				floatingBox_div.style.top = objBody.scrollTop+objBody.clientHeight;
	   		}
	   		else
	   		{
	   			floatingBox_div.style.position = 'fixed';
	   		}
	       	floatingBox_div.id = 'floatingBox_'+messageBoxId;
	       	
	       	var transparentBox_div = document.createElement('div');
	       	transparentBox_div.style.position = 'absolute';
	       	transparentBox_div.style.background = 'green';
	       	transparentBox_div.style.opacity = '.85';
	       	transparentBox_div.id = 'transparentBox_'+messageBoxId;
	       	
	       	var messageBox_div = document.createElement('div');
	       	messageBox_div.style.position = 'absolute';
	       	messageBox_div.style.align = 'center';
	       	messageBox_div.style.padding = '10px';
	       	messageBox_div.style.whiteSpace = 'nowrap';
	       	messageBox_div.style.color = '#FFFFFF';
	       	messageBox_div.style.fontWeight = 'bold';
	       	messageBox_div.id = 'messageBox_'+messageBoxId;
	
	       	floatingBox_div.appendChild(transparentBox_div);
			floatingBox_div.appendChild(messageBox_div);
			objBody.appendChild(floatingBox_div);
			
			floatingBox_div.style.zIndex = 1000;
			
	        this.floatingBox = $('floatingBox_'+messageBoxId);
	    	this.transparentBox = $('transparentBox_'+messageBoxId);
	   		this.messageBox = $('messageBox_'+messageBoxId);
		},
		
		message: function(msg, timeout) {
	       	var objBody = $$('body')[0];	
	       	var tmpTimeout = new Number(timeout);
	       	tmpTimeout = (isNaN(tmpTimeout) || tmpTimeout <= 0) ? 2000 : tmpTimeout;
			//Turns the message on if it is off
			if(this.floatingBox.style.visibility == 'hidden') {	
				this.floatingBox.style.visibility = 'visible';
				this.floatingBox.style.opacity = '1';
				this.messageBox.innerHTML = msg;
				if(this.autoResize) {
					this.transparentBox.style.width = this.messageBox.clientWidth;
					this.transparentBox.style.height = this.messageBox.clientHeight;
					this.floatingBox.style.width = this.messageBox.clientWidth;
					this.floatingBox.style.height = this.messageBox.clientHeight + 5;
					this.floatingBox.style.right = 5;
					if(navigator.appVersion.match("MSIE")) 
						this.floatingBox.style.top = -40+objBody.scrollTop+objBody.clientHeight-document.messageBoxHeight;
					else
						this.floatingBox.style.bottom = document.messageBoxHeight;
				}
				document.messageBoxHeight += this.floatingBox.clientHeight;

				setTimeout('document.messageBoxes["mb_'+this.id+'"].fadeout()',tmpTimeout);
			}
			else {
				this.floatingBox.style.visibility = 'hidden';
			}
		},
		
		fadeout: function() {
			var opacity = this.floatingBox.style.opacity;
			opacity -= .1;
			if(opacity > .2) {
				this.floatingBox.style.opacity = opacity;
				setTimeout('document.messageBoxes["mb_'+this.id+'"].fadeout()',25);
			}
			else {
				document.messageBoxes["mb_"+this.id] = false;
				if(document.messageBoxNum == this.id) {
					document.messageBoxHeight = 0;	
					document.messageBoxNum = 0;
				}
				this.floatingBox.remove();		
			}
		},
		
		setColor: function(color) {
			switch(color) {
				case 'red':
					this.transparentBox.style.background = "#c00";
					break;
				case 'green':
				default:
					this.transparentBox.style.background = '#191';
					break;
			}
		},
		
		setWidth: function(width) {
			this.floatingBox.style.width = width;
		},
		
		setHeight: function(height) {
			this.floatingBox.style.height = height;
		},
		
		getWidth: function() {
			return this.transparentBox.clientWidth;
		},
		
		getHeight: function() {
			return this.transparentBox.clientHeight;
		},
		
		autoResize: function(value) {
			this.autoResize = value;
		},
		
		isVisible: function() {
			return(this.floatingBox.style.visibility == 'visible');
		}
		
	};
}

function loadMessageBox() {
	document.messageBoxes = new Array();
	document.messageBoxHeight = 0;
	document.messageBoxNum = 0;
}

Event.observe(window, 'load', loadMessageBox);