/*********************************************
* jquery.cart.js
* author: John Bohn
* description: jQuery plugin to help with 
*  user input.
* copyright: 2010 Zambooie, Inc.
**********************************************/

(function($){
	
	var _init = false;
	var _background;
	var _content;
	var _settings;
	var _element;
	var _functions = {
			
		init: function(element, settings){
			_settings = settings;
			_element = element;
			_init = true;
			_background = $('<div id="zmessenger_background"></div>');
			_content = $('<div id="zmessenger_content"></div>');
			element.append(_background).append(_content);
		},
		
		show: function(params){
			
			if ( $.isPlainObject(params) )
			{
				if ( params.html != undefined ) _content.html(params.html);
				var speed = params.speed != undefined ? params.speed : 0;
			}
			
			_element.fadeIn(speed != undefined ? speed : 0);
			
			_content.width(params.width != undefined ? params.width : 'auto');
			_content.height(params.height != undefined ? params.height : 'auto');
			
			var content_frame = { width: _content.width(), height: _content.height() };
			
			_content
				.css('left', '50%')
				.css('top', '50%')
				.css('margin-left', '-' + ( content_frame.width/2 ) + 'px' )
				.css('margin-top', '-' + ( content_frame.height/2 ) + 'px' );
				
		},
		
		hide: function(params){
			if ( $.isPlainObject(params) )
			{
				var speed = params.speed != undefined ? params.speed : 0;
			}
			
			_element.fadeOut(speed != undefined ? speed : 0, function(params){
				if ( $.isPlainObject(params) )
				{
					if ( params.clear != undefined && params.clear ) _content.html('');
				}
			});
		}
	};
	
	$.fn.zmessenger = function(func, params)
	{
		if ( $.isPlainObject(func) || typeof func == 'undefined' )
		{
			if ( ! _init ) _functions.init(this, params);
		}
		else if ( $.isFunction(_functions['init']) )
		{
			_functions[func](params);
		}

		return this;
	};
		
})(jQuery);
