/*
 * jQuery Simple Tooltip 0.9.1
 * Copyright (c) 2009 Pierre Bertet (pierrebertet.net)
 * Licensed under the MIT (MIT-LICENSE.txt)
 *
*/

(function(d){function m(b){if(b=d(b).attr("href").match(/#.+/))var a=d(b[0]);return a}function n(b){b.appendTo(document.body).data("width",b.outerWidth()).data("height",b.outerHeight()).css({position:"absolute",zIndex:"9998",display:"none"}).find("a[rel=close]").click(function(a){a.preventDefault();b.trigger("hide")}).end().data("init",true)}function i(b){b.type=="click"&&b.preventDefault();var a=b.data.options,e=d(b.data.target);if(!a.customTooltipCache&&e.data("$tooltip")){e.data("$tooltip").remove(); e.data("$tooltip",false)}e.data("$tooltip")||e.data("$tooltip",d(a.customTooltip(e.get(0))));var c=e.data("$tooltip");c.data("init")||n(c);var j=d(window).width(),k=d(window).height(),g=d(window).scrollTop(),h=d(window).scrollLeft();c.unbind("show").unbind("hide");a.showEffect&&a.showEffect.match(/^fadeIn|slideDown|show$/)?c.bind("show",function(){c[a.showEffect](200);a.showCallback(e[0],this)}):c.bind("show",function(){c.show();a.showCallback(e[0],this)});a.hideEffect&&a.hideEffect.match(/^fadeOut|slideUp|hide$/)? c.bind("hide",function(){a.hideCallback(e[0],this);c[a.hideEffect](200)}):c.bind("hide",function(){a.hideCallback(e[0],this);c.hide()});var f=b.pageX-8;b=b.pageY-8;if(f<h+a.margin)f=h+a.margin;else if(f+c.data("width")>h+j-a.margin)f=h+j-c.data("width")-a.margin;if(b<g+a.margin)b=g+a.margin;else if(b+c.data("height")>g+k-a.margin)b=g+k-c.data("height")-a.margin;if(a.hideDelay>0&&a.hideOnLeave){var l;c.hover(function(){window.clearTimeout(l)},function(){l=window.setTimeout(function(){c.trigger("hide").unbind("mouseenter, mouseleave")}, a.hideDelay*1E3)})}else a.hideOnLeave&&c.bind("mouseleave",function(){c.trigger("hide").unbind("mouseleave")});c.css({left:f+"px",top:b+"px"}).trigger("show")}d.fn.simpletooltip=function(b){var a=d.extend({hideOnLeave:true,margin:5,showEffect:false,hideEffect:false,click:false,hideDelay:0,showDelay:0.1,showCallback:function(){},hideCallback:function(){},customTooltip:false,customTooltipCache:true},b);this.each(function(){d.isFunction(a.customTooltip)||d(this).data("$tooltip",m(this).hide());if(a.click)d(this).bind("click", {options:a,target:this},i);else{var e;d(this).bind("mouseenter",{options:a,target:this},function(c){e=window.setTimeout(function(){i(c)},a.showDelay*1E3)}).bind("mouseleave",function(){window.clearTimeout(e)})}});return this}})(jQuery);