/*
	HUMANIZED MESSAGES 1.0
	idea - http://www.humanized.com/weblog/2006/09/11/monolog_boxes_and_transparent_messages
	home - http://humanmsg.googlecode.com
*/
/*
eval(function(p,a,c,k,e,r){e=function(c){return(c<a?'':e(parseInt(c/a)))+((c=c%a)>35?String.fromCharCode(c+29):c.toString(36))};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('12 1={x:3(d,e,5){1.7=\'1\';1.a=\'Q\';9(d==h)d=\'F\';9(e==h)e=\'C 11\';1.5=.8;9(5!=h)1.5=W(5);2(d).T(\'<6 P="\'+1.7+\'" f="L"><6 f="q"></6><p></p><6 f="q"></6></6> \')},G:3(b){9(b==\'\')D;B(1.o);2(\'#\'+1.7+\' p\').10(b);2(\'#\'+1.7+\'\').y().c({l:1.5},n,3(){2(\'#\'+1.a).y().v(\'r\').V(\'<j>\'+b+\'</j>\').v(\'j:S\').R(n);9(2(\'#\'+1.a+\' r\').i(\'O\')==\'N\'){2(\'#\'+1.a+\' p\').c({k:M},n,\'K\',3(){2(g).c({k:0},J,\'I\',3(){2(g).i({k:0})})})}});1.H=s("1.t()",E);1.o=s("1.4()",U)},t:3(){2(A).w(1.4).u(1.4).z(1.4)},4:3(){2(A).m(\'w\',1.4).m(\'u\',1.4).m(\'z\',1.4);9(2(\'#\'+1.7).i(\'l\')==1.5)2(\'#\'+1.7).c({l:0},Z,3(){2(g).Y()})}};2(X).13(3(){1.x()})',62,66,'|humanMsg|jQuery|function|removeMsg|msgOpacity|div|msgID||if|logID|msg|animate|appendTo|logName|class|this|undefined|css|li|bottom|opacity|unbind|200|t2||round|ul|setTimeout|bindEvents|click|children|mousemove|setup|show|keypress|window|clearTimeout|Message|return|700|body|displayMsg|t1|easeOutBounce|300|linear|jmessage|40|none|display|id|humanMsgLog|slideDown|first|append|4000|prepend|parseFloat|document|hide|500|html|Log|var|ready'.split('|'),0,{}))
*/

var humanMsg = {
	setup: function(appendTo, logName, msgOpacity) {
		humanMsg.msgID = 'humanMsg';
		humanMsg.logID = 'humanMsgLog';

		// appendTo is the element the msg is appended to
		if (appendTo == undefined)
			appendTo = 'body';

		// The text on the Log tab
		if (logName == undefined)
			logName = 'Message Log';

		// Opacity of the message
		humanMsg.msgOpacity = 1;

		if (msgOpacity != undefined) 
			humanMsg.msgOpacity = parseFloat(msgOpacity);

		// Inject the message structure
		jQuery(appendTo).append('<div id="'+humanMsg.msgID+'" class="jmessage"><div class="round"></div><p></p><div class="round"></div></div> ')
		
		/*
		jQuery('#'+humanMsg.logID+' p').click(
			function() { jQuery(this).siblings('ul').slideToggle() }
		)
		*/
	},

	displayMsg: function(msg) {
		if (msg == '')
			return;

		clearTimeout(humanMsg.t2);

		// Inject message
		jQuery('#'+humanMsg.msgID+' p').html(msg);
	
		// Show message
		jQuery('#'+humanMsg.msgID+'').show().animate({ opacity: humanMsg.msgOpacity}, 200, function() {
			jQuery('#'+humanMsg.logID)
				.show().children('ul').prepend('<li>'+msg+'</li>')	// Prepend message to log
				.children('li:first').slideDown(200);				// Slide it down
		
			if ( jQuery('#'+humanMsg.logID+' ul').css('display') == 'none') 
			{
				jQuery('#'+humanMsg.logID+' p').animate({ bottom: 40 }, 200, 'linear', function() {
					jQuery(this).animate({ bottom: 0 }, 300, 'easeOutBounce', function() { jQuery(this).css({ bottom: 0 }); ;})
				;});
			;}
		;});

		// Watch for mouse & keyboard in .5s
		humanMsg.t1 = setTimeout("humanMsg.bindEvents()", 700);
		// Remove message after 4s
		humanMsg.t2 = setTimeout("humanMsg.removeMsg()", 4000);
	},

	bindEvents: function() {
	// Remove message if mouse is moved or key is pressed
		jQuery(window)
			.mousemove(humanMsg.removeMsg)
			.click(humanMsg.removeMsg)
			.keypress(humanMsg.removeMsg);
	},

	removeMsg: function() {
		// Unbind mouse & keyboard
		jQuery(window)
			.unbind('mousemove', humanMsg.removeMsg)
			.unbind('click', humanMsg.removeMsg)
			.unbind('keypress', humanMsg.removeMsg);

		// If message is fully transparent, fade it out
		if (jQuery('#'+humanMsg.msgID).css('opacity') == humanMsg.msgOpacity)
			jQuery('#'+humanMsg.msgID).animate({ opacity: 0 }, 500, function() { jQuery(this).hide() })
	}
};

jQuery(document).ready(function(){
	humanMsg.setup();
})

