
(function($){$.cp_tooltips=function(el,options){var base=this;base.$el=$(el);base.el=el;base.init=function(){base.options=$.extend($.cp_tooltips.defaults,options);var tip=$(base.options.selector);var content=null;(base.options.contentSelector)?content=$(base.options.contentSelector):content=tip;var wrapper=$(base.options.selector);wrapper.appendTo($(document.body));base.$el.mouseover(function(e){tip.css("display","block");content.html($(this).attr("title"));}).mouseout(function(e){tip.css("display","none");}).mousemove(function(e){var posX=0;var posY=0;var diff=($(this).width()/2)-tip.width();if(base.options.anchorElement=="element"){if(base.options.anchorH=="left"){posX=$(this).offset().left-tip.width();}else if(base.options.anchorH=="center"){posX=$(this).offset().left+diff+(tip.width()/2);}else if(base.options.anchorH=="right"){posX=$(this).offset().left+$(this).width();}
if(base.options.anchorV=="top"){posY=$(this).offset().top-tip.height();}else if(base.options.anchorV=="middle"){posY=$(this).offset().top+($(this).height()/2)-(tip.height()/2);}else if(base.options.anchorV=="bottom"){posY=$(this).offset().top+$(this).height();}}else if(base.options.anchorElement=="mouse"){if(base.options.anchorH=="left"){posX=e.pageX-tip.width();}else if(base.options.anchorH=="center"){posX=e.pageX-(tip.width()/2);}else if(base.options.anchorH=="right"){posX=e.pageX+12;}
if(base.options.anchorV=="top"){posY=e.pageY-20;}else if(base.options.anchorV=="middle"){posY=e.pageY-(tip.height()/2);}else if(base.options.anchorV=="bottom"){posY=e.pageY+8;}}
var horPadding=parseInt(tip.css("padding-right"),10)+parseInt(tip.css("padding-left"),10);var verPadding=parseInt(tip.css("padding-top"),10)+parseInt(tip.css("padding-bottom"),10);if(base.options.anchorH=="left"){posX-=horPadding;}else if(base.options.anchorH=="center"){posX-=horPadding/2;}else if(base.options.anchorH=="right"){}
if(base.options.anchorV=="top"){posY-=verPadding;}else if(base.options.anchorV=="middle"){posY-=verPadding/2;}else if(base.options.anchorV=="bottom"){}
tip.css("left",posX);tip.css("top",posY);});}
base.init();};$.cp_tooltips.defaults={selector:"#cp_tooltip",contentSelector:null,anchorElement:"element",anchorH:"right",anchorV:"bottom"};$.fn.cp_tooltips=function(options){options=$.extend($.cp_tooltips.defaults,options);return this.each(function(){(new $.cp_tooltips(this,options));});return this;}})(jQuery);
