(function($) {
  $.fn.termifier = function(options) {
    options = $.extend({
      width: 2000,
      height: 2000,
      lookupResource: 'carrotTerm.do',
      flyoutClass: 'lookerUpperFlyout',
      prompt: 'Click me for my definition!'
    },options||{});
    this.attr('title',options.prompt);
    return this.click(function(event){
      $.ajax({
        url: options.lookupResource,
        type: 'get',
        data: {term: (this.innerHTML=='' ? this.getAttribute('longdesc') : this.innerHTML)},
        dataType: 'html',
        success: function(data) {
          $('<div></div>')
            .css({
              position: 'absolute',
              left: (event.pageX+260<options.width?event.pageX:options.width-260),
              top: (event.pageY+160<options.height?event.pageY+12:options.height-160),
              cursor: 'pointer',
              display: 'none'
            })
            .html(data)
            .addClass(options.flyoutClass)
            .click(function(){
              $(this).fadeOut(1000,function(){$(this).remove();});
             })
            .appendTo('body')
            .fadeIn();
          }
        });
        return false;
      });
  }
})(jQuery);

