(function(d){d.tools=d.tools||{version:"@VERSION"};d.tools.tooltip={conf:{effect:"toggle",fadeOutSpeed:"fast",predelay:0,delay:30,opacity:1,tip:0,position:["top","center"],offset:[0,0],relative:false,cancelDefault:true,events:{def:"mouseenter,mouseleave",input:"focus,blur",widget:"focus mouseenter,blur mouseleave",tooltip:"mouseenter,mouseleave"},layout:"<div/>",tipClass:"tooltip"},addEffect:function(e,g,f){c[e]=[g,f];}};var c={toggle:[function(e){var f=this.getConf(),g=this.getTip(),h=f.opacity;if(h<1){g.css({opacity:h});}g.show();e.call();},function(e){this.getTip().hide();e.call();}],fade:[function(e){var f=this.getConf();this.getTip().fadeTo(f.fadeInSpeed,f.opacity,e);},function(e){this.getTip().fadeOut(this.getConf().fadeOutSpeed,e);}]};function b(g,i,f){var k=f.relative?g.position().top:g.offset().top,j=f.relative?g.position().left:g.offset().left,l=f.position[0];k-=i.outerHeight()-f.offset[0];j+=g.outerWidth()+f.offset[1];var e=i.outerHeight()+g.outerHeight();if(l=="center"){k+=e/2;}if(l=="bottom"){k+=e;}l=f.position[1];var h=i.outerWidth()+g.outerWidth();if(l=="center"){j-=h/2;}if(l=="left"){j-=h;}return{top:k,left:j};}function a(h,i){var q=this,g=h.add(q),n,f=0,p=0,l=h.attr("title"),r=c[i.effect],m,k=h.is(":input"),e=k&&h.is(":checkbox, :radio, select, :button, :submit"),j=h.attr("type"),o=i.events[j]||i.events[k?(e?"widget":"input"):"def"];if(!r){throw'Nonexistent effect "'+i.effect+'"';}o=o.split(/,\s*/);if(o.length!=2){throw"Tooltip: bad events configuration for "+j;}h.bind(o[0],function(s){clearTimeout(f);if(i.predelay){p=setTimeout(function(){q.show(s);},i.predelay);}else{q.show(s);}}).bind(o[1],function(s){clearTimeout(p);if(i.delay){f=setTimeout(function(){q.hide(s);},i.delay);}else{q.hide(s);}});if(l&&i.cancelDefault){h.removeAttr("title");h.data("title",l);}d.extend(q,{show:function(t){if(!n){if(l){n=d(i.layout).addClass(i.tipClass).appendTo(document.body).hide().append(l);}else{if(i.tip){n=d(i.tip).eq(0);}else{n=h.next();if(!n.length){n=h.parent().next();}}}if(!n.length){throw"Cannot find tooltip for "+h;}}if(q.isShown()){return q;}n.stop(true,true);var u=b(h,n,i);t=t||d.Event();t.type="onBeforeShow";g.trigger(t,[u]);if(t.isDefaultPrevented()){return q;}u=b(h,n,i);n.css({position:"absolute",top:u.top,left:u.left});m=true;r[0].call(q,function(){t.type="onShow";m="full";g.trigger(t);});var s=i.events.tooltip.split(/,\s*/);n.bind(s[0],function(){clearTimeout(f);clearTimeout(p);});if(s[1]&&!h.is("input:not(:checkbox, :radio), textarea")){n.bind(s[1],function(v){if(v.relatedTarget!=h[0]){h.trigger(o[1].split(" ")[0]);}});}return q;},hide:function(s){if(!n||!q.isShown()){return q;}s=s||d.Event();s.type="onBeforeHide";g.trigger(s);if(s.isDefaultPrevented()){return;}m=false;c[i.effect][1].call(q,function(){s.type="onHide";m=false;g.trigger(s);});return q;},isShown:function(s){return s?m=="full":m;},getConf:function(){return i;},getTip:function(){return n;},getTrigger:function(){return h;}});d.each("onHide,onBeforeShow,onShow,onBeforeHide".split(","),function(t,s){if(d.isFunction(i[s])){d(q).bind(s,i[s]);}q[s]=function(u){d(q).bind(s,u);return q;};});}d.fn.tooltip=function(e){var f=this.data("tooltip");if(f){return f;}e=d.extend(true,{},d.tools.tooltip.conf,e);if(typeof e.position=="string"){e.position=e.position.split(/,?\s/);}this.each(function(){f=new a(d(this),e);d(this).data("tooltip",f);});return e.api?f:this;};})(jQuery);
