/*
 * 	Easy Tooltip 1.0 - jQuery plugin
 *	written by Alen Grakalic	
 *	http://cssglobe.com/post/4380/easy-tooltip--jquery-plugin
 *
 *	Copyright (c) 2009 Alen Grakalic (http://cssglobe.com)
 *	Dual licensed under the MIT (MIT-LICENSE.txt)
 *	and GPL (GPL-LICENSE.txt) licenses.
 *
 *	Built for jQuery library
 *	http://jquery.com
 *
 */
 
(function($) {
   
   var template1 = '<div class="smallTooltipLeftCorner pngfix"><div class="smallTooltipRightCorner"><div class="smallTooltipContent">{content}</div><div class="smallTooltipBottomBorder pngfix"></div><div class="smallTooltipBottomArrow pngfix"></div></div></div>';
   var template1_ie6 = '<span class="smallTooltipLeftCorner pngfix"></span><span class="smallTooltipContent pngfix">{content}</span><span class="smallTooltipRightCorner pngfix"></span><span class="smallTooltipBottomBorder pngfix"></span><span class="smallTooltipBottomArrow pngfix"></span>';  

	$.fn.easyTooltip = function(options){
	  
		// default configuration properties
		var defaults = {	
			xOffset: 10,		
			yOffset: 25,
			tooltipId: "easyTooltip",
			clickRemove: false,
			content: "",
			useElement: ""			
		}; 
			
		var options = $.extend(defaults, options);  
		var content;
				
		this.each(function() {
      var title = $(this).attr("title");  						
    		$(this).mouseout(function(e){	
    				$("#" + options.tooltipId).remove();
    				$(this).attr("title",title);
    			}
            );	    
			$(this).mousemove(function(e){
			    if (($("#" + options.tooltipId).css("display")=="none") || ($("#" + options.tooltipId).length==0)) {
			         $(this).attr("title","");
			         showTooltip(e);
                }
				$("#" + options.tooltipId)
					.css("top",(e.pageY - options.yOffset) + "px")
					.css("left",(e.pageX + options.xOffset) + "px")					
			});	
			if(options.clickRemove){
				$(this).mousedown(function(e){
					$("#" + options.tooltipId).remove();
					$(this).attr("title",title);
				});				
			}
		});
		
		function showTooltip(e) {
				content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
				if (options.forceContent === true) {
		      content = options.content;
        }
				if (options.template == "template1") {
				  content = template1.replace("{content}", content);
        } else if (options.template == "template1_ie6") {
          content = template1_ie6.replace("{content}", content);
        }
				if (content != "" && content != undefined){			
					$("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");		
					$("#" + options.tooltipId)
						.css("position","absolute")
						.css("top",(e.pageY - options.yOffset) + "px")
						.css("left",(e.pageX + options.xOffset) + "px")						
						.css("display","none")
						.css("background-color","transparent")						
						.css("border","none")
						.fadeIn("fast")
				}
		}
	  
	};

})(jQuery);
