/**
 * @author JRG Productions
 */
		
messages = {

	// inc the z-indexes with each one
	zindex : 0,

	// remove message
	remove_message : function(msg_id) {
		
		// kill it
		document.body.removeChild(document.getElementById(msg_id));
	
		// return site to normal looks
		gray_out();
	},

	// create a message
	create_message : function(title, message, extra_buttons)
	{
		// let's get all gray
		gray_in();
		
		var extra_buttons;
		
		// what this function should return
		var return_val = true;
		
		// id of this
		var msg_id = 'mb_'+Math.random();
		
		// id of close btn
		var close_id = 'cb_'+Math.random();
		
		// create our new message box
		var message_box = document.createElement('div');
		
		// assign it a random id and mb class
		message_box.setAttribute('id', msg_id);
		message_box.setAttribute('class', 'message_box');
		message_box.style.marginTop = this.zindex+'px';
		message_box.style.marginLeft = this.zindex+'px';

		// add h3 tag
		var title_box = document.createElement('h3');
		title_box.innerHTML = title;
		message_box.appendChild(title_box);
	
		// add content
		var content = document.createElement('div');
		content.setAttribute('class', 'content');
		content.innerHTML = message;
		message_box.appendChild(content);
		
		// add bar of actions
		var end_bar = document.createElement('div');
		end_bar.setAttribute('class', 'end');
						
		// add the little buttons
		var btns = document.createElement('div');
		btns.setAttribute('class', 'btns');
		btns.onclick = function(){messages.remove_message(msg_id)};
		end_bar.appendChild(btns);

		// more buttons
		for (i = 0; i < extra_buttons.length; i++) {
			var btn = extra_buttons[i];
			var n_btn = document.createElement('button');
			n_btn.innerHTML = extra_buttons[i].msg;
			n_btn.onclick = btn.action;
			btns.appendChild(n_btn);
		}
		
		// the close button
		if (extra_buttons.length == 0) {
			var close_btn = document.createElement('button');
			close_btn.setAttribute('id', close_id);
			close_btn.onclick = function(){
				messages.remove_message(msg_id);
			};
			close_btn.innerHTML = extra_buttons.length > 0 ? 'Close' : 'Dismiss';
			btns.appendChild(close_btn);
		}

		// append button box to box
		message_box.appendChild(end_bar);

		// insert it into the message_farm
		document.body.appendChild(message_box);

		// just a notif? kill it after a bit and focus the button
		if (extra_buttons.length == 0) {
			document.getElementById(close_id).focus();
			setTimeout('messages.remove_message(\''+msg_id+'\')', 50000);
		}

		// so multiple ones of these aren't directly on top of each other			
		this.zindex += 10;
	}
}

