(function(n){function t(n){(n.attr("title")||typeof n.attr("original-title")!="string")&&n.attr("original-title",n.attr("title")||"").removeAttr("title")}function i(i,r){this.$element=n(i);this.options=r;this.enabled=!0;t(this.$element)}i.prototype={show:function(){var o=this.getTitle(),i;if(o&&this.enabled){i=this.tip();i.find(".tipsy-inner")[this.options.html?"html":"text"](o);i[0].className="tipsy";i.remove().css({top:0,left:0,visibility:"hidden",display:"block"}).appendTo(document.body);var t=n.extend({},this.$element.offset(),{width:this.$element[0].offsetWidth,height:this.$element[0].offsetHeight}),u=i[0].offsetWidth,e=i[0].offsetHeight,f=typeof this.options.gravity=="function"?this.options.gravity.call(this.$element[0]):this.options.gravity,r;switch(f.charAt(0)){case"n":r={top:t.top+t.height+this.options.offset,left:t.left+t.width/2-u/2};break;case"s":r={top:t.top-e-this.options.offset,left:t.left+t.width/2-u/2};break;case"e":r={top:t.top+t.height/2-e/2,left:t.left-u-this.options.offset};break;case"w":r={top:t.top+t.height/2-e/2,left:t.left+t.width+this.options.offset}}f.length==2&&(r.left=f.charAt(1)=="w"?t.left+t.width/2-15:t.left+t.width/2-u+15);i.css(r).addClass("tipsy-"+f);this.options.fade?i.stop().css({opacity:0,display:"block",visibility:"visible"}).animate({opacity:this.options.opacity}):i.css({visibility:"visible",opacity:this.options.opacity})}},hide:function(){this.options.fade?this.tip().stop().fadeOut(function(){n(this).remove()}):this.tip().remove()},getTitle:function(){var r=this.$element,n=this.options,i;return t(r),n=this.options,typeof n.title=="string"?i=r.attr(n.title=="title"?"original-title":n.title):typeof n.title=="function"&&(i=n.title.call(r[0])),i=(""+i).replace(/(^\s*|\s*$)/,""),i||n.fallback},tip:function(){return this.$tip||(this.$tip=n('<div class="tipsy"><\/div>').html('<div class="tipsy-arrow"><\/div><div class="tipsy-inner"/><\/div>')),this.$tip},validate:function(){this.$element[0].parentNode||(this.hide(),this.$element=null,this.options=null)},enable:function(){this.enabled=!0},disable:function(){this.enabled=!1},toggleEnabled:function(){this.enabled=!this.enabled}};n.fn.tipsy=function(t){function r(r){var u=n.data(r,"tipsy");return u||(u=new i(r,n.fn.tipsy.elementOptions(r,t)),n.data(r,"tipsy",u)),u}function f(){var n=r(this);n.hoverState="in";t.delayIn==0?n.show():setTimeout(function(){n.hoverState=="in"&&n.show()},t.delayIn)}function e(){var n=r(this);n.hoverState="out";t.delayOut==0?n.hide():setTimeout(function(){n.hoverState=="out"&&n.hide()},t.delayOut)}if(t===!0)return this.data("tipsy");if(typeof t=="string")return this.data("tipsy")[t]();if(t=n.extend({},n.fn.tipsy.defaults,t),t.live||this.each(function(){r(this)}),t.trigger!="manual"){var u=t.live?"live":"bind",o=t.trigger=="hover"?"mouseenter":"focus",s=t.trigger=="hover"?"mouseleave":"blur";this[u](o,f)[u](s,e)}return this};n.fn.tipsy.defaults={delayIn:0,delayOut:0,fade:!1,fallback:"",gravity:"w",html:!1,live:!1,offset:0,opacity:.9,title:"title",trigger:"hover"};n.fn.tipsy.elementOptions=function(t,i){return n.metadata?n.extend({},i,n(t).metadata()):i};n.fn.tipsy.autoNS=function(){return n(this).offset().top>n(document).scrollTop()+n(window).height()/2?"s":"n"};n.fn.tipsy.autoWE=function(){return n(this).offset().left>n(document).scrollLeft()+n(window).width()/2?"e":"w"}})(jQuery)