/*
	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, logName, msgOpacity) {
		humanMsg.msgID = 'humanMsg';
		humanMsg.logID = 'humanMsgLog';

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

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

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


		jQuery(appendTo).append('<div id="'+humanMsg.msgID+'" class="humanMsg"><p></p></div>');


	},

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

        if(flag)
        {
          jQuery('#'+humanMsg.msgID+'').css("backgroundColor","#A80022");
        }else
          jQuery('#'+humanMsg.msgID+'').css("backgroundColor","black");


		clearTimeout(humanMsg.t2);

		// Inject message
         if(ajax)
		jQuery('#'+humanMsg.msgID+' p').html("Please Wait.....");
        else
        jQuery('#'+humanMsg.msgID+' p').html(msg);

		// Show message
		jQuery('#'+humanMsg.msgID+'').show().animate({ opacity: humanMsg.msgOpacity}, 200, function() {
        /**/
		});

		// Watch for mouse & keyboard in .5s
        if(!ajax){
            humanMsg.t1 = setTimeout("humanMsg.bindEvents()", 700)
    		// Remove message after 5s
        	humanMsg.t2 = setTimeout("humanMsg.removeMsg()", 1000)
            }

	},

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

      jQuery('#'+humanMsg.msgID+' p').html(msg)
      setTimeout("humanMsg.removeMsg()", 1000)

	}
   ,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() })
	}
};