(function(o){var n={},Q,t,G,J=o.browser.msie&&/MSIE\s(5\.5|6\.)/.test(navigator.userAgent),f=false;o.Tooltip={blocked:false,defaults:{delay:200,showURL:true,extraClass:"",top:15,left:15},block:function(){o.Tooltip.blocked=!o.Tooltip.blocked;}};o.fn.extend({Tooltip:function(p){p=o.extend({},o.Tooltip.defaults,p);k();return this.each(function(){this.tSettings=p;this.tooltipText=this.title;o(this).removeAttr("title");this.alt="";}).hover(C,u).click(u);},fixPNG:J?function(){return this.each(function(){var p=o(this).css("backgroundImage");if(p.match(/^url\(["']?(.*\.png)["']?\)$/i)){p=RegExp.$1;o(this).css({"backgroundImage":"none","filter":"progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=crop, src='"+p+"')"}).each(function(){var S=o(this).css("position");if(S!="absolute"&&S!="relative"){o(this).css("position","relative");}});}});}:function(){return this;},unfixPNG:J?function(){return this.each(function(){o(this).css({"filter":"",backgroundImage:""});});}:function(){return this;},hideWhenEmpty:function(){return this.each(function(){o(this)[o(this).html()?"show":"hide"]();});},url:function(){return this.attr("href")||this.attr("src");}});

function k(){
  if(n.parent){return ;}
  n.parent=o("<div id=\"tooltip\"><span></span><div class=\"body\"></div><div class=\"url\"></div></div>").hide().appendTo("body");

  if(o.fn.bgiframe){n.parent.bgiframe();}

  n.title=o("span",n.parent);
  n.body=o("div.body",n.parent);
  n.url=o("div.url",n.parent);
}


function W(p){
  if(this.tSettings.delay){
    G=setTimeout(L,this.tSettings.delay);
  } else {
    L();
  }

  f=!!this.tSettings.track;
  o("body").bind("mousemove",s);
  s(p);
}

function C(){
  if(o.Tooltip.blocked||this==Q||!this.tooltipText){return ;}

  Q=this;
  t=this.tooltipText;

  if(this.tSettings.bodyHandler){
    n.title.hide();
    n.body.html(this.tSettings.bodyHandler.call(this)).show();
  } else {
    if(this.tSettings.showBody){
      var N=t.split(this.tSettings.showBody);
      n.title.html(N.shift()).show();
      n.body.empty();
      for(var S=0,p;p=N[S];S++){
        if(S>0){n.body.append("<br/>");}
        n.body.append(p);
      }
      n.body.hideWhenEmpty();
    } else {
      n.title.html(t).show();
      n.body.hide();
    }
  }

  if(this.tSettings.showURL&&o(this).url()){
    n.url.html(o(this).url().replace("http://","")).show();
  } else {
    n.url.hide();
  }
  n.parent.addClass(this.tSettings.extraClass);
  if(this.tSettings.fixPNG){n.parent.fixPNG();}

  W.apply(this,arguments);
}

function L(){
  G=null;
  n.parent.show();
  s();
}


function s(N){
  if(o.Tooltip.blocked){return ;}

  if(!f&&n.parent.is(":visible")){o("body").unbind("mousemove",s);}

  if(Q==null){
    o("body").unbind("mousemove",s);
    return ;
  }

  var c=n.parent[0].offsetLeft;
  var K=n.parent[0].offsetTop;

  if(N) {
    c=N.pageX+Q.tSettings.left;
    K=N.pageY+Q.tSettings.top;
    n.parent.css({left:c+"px",top:K+"px"});
  }

  var p=T(),S=n.parent[0];

  if(p.x+p.cx<S.offsetLeft+S.offsetWidth){
    c-=S.offsetWidth+20+Q.tSettings.left;
    n.parent.css({left:c+"px"});
  }
  if(p.y+p.cy<S.offsetTop+S.offsetHeight){
    K-=S.offsetHeight+20+Q.tSettings.top;
    n.parent.css({top:K+"px"});
  }
}

function T(){
  return {
    x:o(window).scrollLeft(),
    y:o(window).scrollTop(),
    cx:o(window).width(),
    cy:o(window).height()
  };
}

function u(p){
  if(o.Tooltip.blocked){return ;}
  if(G){clearTimeout(G);}
  Q=null;
  n.parent.hide().removeClass(this.tSettings.extraClass);
  if(this.tSettings.fixPNG){n.parent.unfixPNG();}
}

})(jQuery);

