/* Wayfarer Tooltip
 * Version 1.0.1
 * Author Abel Mohler
 * URI: http://www.wayfarerweb.com/wtooltip.php
 * Released with the MIT License: http://www.wayfarerweb.com/mit.php
 */
(function(a){a.fn.wTooltip=function(f,s){f=a.extend({content:null,ajax:null,follow:true,auto:true,fadeIn:0,fadeOut:0,appendTip:"body",degrade:false,offsetY:10,offsetX:1,style:{},className:null,id:null,callBefore:function(u,p,o){},callAfter:function(u,p,o){},clickAction:function(p,o){a(p).hide()},delay:0,timeout:0,cloneable:false},f||{});if(!f.style&&typeof f.style!="object"){f.style={};f.style.zIndex="1000"}else{f.style=a.extend({border:"1px solid gray",background:"#edeef0",color:"#000",padding:"10px",zIndex:"1000",textAlign:"left"},f.style||{})}if(typeof s=="function"){f.callAfter=s||f.callAfter}f.style.display="none",f.style.position="absolute";var n,m,r,c,l={},b=true,e=false,q=false,t=document.createElement("div"),i=document.getElementsByTagName("html")[0],g=(typeof document.body.style.maxWidth=="undefined")?true:false,k=(typeof a.talk=="function"&&typeof a.listen=="function")?true:false;if(f.id){t.id=f.id}if(f.className){t.className=f.className}f.degrade=(f.degrade&&g)?true:false;for(var d in f.style){t.style[d]=f.style[d]}function j(o){if(o){if(f.degrade){a(t).html(f.content.replace(/<\/?[^>]+>/gi,""))}else{a(t).html(f.content)}}}if(f.ajax){a.get(f.ajax,function(o){if(o){f.content=o}j(f.content)})}function h(p){function u(v){if(n&&!f.content){v.title=n;n=null}}function o(){if(!e&&f.auto){clearInterval(c);if(f.fadeOut){a(t).fadeOut(f.fadeOut,function(){u(p)})}else{u(p);t.style.display="none"}}if(typeof f.callAfter=="function"){f.callAfter(t,p,f)}if(k){f=a.listen(f)}}if(f.timeout>0){r=setTimeout(function(){o()},f.timeout)}else{o()}}a(t).hover(function(){e=true},function(){e=false;h(l)});if(k){f.key=t;f.plugin="wTooltip";f.channel="wayfarer";a.talk(f)}j(f.content&&!f.ajax);a(t).appendTo(f.appendTip);return this.each(function(){this.onmouseover=function(u){var p=this;clearTimeout(r);if(this.title&&!f.degrade&&!f.content){n=this.title;this.title=""}if(f.content&&f.degrade){this.title=t.innerHTML}function o(){if(typeof f.callBefore=="function"){f.callBefore(t,p,f)}if(k){f=a.listen(f)}if(f.auto){var v;if(f.content){if(!f.degrade){v="block"}}else{if(n&&!f.degrade){a(t).html(n);v="block"}else{v="none"}}if(v=="block"&&f.fadeIn){a(t).fadeIn(f.fadeIn)}else{t.style.display=v}}}if(f.delay>0){m=setTimeout(function(){o()},f.delay)}else{o()}};this.onmousemove=function(y){var w=(y)?y:window.event,v=this;l=this;if(f.follow||b){var z=i.scrollTop;var A=i.scrollLeft;var x=w.clientY+z+f.offsetY;var p=w.clientX+A+f.offsetX;var o=a(window).width()+A-a(t).outerWidth();var u=a(window).height()+z-a(t).outerHeight();q=(x>u||p>o)?true:false;if(p-A<=0&&f.offsetX<0){p=A}else{if(p>o){p=o}}if(x-z<=0&&f.offsetY<0){x=z}else{if(x>u){x=u}}t.style.top=x+"px";t.style.left=p+"px";b=false}};this.onmouseout=function(){clearTimeout(m);var o=this;b=true;if(!f.follow||q||(f.offsetX<0&&f.offsetY<0)){setTimeout(function(){c=setInterval(function(){h(o)},1)},1)}else{h(this)}};if(typeof f.clickAction=="function"){this.onclick=function(){f.clickAction(t,this)}}})}})(jQuery);