/*!
 * jQuery.tipsy
 * Copyright (c) 2014 CreativeDream
 * Website: http://creativedream.net/plugins/
 * Version: 1.0 (18-11-2014)
 * Requires: jQuery v1.7.1 or later
 */
!function(t){t.fn.tipsy=function(i){if("string"==typeof i&&["show","hide"].indexOf(i)>-1){switch(i){case"show":jQuery(this).trigger("tipsy.show");break;case"hide":jQuery(this).trigger("tipsy.hide")}return this}var e=t.extend({arrowWidth:10,attr:"data-tipsy",cls:null,duration:150,offset:7,position:"top-center",trigger:"hover",onShow:null,onHide:null},i);return this.each(function(i,o){var r=t(o),n=t('<div class="tipsy"></div>'),s=["top-left","top-center","top-right","bottom-left","bottom-center","bottom-right","left","right"],a={init:function(){var t={};switch(e.trigger){case"hover":t={mouseenter:a._show,mouseleave:a._hide};break;case"focus":t={focus:a._show,blur:a._hide};break;case"click":t={click:function(t){a._clSe?(a._clSe=!1,a._hide(t)):(a._clSe=!0,a._show(t))}};break;case"manual":a._unbindOptions(),t={"tipsy.show":function(t){a._clSe=!0,a._show(t)},"tipsy.hide":function(t){a._clSe=!1,a._hide(t)}}}r.on(t),n.hide()},_show:function(t){if(jQuery(".tipsy").remove(),a._clear(),a.hasAttr(e.attr+"-disabled"))return!1;a._createBox(),"manual"!=e.trigger&&a._bindOptions()},_hide:function(t){a._fixTitle(!0),n.stop(!0,!0).fadeOut(e.duration,function(){null!=e.onHide&&"function"==typeof e.onHide&&e.onHide(n,r),a._clear(),jQuery(this).remove()})},_showIn:function(){n.stop(!0,!0).fadeIn(e.duration,function(){null!=e.onShow&&"function"==typeof e.onShow&&e.onShow(n,r)})},_bindOptions:function(){t(window).bind("contextmenu",function(){a._hide()}).bind("blur",function(){a._hide()}).bind("resize",function(){a._hide()}).bind("scroll",function(){a._hide()})},_unbindOptions:function(){t(window).unbind("contextmenu",function(){a._hide()}).unbind("blur",function(){a._hide()}).unbind("resize",function(){a._hide()}).unbind("scroll",function(){a._hide()})},_clear:function(){n.attr("class","tipsy").empty(),a._lsWpI=[],a._lsWtI=[]},hasAttr:function(t){return void 0!==(t=r.attr(t))&&!1!==t},_fixTitle:function(t){t?a.hasAttr("data-title")&&!a.hasAttr("title")&&1==a._lsWtI[0]&&r.attr("title",a._lsWtI[1]||"").removeAttr("data-title"):!a.hasAttr("title")&&a.hasAttr("data-title")||(a._lsWtI=[!0,r.attr("title")],r.attr("data-title",r.attr("title")||"").removeAttr("title"))},_getTitle:function(){a._fixTitle();var t=r.attr("data-title");return t=""+t},_position:function(t){var i={top:0,left:0},o=t||(a.hasAttr(e.attr+"-position")?r.attr(e.attr+"-position"):e.position),l=o.split("-"),u=a.hasAttr(e.attr+"-offset")?r.attr(e.attr+"-offset"):e.offset,f=r.offset().top,c=r.offset().left,d=r.outerWidth(),h=r.outerHeight(),_=n.outerWidth(),p=n.outerHeight(),w=jQuery(window).outerWidth(),b=jQuery(window).outerHeight(),y=jQuery(window).scrollTop();jQuery(window).scrollLeft();if(-1==jQuery.inArray(o,s)||-1!==jQuery.inArray(o,a._lsWpI))return a._hide(),i;switch(a._lsWpI.push(o),l[0]){case"bottom":if(i.top=f+h+u,i.top>=b+y)return a._position("top-"+l[1]);n.addClass("arrow-top");break;case"top":if(i.top=f-p-u,i.top-y<=0)return a._position("bottom-"+l[1]);n.addClass("arrow-bottom");break;case"left":return i.top=f+h/2-p/2,i.left=c-_-u,i.left<=0?a._position("right"):(n.addClass("arrow-side-right"),i);case"right":return i.top=f+h/2-p/2,i.left=c+d+u,i.left+_>w?a._position("left"):(n.addClass("arrow-side-left"),i)}switch(l[1]){case"left":if(i.left=c+d/2-_+e.arrowWidth,i.left<=0)return a._position(l[0]+"-right");n.addClass("arrow-right");break;case"center":if(i.left=c+d/2-_/2,i.left+_>w)return a._position(l[0]+"-left");if(i.left<=0)return a._position(l[0]+"-right");n.addClass("arrow-center");break;case"right":if(i.left=c+d/2-e.arrowWidth,i.left+_>w)return a._position(l[0]+"-left");n.addClass("arrow-left")}return i},_createBox:function(){n.html(a._getTitle()).appendTo("body"),(null!=e.cls&&"string"==typeof e.cls||a.hasAttr(e.attr+"-cls"))&&n.addClass(a.hasAttr(e.attr+"-cls")?r.attr(e.attr+"-cls"):e.cls),n.css(a._position()),a._showIn()},_lsWtI:[],_lsWpI:[]};return a.init(),this})}}(jQuery);