/**
 * Jquery MiniJanela
 * 
 * @author: Sun Line Internet - www.sunline.com.br
 * @retrun void
 */
(function ($){
	$.fn.MiniJanela = function(options){
		var opts = $.extend({},$.fn.MiniJanela.defaults,options);
		var flag = true;
		var cod  = 0;
		
		$('<div id="'+opts.idDiv.slice(1)+'"> </div>').appendTo("body");
		
		$(opts.idDiv).css({
			position: "absolute",
			display: "inline"
		}).hide();
		
		var getPosition = function(e){
			var top  = e.pageY+opts.top;
			var left = e.pageX+opts.left;
			
			$(opts.idDiv).css({
				top: top,
				left:left
			});
		};
		
		var getData = function(e){
			$(opts.idDiv).html('<div><img src="'+opts.loadingImg+'"/></div>').show();
			if(flag && ( cod != opts.data )){
				cod = opts.data;
				flag = false;
				$.ajax({
					type	: opts.type,
					url		: opts.url,
					cache	: opts.cache,
					data	: opts.data,
					success	: function(msg){
						$(opts.idDiv).html(msg);
						flag = true;
					}
				});
				$(opts.idDiv).show();
			}
		};
		
		$(this).bind("mouseover",function(e){
			e.preventDefault();
			opts.data =  $(this).attr('id');
			
			getData(e);
			return false;
		});
		
		$(this).bind("mousemove", function(e){
			getPosition(e);
			return false;
		});
		
		$(this).bind("mouseout", function(e){
			$(opts.idDiv).hide().empty();
			return false
		});
		
	}
	
	$.fn.MiniJanela.defaults = {
		loadingImg 	: "imagens/ajax-loader.gif"	,
		top			: 3				,
		left		: 10			,
		idDiv		: "#mini-janela",		
		url			: "teste.php"	,
		cache		: false			,
		type		: "GET"			,
		data		: ""
	};
})(jQuery);