(function(B){B.tools=B.tools||{version:"v1.2.5"},B.tools.tooltip={conf:{effect:"toggle",fadeOutSpeed:"fast",predelay:0,delay:30,opacity:1,tip:0,position:["top","center"],offset:[0,0],relative:!1,cancelDefault:!0,events:{def:"mouseenter,mouseleave",input:"focus,blur",widget:"focus mouseenter,blur mouseleave",tooltip:"mouseenter,mouseleave"},layout:"<div/>",tipClass:"tooltip"},addEffect:function(E,G,F){A[E]=[G,F]
}};
var A={toggle:[function(F){var E=this.getConf(),H=this.getTip(),G=E.opacity;
G<1&&H.css({opacity:G}),H.show(),F.call()
},function(E){this.getTip().hide(),E.call()
}],fade:[function(F){var E=this.getConf();
this.getTip().fadeTo(E.fadeInSpeed,E.opacity,F)
},function(E){this.getTip().fadeOut(this.getConf().fadeOutSpeed,E)
}]};
function D(E,L,K){var J=K.relative?E.position().top:E.offset().top,I=K.relative?E.position().left:E.offset().left,H=K.position[0];
J-=L.outerHeight()-K.offset[0],I+=E.outerWidth()+K.offset[1],/iPad/i.test(navigator.userAgent)&&(J-=B(window).scrollTop());
var G=L.outerHeight()+E.outerHeight();
H=="center"&&(J+=G/2),H=="bottom"&&(J+=G),H=K.position[1];
var F=L.outerWidth()+E.outerWidth();
H=="center"&&(I-=F/2),H=="left"&&(I-=F);
return{top:J,left:I}
}function C(S,R){var Q=this,P=S.add(Q),O,N=0,M=0,L=S.attr("title"),K=S.attr("data-tooltip"),J=A[R.effect],I,H=S.is(":input"),G=H&&S.is(":checkbox, :radio, select, :button, :submit"),F=S.attr("type"),E=R.events[F]||R.events[H?G?"widget":"input":"def"];
if(!J){throw'Nonexistent effect "'+R.effect+'"'
}E=E.split(/,\s*/);
if(E.length!=2){throw"Tooltip: bad events configuration for "+F
}S.bind(E[0],function(T){clearTimeout(N),R.predelay?M=setTimeout(function(){Q.show(T)
},R.predelay):Q.show(T)
}).bind(E[1],function(T){clearTimeout(M),R.delay?N=setTimeout(function(){Q.hide(T)
},R.delay):Q.hide(T)
}),L&&R.cancelDefault&&(S.removeAttr("title"),S.data("title",L)),B.extend(Q,{show:function(T){if(!O){K?O=B(K):R.tip?O=B(R.tip).eq(0):L?O=B(R.layout).addClass(R.tipClass).appendTo(document.body).hide().append(L):(O=S.next(),O.length||(O=S.parent().next()));
if(!O.length){throw"Cannot find tooltip for "+S
}}if(Q.isShown()){return Q
}O.stop(!0,!0);
var V=D(S,O,R);
R.tip&&O.html(S.data("title")),T=T||B.Event(),T.type="onBeforeShow",P.trigger(T,[V]);
if(T.isDefaultPrevented()){return Q
}V=D(S,O,R),O.css({position:"absolute",top:V.top,left:V.left}),I=!0,J[0].call(Q,function(){T.type="onShow",I="full",P.trigger(T)
});
var U=R.events.tooltip.split(/,\s*/);
O.data("__set")||(O.bind(U[0],function(){clearTimeout(N),clearTimeout(M)
}),U[1]&&!S.is("input:not(:checkbox, :radio), textarea")&&O.bind(U[1],function(W){W.relatedTarget!=S[0]&&S.trigger(E[1].split(" ")[0])
}),O.data("__set",!0));
return Q
},hide:function(T){if(!O||!Q.isShown()){return Q
}T=T||B.Event(),T.type="onBeforeHide",P.trigger(T);
if(!T.isDefaultPrevented()){I=!1,A[R.effect][1].call(Q,function(){T.type="onHide",P.trigger(T)
});
return Q
}},isShown:function(T){return T?I=="full":I
},getConf:function(){return R
},getTip:function(){return O
},getTrigger:function(){return S
}}),B.each("onHide,onBeforeShow,onShow,onBeforeHide".split(","),function(T,U){B.isFunction(R[U])&&B(Q).bind(U,R[U]),Q[U]=function(V){V&&B(Q).bind(U,V);
return Q
}
})
}B.fn.tooltip=function(E){var F=this.data("tooltip");
if(F){return F
}E=B.extend(!0,{},B.tools.tooltip.conf,E),typeof E.position=="string"&&(E.position=E.position.split(/,?\s/)),this.each(function(){F=new C(B(this),E),B(this).data("tooltip",F)
});
return E.api?F:this
}
})(jQuery);
