var MessageClass = new Class(
{
	Implements: [Options,Events],
	message_div:$empty,
	overlay:$empty,
	options: {
		max_opacity: ".8"
	},
	message_div_fx:$empty,
	overlay_div_fx:$empty,
	oncloseFunction:'',

	initialize: function(options)
	{
		this.createMessageHTML();
		this.generateOverlay();
		
		
		this.message_div_fx = new Fx.Tween(this.message_div, {
			duration: 500,
			wait: false,
			transition: Fx.Transitions.Quad.easeOut,
			onCancel : function()
			{
				//his.current_opacity = my_overlay.style.opacity;
			}
		});
		
		this.overlay_div_fx = new Fx.Tween(this.overlay, {
			duration: 500,
			wait: false,
			transition: Fx.Transitions.Quad.easeOut,
			onCancel : function()
			{
				//his.current_opacity = my_overlay.style.opacity;
			}
		});
		

	},

	createMessageHTML: function()
	{

		var html = '<table style="width:100%;" class="baseTableNoBorder"><tr class="messageTableHeader"><td width=80%><span id="message_title"></td><td align="right" width="20%" style="color:black;" ><acronym onclick="closeMessage()" style="cursor:pointer;">X</acronym>&nbsp;&nbsp;&nbsp;</td></tr><tr><td colspan=2><div id="message_body" class="messageBody" style="margin-top:15px;"></div></td></tr></table></div>';
		this.message_div = new Element('div', {
		'id': 'message_box_div',
		'html': html,
		'styles': {
		'display': 'block',
		'width': '500px',
		'height': '300px',
		'position': 'absolute',
		'background': '#ffffff',
		'border': '1px solid #030303',
		'z-index': '1006',
		'visibility':'visible',
		'opacity': 0
		}
		});
		// set the id into an array to call when needed
		//windowArray[windowArray.length+1] = id;

		document.body.appendChild(this.message_div);
	},
	generateOverlay : function ()
	{
		this.overlay = new Element('div', {
		'id': 'newOverlay',
		'styles': {
		'display': 'block',
		//'position': 'fixed',
		'width': '100%',
		'position': 'absolute',
		'top': 0,
		'left': 0,
		'opacity': '0',
		'background': '#3c3c3c',
		'z-index': '1004'
		}
		});

		this.updateOverLaySize();

		document.body.appendChild(this.overlay);
	},
	centerWaitingDiv: function ()
	{

		var scroll = window.getScrollSize(); 	// mootools scroll size function
		var scrollPos = window.getScroll(); 	// mootools position function
		var windowSize = window.getSize();		// mootools size function

		var X = $('message_box_div').getStyle('width').replace(/px$/,"");		// remove the px so that we can do math on it
		var Y = $('message_box_div').getStyle('height').replace(/px$/,""); 

		// if the height of the object is set to auto, auto adjust
		if (Y == "auto") 
		{
			Y = (windowSize.y/2)-20;
		}

		// set the position of the element
		$('message_box_div').style.left = ((scroll.x/2) - (X/2)) + "px";
		$('message_box_div').style.top = (((windowSize.y/2) + scrollPos.y) - (Y/2)) + "px";


	},
	updateOverLaySize: function ()
	{
		var windowsize_y
		windowsize_y= window.getScrollSize().y;

		this.overlay.style.height = windowsize_y + "px";
	},
	showMessage: function(title,height,width)
	{
		if(!height)height = 300;
		if(!width)width = 200;
		this.centerWaitingDiv();
		$('message_title').innerHTML = title;
		this.message_div.style.height = height;
		this.message_div.style.width = width;
		this.message_div.setStyle('height',height);
		//$('message_box_div').style.display = '';
		//$('message_box_div').style.opacity = 1;

		this.showOverlay();
		
		this.message_div_fx.start('opacity', 0, 1);


		this.updateOverLaySize();
	},
	closeMessage: function()
	{
		this.message_div_fx.start('opacity', 1, 0);
		this.overlay_div_fx.start('opacity', '.5', 0);
		
		if(this.oncloseFunction !='')
		{
			eval(this.oncloseFunction);
			this.oncloseFunction = '';
		}
	},
	showOverlay: function()
	{
		this.overlay_div_fx.start('opacity', 0, '.5');
	},
	setOnCloseCallFunction: function(str)
	{
		this.oncloseFunction = str;
	}


});

