// tipsy, facebook style tooltips for jquery
// version 1.0.0a
// (c) 2008-2010 jason frame [jason@onehackoranother.com]
// released under the MIT license
(function(b){function j(a,c){this.$element=b(a);this.options=c;this.enabled=true;this.fixTitle()}j.prototype={show:function(){var a=this.getTitle();if(a&&this.enabled){var c=this.tip();c.find(".tipsy-inner")[this.options.html?"html":"text"](a);c[0].className="tipsy";c.remove().css({top:0,left:0,visibility:"hidden",display:"block"}).appendTo(document.body);a=b.extend({},this.$element.offset(),{width:this.$element[0].offsetWidth,height:this.$element[0].offsetHeight});var e=c[0].offsetWidth,h=c[0].offsetHeight, f=typeof this.options.gravity=="function"?this.options.gravity.call(this.$element[0]):this.options.gravity,g;switch(f.charAt(0)){case "n":g={top:a.top+a.height+this.options.offset,left:a.left+a.width/2-e/2};break;case "s":g={top:a.top-h-this.options.offset,left:a.left+a.width/2-e/2};break;case "e":g={top:a.top+a.height/2-h/2,left:a.left-e-this.options.offset};break;case "w":g={top:a.top+a.height/2-h/2,left:a.left+a.width+this.options.offset}}if(f.length==2)g.left=f.charAt(1)=="w"?a.left+a.width/2- 15:a.left+a.width/2-e+15;c.css(g).addClass("tipsy-"+f);this.options.fade?c.stop().css({opacity:0,display:"block",visibility:"visible"}).animate({opacity:this.options.opacity}):c.css({visibility:"visible",opacity:this.options.opacity})}},hide:function(){this.options.fade?this.tip().stop().fadeOut(function(){b(this).remove()}):this.tip().remove()},fixTitle:function(){var a=this.$element;if(a.attr("title")||typeof a.attr("original-title")!="string")a.attr("original-title",a.attr("title")||"").removeAttr("title")}, getTitle:function(){var a,c=this.$element,e=this.options;this.fixTitle();e=this.options;if(typeof e.title=="string")a=c.attr(e.title=="title"?"original-title":e.title);else if(typeof e.title=="function")a=e.title.call(c[0]);return(a=(""+a).replace(/(^\s*|\s*$)/,""))||e.fallback},tip:function(){if(!this.$tip)this.$tip=b('<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.options=this.$element=null}},enable:function(){this.enabled=true},disable:function(){this.enabled=false},toggleEnabled:function(){this.enabled=!this.enabled}};b.fn.tipsy=function(a){function c(d){var i=b.data(d,"tipsy");if(!i){i=new j(d,b.fn.tipsy.elementOptions(d,a));b.data(d,"tipsy",i)}return i}function e(){var d=c(this);d.hoverState="in";if(a.delayIn==0)d.show();else{d.fixTitle();setTimeout(function(){d.hoverState=="in"&&d.show()},a.delayIn)}}function h(){var d=c(this);d.hoverState="out"; a.delayOut==0?d.hide():setTimeout(function(){d.hoverState=="out"&&d.hide()},a.delayOut)}if(a===true)return this.data("tipsy");else if(typeof a=="string"){var f=this.data("tipsy");f&&f[a]();return this}a=b.extend({},b.fn.tipsy.defaults,a);a.live||this.each(function(){c(this)});if(a.trigger!="manual"){f=a.live?"live":"bind";var g=a.trigger=="hover"?"mouseleave":"blur";this[f](a.trigger=="hover"?"mouseenter":"focus",e)[f](g,h)}return this};b.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"};b.fn.tipsy.elementOptions=function(a,c){return b.metadata?b.extend({},c,b(a).metadata()):c};b.fn.tipsy.autoNS=function(){return b(this).offset().top>b(document).scrollTop()+b(window).height()/2?"s":"n"};b.fn.tipsy.autoWE=function(){return b(this).offset().left>b(document).scrollLeft()+b(window).width()/2?"e":"w"}})(jQuery);
