/*
 * Jatt - just another tooltip
 * 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/)
 *
 * v2.1  8/22/2010 Converted to a plugin, added enhancements & commented out dhtmltooltip script
 * v2.01 8/29/2009 Added Websnapr.com site screenshot option
 * v2.0  6/10/2009 Combined scripts, added support for dhtmltooltip
 * v1.0  5/8/2008  Original tooltip script by Alen Grakalic
 */

function objClone(b){if(null===b||"object"!=typeof b)return b;var o=b.constructor();for(var a in b)if(b.hasOwnProperty(a))o[a]=b[a];return o}
(function(b){b.jatt=function(o){var a,e=b.extend({},b.jatt.defaultOptions,o);b.jatt.ttrelocate=function(f,h){var c=b(h).outerWidth(),d=b(h).outerHeight(),g={e:[a.xOffset,-d/2,c+a.xOffset,d/2],se:[a.xOffset,a.yOffset,c+a.xOffset,d+a.yOffset],s:[-c/2,a.yOffset,c/2,d+a.yOffset],sw:[-c-a.xOffset,a.yOffset,-a.xOffset,d+a.yOffset],w:[-c-a.xOffset,-d/2,-a.xOffset,d/2],nw:[-c-a.xOffset,-d-a.yOffset,-a.xOffset,-a.yOffset],n:[-c/2,-d-a.yOffset,c/2,-a.yOffset],ne:[a.xOffset,-d-a.yOffset,c+a.xOffset,-a.yOffset]}[a.direction],
m=b(window).scrollTop(),k=b(window).scrollLeft(),j=f.pageX,l=f.pageY;if(!a.followMouse){l=b(f.target);j=l.outerWidth();var i=l.outerHeight();i={e:[j,i/2],se:[j,i],s:[j/2,i],sw:[0,i],w:[0,i/2],nw:[0,0],n:[j/2,0],ne:[j,0]};j=l.offset().left+i[a.direction][0];l=l.offset().top+i[a.direction][1]}i=j+g[0];var n=l+g[1];if(j+g[2]>k+b(window).width()-a.xOffset)i=b(window).width()-c-a.xOffset;if(l+g[3]>m+b(window).height()-a.yOffset)n=l-d-a.yOffset;if(i<k+a.xOffset)i=k+a.xOffset;if(n<m+a.yOffset)n=l+a.yOffset;
if(j>i&&j<i+c&&l>n&&l<n+d)n+=n-d/2-a.yOffset<m+a.yOffset?d/2+a.yOffset:-d/2-a.yOffset;b(h).css({left:i+"px",top:n+"px"})};b.jatt.getMeta=function(f){a=objClone(e);f=f.attr(e.metadata).match(/(\{.*\})/g)||"";if(f!==""){var h,c="";f=f[0].replace(/(\{|\'|\"|\})/g,"");if(f.match("direction|followMouse|content|speed|local|xOffset|yOffset|zIndex")){b.each(f.split(";"),function(d,g){h=g.split(":");if(h[0].match("direction|followMouse|content|speed|local|xOffset|yOffset|zIndex")){var m=b.trim(h[0]),k=b.trim(h[1]);
a[m]=k=="true"||k=="false"?k=="true"?true:false:isNaN(k)?k:parseFloat(k)}else c+=g+";"});f=c}}return[a,f]};(function(){var f=e.live?"live":"bind";b(e.tooltip)[f](e.activate,function(h){var c=b(this),d=e.metadata.toString()=="false"?[e,""]:b.jatt.getMeta(c);a=d[0];var g=c.attr(a.content)===""?c.data("tooltip")||"":c.attr(a.content)||"",m=c.attr("rel")||"",k=c.attr("href")||"";c.data("tooltip",g);c.attr("title","");if(g==="")if(m!=="")g=b(m).html()||"No tooltip found";else if(k!==""){g="Loading...";
var j=b("<div />");j.load(k,function(){b("#"+e.tooltipId).html(j.html())})}d='<div id="'+e.tooltipId+'" style="position:absolute;z-index:'+a.zIndex+";"+d[1]+'">'+g+"</div>";a.local?c.before(d):b("body").append(d);b.jatt.ttrelocate(h,"#"+e.tooltipId);b("#"+e.tooltipId).fadeIn(a.speed)})[f](e.deactivate,function(){b("#"+e.tooltipId).remove()})[f]("mousemove",function(h){a.followMouse&&b.jatt.ttrelocate(h,"#"+e.tooltipId)});b(e.preview+","+e.screenshot)[f](e.activate,function(h){var c=b(this),d=e.metadata.toString()==
"false"?[e,""]:b.jatt.getMeta(c);a=d[0];var g=c.attr(a.content)===""?c.data("tooltip")||"":c.attr(a.content)||"";c.data("tooltip",g);a.content=="title"&&c.attr(a.content,"");d='<div id="'+e.previewId+'" style="position:absolute;z-index:'+a.zIndex+";"+d[1]+'"><img src="';g=g!==""?"<br/>"+g:"";var m=c.is(e.screenshot)&&this.rel=="#"?"http://images.websnapr.com/?url="+this.href:this.rel;d+=c.is(e.preview)?this.href+'" alt="Image preview" />':m+'" alt="URL preview: '+this.href+'" />';d+=g+"</div>";a.local?
c.before(d):b("body").append(d);b("#"+e.previewId).data("options",a);b.jatt.ttrelocate(h,"#"+e.previewId);b("#"+e.previewId).fadeIn(a.speed)})[f](e.deactivate,function(){b("#"+e.previewId).remove()})[f]("mousemove",function(h){a.followMouse&&b.jatt.ttrelocate(h,"#"+e.previewId)})})()};b.jatt.defaultOptions={direction:"n",followMouse:true,content:"title",speed:300,local:false,xOffset:20,yOffset:20,zIndex:1E3,live:false,metadata:"class",activate:"mouseenter focusin",deactivate:"mouseleave focusout",
tooltip:".tooltip",screenshot:"a.screenshot",preview:"a.preview",tooltipId:"tooltip",previewId:"preview"}})(jQuery);

