(function(n){n.tooltipsy=function(t,i){this.options=i,this.$el=n(t),this.title=this.$el.attr("title")||"",this.$el.attr("title",""),this.random=parseInt(Math.random()*1e4),this.ready=!1,this.shown=!1,this.width=0,this.height=0,this.delaytimer=null,this.$el.data("tooltipsy",this),this.init()},n.tooltipsy.prototype.init=function(){var t=this;t.settings=n.extend({},t.defaults,t.options),t.settings.delay=parseInt(t.settings.delay),typeof t.settings.content=="function"&&t.readify(),t.$el.bind("mouseenter",function(n){t.settings.delay>0?t.delaytimer=window.setTimeout(function(){t.enter(n)},t.settings.delay):t.enter(n)}).bind("mouseleave",function(n){window.clearTimeout(t.delaytimer),t.delaytimer=null,t.leave(n)})},n.tooltipsy.prototype.enter=function(t){var i=this,u,r;i.ready===!1&&i.readify(),i.shown===!1&&(function(n){var i=0,t;for(t in n)n.hasOwnProperty(t)&&i++;return i}(i.settings.css)>0&&i.$tip.css(i.settings.css),i.width=i.$tipsy.outerWidth(),i.height=i.$tipsy.outerHeight()),i.settings.alignTo==="cursor"?(r=[t.pageX+i.settings.offset[0],t.pageY+i.settings.offset[1]],u=r[0]+i.width>n(window).width()?{top:r[1]+"px",right:r[0]+"px",left:"auto"}:{top:r[1]+"px",left:r[0]+"px",right:"auto"}):r=[function(n){return i.settings.offset[0]<0?n.left-Math.abs(i.settings.offset[0])-i.width:i.settings.offset[0]===0?n.left-(i.width-i.$el.outerWidth())/2:n.left+i.$el.outerWidth()+i.settings.offset[0]}(i.offset(i.$el[0])),function(n){return i.settings.offset[1]<0?n.top-Math.abs(i.settings.offset[1])-i.height:i.settings.offset[1]===0?n.top-(i.height-i.$el.outerHeight())/2:n.top+i.$el.outerHeight()+i.settings.offset[1]}(i.offset(i.$el[0]))],i.$tipsy.css({top:r[1]+"px",left:r[0]+"px"}),i.settings.show(t,i.$tipsy.stop(!0,!0))},n.tooltipsy.prototype.leave=function(n){var t=this;if(n.relatedTarget===t.$tip[0]){t.$tip.bind("mouseleave",function(n){if(n.relatedTarget===t.$el[0])return;t.settings.hide(n,t.$tipsy.stop(!0,!0))});return}t.settings.hide(n,t.$tipsy.stop(!0,!0))},n.tooltipsy.prototype.readify=function(){this.ready=!0,this.$tipsy=n('<div id="tooltipsy'+this.random+'" style="position:absolute;z-index:2147483647;display:none">').appendTo("body"),this.$tip=n('<div class="'+this.settings.className+'">').appendTo(this.$tipsy).html(this.settings.content!=""?this.settings.content:this.title),this.$tip.data("rootel",this.$el)},n.tooltipsy.prototype.offset=function(n){var t=ot=0;if(n.offsetParent)do n.tagName!="BODY"&&(t+=n.offsetLeft-n.scrollLeft,ot+=n.offsetTop-n.scrollTop);while(n=n.offsetParent);return{left:t,top:ot}},n.tooltipsy.prototype.defaults={alignTo:"element",offset:[0,-1],content:"",show:function(n,t){t.fadeIn(100)},hide:function(n,t){t.fadeOut(100)},css:{},className:"tooltipsy",delay:200},n.fn.tooltipsy=function(t){return this.each(function(){new n.tooltipsy(this,t)})}})(jQuery)
