/*
 * humanMsg 1.1 - Plugin for jQuery
 * 
 * My implementation of humanized messages http://ajaxian.com/archives/humanized-messages-library
 *
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 *
 * Depends:
 *   jquery.js
 *
 *  Copyright (c) 2008 Oleg Slobodskoi ( http://code.google.com/p/ajaxsoft/ )
 */



(function($){
$.fn.humanMsg = function ( message, options )
{
	return this.each(function(){
	    var elem = this == window || this == document ? document.body : this;
		!$.data(elem, 'humanMsg') && $.data(elem, 'humanMsg', new $.humanMsg (elem, message, options) );
	});
};

$.fn.humanMsg.defaults = {
	message: 'no message was set',
	autoHide: 3000,
	addClass: '',
	speed: 300
};

$.humanMsg = function ( container, message, options )
{
	if (typeof message == 'object') {
		options = message;
		message = null;
	};  


	var s = $.extend({}, $.fn.humanMsg.defaults, options);

	
	var $m,
		sizeContainer = container == document.body ? window : container
	;
	

	
	$m = $('<div class="humanized-message '+s.addClass+'"/>')
	.html(message || s.message)
	.click(remove)
	.appendTo(container);

	$m.css({
		display: 'none',
		visibility: 'visible',
		top: ($(sizeContainer).height()-$m.innerHeight())/2,
		left: ($(sizeContainer).width()-$m.innerWidth())/2
	})
	.fadeIn(s.speed);
	
		
	s.autoHide && setTimeout(remove, s.autoHide);	

	function remove () {
		$m.fadeOut(s.speed, function(){
			$m.remove();
			$.removeData(container, 'humanMsg');
		});
	};

};


	

})(jQuery);	
		

