///////////////////////////////////////////////////////\\
///////////////////////////////////////////////////////\\
//***************************************************\\\\
//              JQuery Easy Tooltip v2.0             \\\\
//                    ExpBuilder                     \\\\
//                elkadrey@gmail.com                 \\\\
//                webmaster@expbuilder.com           \\\\
//***************************************************\\\\
///////////////////////////////////////////////////////\\
///////////////////////////////////////////////////////\\
(function($) {

jQuery.fn.easytooltip = function(id, options)
{

    var Config = {
         backgroundcolor: "#ffffff",
         border         : "1px solid #000",
         color          : "#000",
         event          : 'mousemove'
    };

    if(options)
    {
		jQuery.extend(Config, options);
	};

    if(!document.getElementById('tool_tip'))
    {
       $("body").append('<div id="tool_tip_action_' + id + '">&nbsp;</div>');
       $("#tool_tip_action_" + id).css({"background-color": Config.backgroundcolor, border: Config.border, color: Config.color, position: "absolute", "z-index": "1001", "display": "none"});
    }

    function brwstester()
    {
        return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
    }


    $("#" + id).hide();

        $(this).bind(Config.event, function(e)
        {
            if(screen.width <= (e.pageX + 40 + $("#tool_tip_action_" + id).width()))
            {
               var lfts = e.pageX - $("#tool_tip_action_" + id).width() - 20;
            }

            else
            {
                  var lfts = e.pageX + 20;
            }

            if(brwstester().scrollTop < e.pageY - 20 - $("#tool_tip_action_" + id).height())
            {
                var tps =  (e.pageY - $("#tool_tip_action_" + id).height() - 20);
            }
            else
            {
                var tps = e.pageY + 20;
            }


            $("#tool_tip_action_" + id).html($("#" + id).html()).css({"left": lfts, "top" : tps}).show();
        });


       $(this).bind("mouseout", function()
       {
            $("#tool_tip_action_" + id).hide().css({"left": 0, "top" : 0});
       });


}

$.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).hover(function(e){											 							   
				content = (options.content != "") ? options.content : title;
				content = (options.useElement != "") ? $("#" + options.useElement).html() : content;
				$(this).attr("title","");									  				
				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")
						.fadeIn("fast")
				}
			},
			function(){	
				$("#" + options.tooltipId).remove();
				$(this).attr("title",title);
			});	
			$(this).mousemove(function(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);
				});				
			}
		});
	  
	};

})(jQuery);
