(function(c){c.fn.wtooltip=function(f,e){if(typeof f==="object"){e=f;
}else{if(typeof f==="string"){var d=[];
var g=this.each(function(){var h=c(this).data("_wtooltip");
if(h){if(f==="title"){h.settings.html?h.content.html(e):h.content.text(e);
}else{if(c.fn.wtooltip.defaultSettings[f]!==undefined){if(e!==undefined){h.settings[f]=e;
}else{d.push(h.settings[f]);
}}}}});
if(d.length===1){return d[0];
}if(d.length>0){return d;
}else{return g;
}}}return this.each(function(){var j=c(this);
var i=c.extend({},c.fn.wtooltip.defaultSettings,e||{});
i.title=i.title||j.attr("title")||"No title set";
var h=new a();
var k=new b(i,h,j);
k.generate();
k.appendToBody();
j.removeAttr("title");
if(i.position=="default"){j.mousestop(function(l){k.move(l);
k.hoverOn();
},{timeToStop:i.timeToStop,onMouseout:function(){k.hoverOff();
},onStopMove:function(){k.hoverOff();
}});
}else{if(i.position=="mouse"){j.mouseover(function(){k.hoverOn();
}).mouseout(function(){k.hoverOff();
}).mousemove(function(l){k.move(l);
});
}else{j.mouseover(function(){k.setBestPosition(j);
k.hoverOn();
}).mouseout(function(){k.hoverOff();
});
}}j.data("_wtooltip",k);
});
};
c.fn.wtooltip.defaultSettings={position:"default",timeToStop:null,theme:"cream",opacity:0.8,title:null,fadeIn:0,fadeOut:0,delayIn:0,delayOut:0,width:null,height:null,offsetX:8,offsetY:9,html:true};
function a(){return this;
}a.prototype={set:function(d,e){this.timer=setTimeout(d,e);
},clear:function(){clearTimeout(this.timer);
}};
function b(e,d,f){this.tooltip=null;
this.$elem=f;
this.content=null;
this.hover=false;
this.shown=false;
this.settings=e;
this.eventScheduler=d;
return this;
}b.prototype={generate:function(){if(this.tooltip){return this.tooltip;
}this.content=c('<div class="_wtooltip_content"></div>').css({width:this.settings.width||"",height:this.settings.height||"",whiteSpace:this.settings.width==null&&this.settings.height==null?"nowrap":"normal"});
this.settings.html?this.content.html(this.settings.title):this.content.text(this.settings.title);
var d=c('<div class="_wtooltip_bg"></div>').css({opacity:this.settings.opacity});
this.tooltip=c('<div class="_wtooltip_holder"></div>').append(c('<div class="_wtooltip_outer"></div>').append(c('<div class="_wtooltip_inner"></div>').append(d).append(this.content))).addClass("_wtooltip_"+this.settings.theme);
return this.tooltip;
},appendToBody:function(){c("body").append(this.tooltip);
},show:function(){var d=this;
this.tooltip.fadeIn(this.settings.fadeIn,function(){d.shown=true;
if(!d.hover){d.hide();
}});
},hide:function(){var d=this;
d.eventScheduler.set(function(){d.tooltip.fadeOut(d.settings.fadeOut,function(){d.shown=false;
});
},d.settings.delayOut);
},move:function(h){var f=c(window).width();
var k=c(window).height();
var d=h.pageX+this.settings.offsetX;
var j=h.pageY+this.settings.offsetY;
var g=this.tooltip.outerWidth();
var i=this.tooltip.outerHeight();
if(d-c(window).scrollLeft()+g>f){d=d-this.settings.offsetX*2-g;
}if(j-c(window).scrollTop()+i>k){j=j-this.settings.offsetY*2-i;
}this.tooltip.css({left:d,top:j});
},isOverflow:function(i,h){var f=(i+this.settings.offsetX+this.tooltip.outerWidth())-(c(window).scrollLeft()+c(window).width());
var d=i-c(window).scrollLeft();
var e=(h+this.settings.offsetY+this.tooltip.outerHeight())-(c(window).scrollTop()+c(window).height());
var g=h-c(window).scrollTop();
overflowTotal=0;
if(f>0){overflowTotal+=f;
}if(d<0){overflowTotal+=Math.abs(d);
}if(e>0){overflowTotal+=e;
}if(g<0){overflowTotal+=Math.abs(g);
}return overflowTotal;
},getOffset:function(h,m){var l=m.substring(0,1);
var e=m.substring(1,2);
var q=h.offset();
var k=q.left;
var p=q.top;
var n=h.outerWidth();
var j=h.outerHeight();
var d=c(window).width();
var r=c(window).height();
var i=this.tooltip.outerWidth();
var f=this.tooltip.outerHeight();
var g=null;
var o=null;
if(!(l=="m"&&e=="m")){if(l=="t"){o=p-f-this.settings.offsetY;
}else{if(l=="b"){o=p+j+this.settings.offsetY;
}else{if(e=="t"){o=p+this.settings.offsetY;
}else{if(e=="b"){o=p+j-f-this.settings.offsetY;
}else{if(e=="m"){o=p-(f-j)/2;
}}}}}if(l=="l"){g=k-i-this.settings.offsetX;
}else{if(l=="r"){g=k+n+this.settings.offsetX;
}else{if(e=="l"){g=k+this.settings.offsetX;
}else{if(e=="r"){g=k-(i-n)-this.settings.offsetX;
}else{if(e=="c"){g=k-(i-n)/2;
}}}}}}return{left:g,top:o};
},setBestPosition:function(h){var i={lt:["lt","lm","lb","rt","rm","rb","tl","tc","tr","bl","bc","br","mm"],lm:["lm","lt","lb","rm","rt","rb","tl","tc","tr","bl","bc","br","mm"],lb:["lb","lm","lt","rb","rm","rt","bl","bc","br","tl","tc","tr","mm"],rt:["rt","rm","rb","lt","lm","lb","tr","tc","tl","br","bc","bl","mm"],rm:["rm","rt","rb","lm","lt","lb","tr","tc","tl","br","bc","bl","mm"],rb:["rb","rm","rt","lb","lm","lt","br","bc","bl","tr","tc","tl","mm"],tl:["tl","tc","tr","bl","bc","br","lt","lm","lb","rt","rm","rb","mm"],tc:["tc","tl","tr","bc","bl","br","lt","lm","lb","rt","rm","rb","mm"],tr:["tr","tc","tl","br","bc","bl","rt","rm","rb","lt","lm","lb","mm"],bl:["bl","bc","br","tl","tc","tr","lb","lm","lt","rb","rm","rt","mm"],bc:["bc","bl","br","tc","tl","tr","lb","lm","lt","rb","rm","rt","mm"],br:["br","bc","bl","tr","tc","tl","rb","rm","rt","lb","lm","lt","mm"]};
var e=null;
var g=null;
var f=null;
var j=null;
var d=i[this.settings.position];
for(index in d){j=this.getOffset(h,d[index]);
e=this.isOverflow(j.left,j.top);
if(f==null||e<f){g=d[index];
f=e;
}if(!e){break;
}}if(j.left==null&&j.top==null){j=this.getOffset(h,g);
}this.tooltip.css({left:j.left,top:j.top});
},hoverOn:function(){var d=this;
this.hover=true;
this.eventScheduler.set(function(){d.show();
},this.settings.delayIn);
},hoverOff:function(d){this.hover=false;
if(this.shown){this.hide();
}}};
})(jQuery);
(function(a){a.fn.mousestop=function(c,b){b=a.extend({},a.fn.mousestop.defaultSettings,b||{});
return this.each(function(){var h=a(this);
var g=false;
var j=null;
var i=null;
if(b.timeToStop!=null){var e=null;
var k=null;
var f=0;
var d=Math.ceil(b.timeToStop/100);
h.mouseover(function(l){g=true;
j=setInterval(function(){f++;
if(f<d){if(!g){clearTimeout(j);
l.pageX=e;
l.pageY=k;
if(c){c.apply(this,[l]);
}}}else{g=false;
}},100);
});
}h.mouseout(function(l){clearTimeout(j);
clearTimeout(i);
f=0;
g=false;
if(b.onMouseout){b.onMouseout.apply(this,[l]);
}}).mousemove(function(l){e=l.pageX;
k=l.pageY;
if(g){clearTimeout(i);
i=setTimeout(function(){g=false;
if(b.timeToStop==null&&c){c.apply(this,[l]);
}},b.delayToStop);
}else{if(b.onStopMove){b.onStopMove.apply(this,[l]);
}g=true;
}});
});
};
a.fn.mousestop.defaultSettings={timeToStop:null,delayToStop:"300",onMouseout:null,onStopMove:null};
})(jQuery);
