/** 
 * jQuery plugin JToolTip
 *
 *  http://moda.ru/
 *
 *  Example: 
 *  var wait = $('body').jtooltip();
 *  	wait.show();
 *  	wait.hide();
 *
 *  jQuery required. Download it at http://jquery.com/
 *
 */


(function(jQuery) {

	jQuery.fn.jtooltip = function(options){
		
		var self = this;
		var tooltip;
		
		options = jQuery.extend({
			message: null,
			width: 300
		}, options);
		
		var input = $('input, textarea, select', this);
		var child = input.parent().children();
		var last = child[child.length-1];
		var idx = 'jtooltip_' + input.attr('name');
		var tooltip = $('#' + idx);
		
		if (!tooltip.length) {
		
			var table = '<div class="jtooltip" id="jtooltip_' + input.attr('name') + '">' +
			'<div class="jtooltip_tail"></div>' +
			'<table border="0" cellpadding="0" cellspacing="0"><tbody>' +
			'<tr><td class="jtooltip_tl"></td><td class="jtooltip_tc"></td><td class="jtooltip_tr"></td></tr>' +
			'<tr><td class="jtooltip_ml"></td><td class="jtooltip_mc">' + options.message +'</td><td class="jtooltip_mr"></td></tr>' +
			'<tr><td class="jtooltip_bl"></td><td class="jtooltip_bc"></td><td class="jtooltip_br"></td></tr>' +
			'</tbody></table></div>';
			
			tooltip = $(table).
				css({
					'margin-left': input.parent().width() + 25
				}).
				width(options.width + 'px').
				insertAfter(last);
		}
		
		 tooltip.show();
	}
		
})(jQuery);