
var humanMsg = {
	setup: function(appendTo, logName, msgOpacity) {
		 humanMsg.msgID = 'humanMsg';
		 humanMsg.defaults =
		 {
			closeType:  "auto",
			closeTime:  3000,
			closeBtn:   0,
			width:      "560px",
			height:	    "auto",
			top:        "200px",
			left:       "235px",
			bgcolor:    "black",
			msgType:    0
		};

		// appendTo is the element the msg is appended to
		if (appendTo == undefined)
		{
			appendTo = 'body';
		}
		// Opacity of the message
		humanMsg.msgOpacity = .99;

		if (msgOpacity != undefined)
		{ 
			humanMsg.msgOpacity = parseFloat(msgOpacity);
		}
		// Inject the message structure
				
    str = '<div id="'+humanMsg.msgID+'" class="humanMsg">'+
            '<div class="icon" id="'+humanMsg.msgID+'_icon"><img src="../images/WarningIcon.gif" alt="error"/></div>'+
            '<div id="'+humanMsg.msgID+'_close"></div>'+
            '<div style="padding:10px;"><p style="margin:0 10px 0 10px"></p></div>'+
          '</div>'
        
		
        jQuery(appendTo).append(str);
    },
	
	loadDefaults: function(conf){
	
	    humanMsg.defaults = jQuery.fn.extend({}, humanMsg.defaults, conf);
	},   

	displayMsg: function(msg,cfg) {
		if (msg == '') return;
		if(!cfg) cfg = { };
		
		humanMsg.config = jQuery.fn.extend({}, humanMsg.defaults, cfg);

		//Load config to css
		jQuery('#'+humanMsg.msgID).css({width:humanMsg.config.width, height:humanMsg.config.heigth, top:humanMsg.config.top, left:humanMsg.config.left});
		
		//add close btton function
		if(humanMsg.config.closeBtn)
		{
			jQuery('#'+humanMsg.msgID+'_close').css({textAlign:"right",padding:"10px",widht:"25px",height:"29px",float:"right"})
			jQuery('#'+humanMsg.msgID+'_close').html('<img src="../images/x.png" alt="close"/>');
			jQuery('#'+humanMsg.msgID+'_close').click(humanMsg.removeMsg).css('cursor', 'pointer');
		}
		
		//change the error style
		if(humanMsg.config.msgType == 1)
		{
		    jQuery('#'+humanMsg.msgID).addClass("humanMsg_Ok");
		    jQuery('#'+humanMsg.msgID+'_icon img').attr({ src: "../images/ok48.gif",alt: "rror"});
		}
		    
	    else if (jQuery('#'+humanMsg.msgID).is(".humanMsg_Ok") )
	    {
	        jQuery('#'+humanMsg.msgID).removeClass("humanMsg_Ok");
	        jQuery('#'+humanMsg.msgID+'_icon img').attr({ src: "../images/WarningIcon.gif",alt: "error"});
	    
	    }
		    
		
		
		
		clearTimeout(humanMsg.t2);

		// Inject message
		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( humanMsg.config.closeType =="auto" && !humanMsg.config.closeBtn)
		{
			humanMsg.t1 = setTimeout("humanMsg.bindEvents()", 2000);
			// Remove message after 5s
			humanMsg.t2 = setTimeout("humanMsg.removeMsg()", humanMsg.config.closeTime);
		}
		
	},

	bindEvents: function() {
	// Remove message if mouse is moved or key is pressed
		jQuery(document)
			.mousemove(humanMsg.removeMsg)
			.click(humanMsg.removeMsg)
			.keypress(humanMsg.removeMsg)
	},

	removeMsg: function() {
		// Unbind mouse & keyboard
		jQuery(document)
			.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();
})