/*
 * Jatt - just another tooltip v2.8.2 min
 * http://github.com/Mottie/Jatt
 * by Rob Garrison (aka Mottie)
 *
 * based on tooltip by Alen Grakalic (http://cssglobe.com/post/1695/easiest-tooltip-and-image-preview-using-jquery)
 * tooltip modification by Rob G, aka Mottie (http://wowmotty.blogspot.com/)
 *
 */

(function(c,v,t){c.jatt=function(w){var f,r,s=[],u=c("body"),m=c(t),p=c(v),d=c.extend({},c.jatt.defaultOptions,w);c.jatt.ttrelocate=function(f,h){var j=c("#"+h),b=j.outerWidth(),e=j.outerHeight(),a=j.data("options")||d,q={e:[a.xOffset,-e/2,b+a.xOffset,e/2],se:[a.xOffset,a.yOffset,b+a.xOffset,e+a.yOffset],s:[-b/2,a.yOffset,b/2,e+a.yOffset],sw:[-b-a.xOffset,a.yOffset,-a.xOffset,e+a.yOffset],w:[-b-a.xOffset,-e/2,-a.xOffset,e/2],nw:[-b-a.xOffset,-e-a.yOffset,-a.xOffset,-a.yOffset],n:[-b/2,-e-a.yOffset, b/2,-a.yOffset],ne:[a.xOffset,-e-a.yOffset,b+a.xOffset,-a.yOffset]}[a.direction],k=p.scrollTop(),m=p.scrollLeft(),i=c(f.target),g=f.pageX||i.position().left+i.width()/2,l=f.pageY||i.position().top+i.height()/2;a.followMouse||(g=i.outerWidth(),l=i.outerHeight(),l={e:[g,l/2],se:[g,l],s:[g/2,l],sw:[0,l],w:[0,l/2],nw:[0,0],n:[g/2,0],ne:[g,0]},g=i.offset().left+l[a.direction][0],l=i.offset().top+l[a.direction][1]);var i=g+q[0],o=l+q[1];g+q[2]>m+p.width()-a.xOffset&&(i=p.width()-b-a.xOffset);l+q[3]>k+p.height()- a.yOffset&&(o=l-e-a.yOffset);i<m+a.xOffset&&(i=m+a.xOffset);o<k+a.yOffset&&(o=l+a.yOffset);g>i&&g<i+b&&l>o&&l<o+e&&(o+=o-e/2-a.yOffset<k+a.yOffset?e/2+a.yOffset:-e/2-a.yOffset);j.css({left:i+"px",top:o+"px"})};c.jatt.getMeta=function(n){f=c.extend({},d);var h,j=[],b=n.attr(d.metadata)||"",b=b.match(/(\{.*\})/g)?b.match(/(\{.*\})/g)[0]:n.attr(d.metadata)||"",b=b.match("width|background|color|border|direction|followMouse|content|speed|local|xOffset|yOffset|zIndex")?b:n.attr("data-jatt")||"";b!==""&& (b=b.replace(/(\{|\'|\"|\})/g,""),b.match("direction|followMouse|content|speed|local|xOffset|yOffset|zIndex")&&(c.each(b.split(";"),function(b,a){h=a.split(":");if(h[0].match("direction|followMouse|content|speed|local|xOffset|yOffset|zIndex")){var d=c.trim(h[0]),k=c.trim(h[1]);f[d]=k=="true"||k=="false"?k=="true"?!0:!1:isNaN(k)?k:parseFloat(k)}else j.push(a)}),b=j.join(";")));return[f,b]};c.jatt.removeTooltips=function(){for(c("#"+d.previewId+", #"+d.tooltipId).remove();c("#"+d.previewId+", #"+d.tooltipId).length> 0;)c("#"+d.previewId+", #"+d.tooltipId).remove()};c.jatt.preloadContent=function(f){var h,j,b,e,a,m=[],k=c(d.tooltip);for(a=f.length;a--;)h=t.createElement("img"),h.src=f[a],s.push(h);k.each(function(a){j=c(this);this.tagName==="A"&&j.is(d.preloadContent)&&(e=c(this).attr("href")||"",e!==""&&!e.match(/^#/)&&(b=c('<div rel="'+a+'" />'),m.push(b),b.load(e,function(){k.eq(b.attr("rel")).data("tooltip",b.html())})))})};(function(){var n=d.live?"live":"bind",h=[];c.each("initialized.jatt beforeReveal.jatt revealed.jatt hidden.jatt".split(" "), function(f,b){var e=b.split(".")[0];c.isFunction(d[e])&&m.bind(b,d[e])});c(d.tooltip)[n](d.activate,function(j){c.jatt.removeTooltips();var b,e,a,h,k,n,i,g=c(this);b=d.metadata.toString()==="false"?[d,""]:c.jatt.getMeta(g);m.trigger("initialized.jatt",g);f=b[0];e=g.attr(f.content)===""?g.data("tooltip")||"":g.attr(f.content)||"";h=g.attr("rel")||"";k=g.attr("href")||"";g.data("tooltip",e);g.attr("title","");b='<div id="'+d.tooltipId+'" style="position:absolute;z-index:'+f.zIndex+";"+b[1]+'"><span class="body"></span><span class="close">x</span></div>'; f.local?g.before(b):u.append(b);a=c("#"+d.tooltipId);if(e==="")if(h!=="")e=c(h).html()||d.notFound;else if(k!=="")e=d.loading,n=c("<div />"),n.load(k,function(){i=n.html();s=d.cacheData?i:"";a.hide().find(".body").html(i);g.data("tooltip",s);c.jatt.ttrelocate(j,d.tooltipId);a.fadeIn(f.speed)});a.data("options",f).find(".body").html(e);c.jatt.ttrelocate(j,d.tooltipId);g.is(d.sticky)&&a.find(".close").show().click(function(){c.jatt.removeTooltips()});m.trigger("beforeReveal.jatt",g);a.fadeIn(f.speed); m.trigger("revealed.jatt",g)})[n](d.deactivate,function(){c(this).is(d.sticky)||(c.jatt.removeTooltips(),m.trigger("hidden.jatt",this))})[n]("mousemove",function(j){c("#"+d.tooltipId).length&&f.followMouse&&c.jatt.ttrelocate(j,d.tooltipId)});r=function(j,b,e){m.trigger("initialized.jatt",b);var a,h=d.metadata.toString()=="false"?[d,""]:c.jatt.getMeta(b);f=h[0];a=b.attr(f.content)===""?b.data("tooltip")||"":b.attr(f.content)||"";b.data("tooltip",a);f.content==="title"&&b.attr(f.content,"");e='<div id="'+ d.previewId+'" style="position:absolute;z-index:'+f.zIndex+";"+h[1]+'"><span class="body"><img src="'+e;e+=a!==""?"<br/>"+a:"";e+='</span><span class="close">x</span></div>';f.local?b.before(e):u.append(e);a=c("#"+d.previewId);m.trigger("beforeReveal.jatt",b);a.hide().data("options",f).fadeIn(f.speed);b.is(d.sticky)&&a.find(".close").show().click(function(){c.jatt.removeTooltips()});c.jatt.ttrelocate(j,d.previewId);m.trigger("revealed.jatt",b)};c(d.preview)[n](d.activate,function(f){c.jatt.removeTooltips(); r(f,c(this),c(this).attr("href")+'" alt="'+d.imagePreview+'" />')}).each(function(){h.push(c(this).attr("href"))});c(d.screenshot)[n](d.activate,function(f){c.jatt.removeTooltips();var b=c(this),e=b.attr("rel")==="#"?d.websitePreview+b.attr("href"):b.attr("rel");e+='" alt="'+d.siteScreenshot+b.attr("href")+'" />';r(f,b,e)}).each(function(){var f=c(this);h.push(f.attr("rel")==="#"?d.websitePreview+f.attr("href"):f.attr("rel"))});c(d.preview+","+d.screenshot)[n](d.deactivate,function(){c(this).is(d.sticky)|| (c.jatt.removeTooltips(),m.trigger("hidden.jatt",this))})[n]("mousemove",function(h){c("#"+d.previewId).length&&f.followMouse&&c.jatt.ttrelocate(h,d.previewId)});c.jatt.preloadContent(h)})()};c.jatt.defaultOptions={direction:"n",followMouse:!0,content:"title",speed:300,local:!1,xOffset:20,yOffset:20,zIndex:1E3,live:!1,metadata:"class",activate:"mouseenter focusin",deactivate:"mouseleave focusout",cacheData:!0,websitePreview:"http://api1.thumbalizr.com/?width=250&url=",loading:"Loading...",notFound:"No tooltip found", imagePreview:"Image preview",siteScreenshot:"URL preview: ",tooltip:".tooltip",screenshot:"a.screenshot",preview:"a.preview",preloadContent:".preload",sticky:".sticky",tooltipId:"tooltip",previewId:"preview"}})(jQuery,this,document);

