/*
 *   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($j) {
    $j.fn.setTooltip = function(val){
        this[0]._title = val;
    },

    $j.fn.getTooltip = function(){
        return this[0]._title;    
    },
            
  $j.fn.easyTooltip = function(options){
    
    // default configuration properties
    var defaults = {  
      xOffset: 10,    
      yOffset: 25,
      tooltipId: "easyTooltip",
      clickRemove: false,
      content: "",
      useElement: ""
    }; 
      
    var options = $j.extend(defaults, options);  
    var content;
        
    this.each(function() {          
      this._title = this.title;
            this.title = '';
            
      $j(this).bind('mouseover', function(e){                                        
        content = (options.content != "") ? options.content : this._title;
        content = (options.useElement != "") ? $("#" + options.useElement).html() : content;

        if (content != "" && content != undefined){      
          $j("body").append("<div id='"+ options.tooltipId +"'>"+ content +"</div>");    
          $j("#" + options.tooltipId)
            .css("position","absolute")
            .css("top",(e.pageY - options.yOffset) + "px")
            .css("left",(e.pageX + options.xOffset) + "px")            
            .css("display","none")
            .fadeIn("fast")
        }
      });
      $j(this).bind('mouseout', function(e){  
        $j("#" + options.tooltipId).remove();
      });  
      $j(this).mousemove(function(e){
        $j("#" + options.tooltipId)
          .css("top",(e.pageY - options.yOffset) + "px")
          .css("left",(e.pageX + options.xOffset) + "px")          
      });  
      if(options.clickRemove){
        $j(this).mousedown(function(e){
          $("#" + options.tooltipId).remove();
        });        
      }
    });
  };

})(jQuery);

