(function($) {
	$.fn.easyTooltip = function(options){

		var defaults = {	
			xOffset: 10,		
			yOffset: 25,
			tooltipId: "easyTooltip",
			clickRemove: false,
			content: "",
			useElement: "",
                     className: 'totip',
                     width:300
		}; 

		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 +"' class='"+options.className+"'>"+ content +"</div>");		
					$("#" + options.tooltipId)
						.css("position","absolute")
						.css("z-index","9999")
						.css("top",(e.pageY - options.yOffset) + "px")
						.css("left",(e.pageX > screen.width - options.width - options.xOffset ? e.pageX - options.xOffset - options.width: e.pageX + options.xOffset)+ "px")						
						.css("display","none")
                                          .css("margin-right", "10px")
                                          .css("width", options.width + 'px')
						//.show()}, 1000);/*.fadeIn(1000)*/
                                   setTimeout( function() {$("#" + options.tooltipId).show()}, 1000);

				}
			},
			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 > screen.width - options.width - options.xOffset ? e.pageX - options.xOffset - options.width: e.pageX + options.xOffset) + "px")					
			});	
			if(options.clickRemove){
				$(this).mousedown(function(e){
					$("#" + options.tooltipId).remove();
					$(this).attr("title",title);
				});				
			}
		});
	  
	};

})(jQuery);

