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