/*
	HUMANIZED MESSAGES 1.0
	idea - http://www.humanized.com/weblog/2006/09/11/monolog_boxes_and_transparent_messages
	home - http://humanmsg.googlecode.com
*/

var humanMsg = {
	setup: function(appendTo, opacity) {
		humanMsg.elementId = 'humanMsg';

		// appendTo is the element the msg is appended to
		if (appendTo == undefined) {
			appendTo = 'body';
        }

		// Opacity of the message
        humanMsg.opacity = 0.8;
		if (opacity != undefined){ 
			humanMsg.opacity = parseFloat(opacity);
        }

		// Inject the message structure
		$j(appendTo).append('<div id="'+humanMsg.elementId+'" class="humanMsg"><p></p></div>')
	},

	displayMsg: function(message) {
		if (message == '') {
			return;
        }

		clearTimeout(humanMsg.t2);

		// Inject message
		$j('#'+humanMsg.elementId+' p').html(message)
	
		// Show message
		$j('#'+humanMsg.elementId+'').show().animate({ opacity: humanMsg.opacity}, 200, function() {})

		// Watch for mouse & keyboard in 1.5s
		humanMsg.t1 = setTimeout("humanMsg.bindEvents()", 1500)
		// Remove message after 5s
		humanMsg.t2 = setTimeout("humanMsg.removeMsg()", 5000)
	},

	bindEvents: function() {
        // Remove message if mouse is moved or key is pressed
		$j(window).mousemove(humanMsg.removeMsg)
			      .click(humanMsg.removeMsg)
			      .keypress(humanMsg.removeMsg)
	},

	removeMsg: function() {
		// Unbind mouse & keyboard
		$j(window).unbind('mousemove', humanMsg.removeMsg)
		      	  .unbind('click', humanMsg.removeMsg)
			      .unbind('keypress', humanMsg.removeMsg)

		// If message is fully transparent, fade it out
		if ($j('#'+humanMsg.elementId).css('opacity') == humanMsg.opacity) {
			$j('#'+humanMsg.elementId).animate({ opacity: 0 }, 500, function() { $j(this).hide() })
        }
	}
};
