//Licensed under The MIT License
//Copyright (c) 2008 Jason Frame (jason@onehackoranother.com)
(function(A){A.fn.tipsy=function(C){C=A.extend({fade:false,gravity:"n"},C||{});if(!C.offsetTop){C.offsetTop=0}if(!C.offsetLeft){C.offsetLeft=0}if(!C.header){C.header=""}if(!C.footer){C.footer=""}if(!C.hideTimeout){C.hideTimeout=100}if(!C.showTimeout){C.hideTimeout=0}var B=false;var D=null,E=false;this.hover(function(){var G=A(this).text();var M=C.header.replace("%{link}",G);var L=C.footer.replace("%{link}",G);A.data(this,"cancel.tipsy",true);var H=A.data(this,"active.tipsy");if(!H){A(".tipsy").hide();H=A('<div class="tipsy"><div class="tipsy-inner">'+M+A(this).attr("title")+L+"</div></div>");H.css({position:"absolute",zIndex:100000});A(this).attr("title","");A.data(this,"active.tipsy",H)}else{if(A(this).attr("title")!=""){H.find(".tipsy-inner").html(A(this).attr("title"));A(this).attr("title","")}}var K=A.extend({},A(this).offset(),{width:this.offsetWidth,height:this.offsetHeight});K.top=K.top+C.offsetTop;K.left=K.left+C.offsetLeft;A(".tipsy").hide();H.remove().css({top:0,left:0,visibility:"hidden",display:"block"}).appendTo(document.body);var I=H[0].offsetWidth,J=H[0].offsetHeight;switch(C.gravity.charAt(0)){case"n":H.css({top:K.top+K.height,left:K.left+K.width/2-I/2}).addClass("tipsy-north");break;case"s":H.css({top:K.top-J,left:K.left+K.width/2-I/2}).addClass("tipsy-south");break;case"e":H.css({top:K.top+K.height/2-J/2,left:K.left-I}).addClass("tipsy-east");break;case"w":H.css({top:K.top+K.height/2-J/2,left:K.left+K.width}).addClass("tipsy-west");break}function F(){if(C.fade){H.css({opacity:0,display:"block",visibility:"visible"}).animate({opacity:1})}else{H.css({visibility:"visible"})}}if(C.showTimeout){B=setTimeout(F,C.showTimeout)}else{F()}},function(){clearTimeout(B);A.data(this,"cancel.tipsy",false);var F=this;setTimeout(function(){if(A.data(this,"cancel.tipsy")){return }var G=A.data(F,"active.tipsy");if(C.fade){G.stop().fadeOut(function(){A(this).remove()})}else{G.remove()}},C.hideTimeout)})}})(jQuery);
