/*
 * 	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>';  
   var template2 = 	'<div class="smallTooltipLeftCorner pngfix"><div class="smallTooltipRightCorner"><div class="smallTooltipTopArrow"></div><div class="smallTooltipTopBorder pngfix"></div><div class="smallTooltipContentTop">{content}</div></div></div>';
   var template3 = 	'<div class="smallTooltipLeftCorner pngfix"><div class="smallTooltipRightCorner"><div class="smallTooltipTopBorder1 pngfix"></div><div class="smallTooltipContentTop">{content}</div></div></div>';
	$.fn.easyTooltip = function(options){
	  
		// default configuration properties
		var defaults = {	
			xOffset: 10,		
			yOffset: 25,
			tooltipId: "tTip",
			clickRemove: true,
			content: "",
			useElement: ""				
		}; 
			
		var options = $.extend(defaults, options);  
		var content;		
				
		this.each(function() {
	      	var title = $(this).attr("title_tt");
			$(this).mouseout(function(e) {
    				$("#" + options.tooltipId).remove();
    				$(this).attr("title_tt", title);
    			}
            );	    
			$(this).mousemove(function(e){
			    if (($("#" + options.tooltipId).css("display")=="none") || ($("#" + options.tooltipId).length==0)) {
			         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_tt",title);
				});					
			}
		});
		
		function showTooltip(e) {
				ttcontent = $(e.currentTarget).attr("title_tt");
				content = (options.useElement != "") ? $("#" + options.useElement).html() : content;				
				
				if (options.forceContent === true) {
					content = options.content;
    		    }
				if (options.template == "template1") {
				  content = template1.replace("{content}", ttcontent);  
				} else if (options.template == "template2") {
				  content = template2.replace("{content}", ttcontent); 
				} else if (options.template == "template3") {
				  content = template3.replace("{content}", ttcontent); 
				} else if (options.template == "template1_ie6") {
				  content = template1_ie6.replace("{content}", ttcontent);
				}
				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")
						.css("z-index","10010")
						.fadeIn("fast")
				}
		}
	  
	};

})(jQuery);

