!function(a){"function"==typeof define&&define.amd&&define.amd.jQuery?define(["jquery"],a):a(jQuery)}(function(a){function b(b){return!b||void 0!==b.allowPageScroll||void 0===b.swipe&&void 0===b.swipeStatus||(b.allowPageScroll=j),void 0!==b.click&&void 0===b.tap&&(b.tap=b.click),b||(b={}),b=a.extend({},a.fn.swipe.defaults,b),this.each(function(){var d=a(this),e=d.data(B);e||(e=new c(this,b),d.data(B,e))})}function c(b,c){function C(b){if(!(jb()||a(b.target).closest(c.excludedElements,Sb).length>0)){var d,e=b.originalEvent?b.originalEvent:b,f=y?e.touches[0]:e;return Tb=u,y?Ub=e.touches.length:b.preventDefault(),Jb=0,Kb=null,Qb=null,Lb=0,Mb=0,Nb=0,Ob=1,Pb=0,Vb=ob(),Rb=rb(),hb(),!y||Ub===c.fingers||c.fingers===s||R()?(lb(0,f),Wb=Ab(),2==Ub&&(lb(1,e.touches[1]),Mb=Nb=ub(Vb[0].start,Vb[1].start)),(c.swipeStatus||c.pinchStatus)&&(d=J(e,Tb))):d=!1,d===!1?(Tb=x,J(e,Tb),d):(c.hold&&(ac=setTimeout(a.proxy(function(){Sb.trigger("hold",[e.target]),c.hold&&(d=c.hold.call(Sb,e,e.target))},this),c.longTapThreshold)),kb(!0),null)}}function D(a){var b=a.originalEvent?a.originalEvent:a;if(Tb!==w&&Tb!==x&&!ib()){var d,e=y?b.touches[0]:b,f=mb(e);if(Xb=Ab(),y&&(Ub=b.touches.length),c.hold&&clearTimeout(ac),Tb=v,2==Ub&&(0==Mb?(lb(1,b.touches[1]),Mb=Nb=ub(Vb[0].start,Vb[1].start)):(mb(b.touches[1]),Nb=ub(Vb[0].end,Vb[1].end),Qb=wb(Vb[0].end,Vb[1].end)),Ob=vb(Mb,Nb),Pb=Math.abs(Mb-Nb)),Ub===c.fingers||c.fingers===s||!y||R()){if(Kb=zb(f.start,f.end),P(a,Kb),Jb=xb(f.start,f.end),Lb=tb(),pb(Kb,Jb),(c.swipeStatus||c.pinchStatus)&&(d=J(b,Tb)),!c.triggerOnTouchEnd||c.triggerOnTouchLeave){var g=!0;if(c.triggerOnTouchLeave){var h=Bb(this);g=Cb(f.end,h)}!c.triggerOnTouchEnd&&g?Tb=I(v):c.triggerOnTouchLeave&&!g&&(Tb=I(w)),(Tb==x||Tb==w)&&J(b,Tb)}}else Tb=x,J(b,Tb);d===!1&&(Tb=x,J(b,Tb))}}function E(a){var b=a.originalEvent;return y&&b.touches.length>0?(gb(),!0):(ib()&&(Ub=Zb),Xb=Ab(),Lb=tb(),M()||!L()?(Tb=x,J(b,Tb)):c.triggerOnTouchEnd||0==c.triggerOnTouchEnd&&Tb===v?(a.preventDefault(),Tb=w,J(b,Tb)):!c.triggerOnTouchEnd&&Y()?(Tb=w,K(b,Tb,n)):Tb===v&&(Tb=x,J(b,Tb)),kb(!1),null)}function F(){Ub=0,Xb=0,Wb=0,Mb=0,Nb=0,Ob=1,hb(),kb(!1)}function G(a){var b=a.originalEvent;c.triggerOnTouchLeave&&(Tb=I(w),J(b,Tb))}function H(){Sb.unbind(Eb,C),Sb.unbind(Ib,F),Sb.unbind(Fb,D),Sb.unbind(Gb,E),Hb&&Sb.unbind(Hb,G),kb(!1)}function I(a){var b=a,d=O(),e=L(),f=M();return!d||f?b=x:!e||a!=v||c.triggerOnTouchEnd&&!c.triggerOnTouchLeave?!e&&a==w&&c.triggerOnTouchLeave&&(b=x):b=w,b}function J(a,b){var c=void 0;return V()||U()?c=K(a,b,l):(S()||R())&&c!==!1&&(c=K(a,b,m)),eb()&&c!==!1?c=K(a,b,o):fb()&&c!==!1?c=K(a,b,p):db()&&c!==!1&&(c=K(a,b,n)),b===x&&F(a),b===w&&(y?0==a.touches.length&&F(a):F(a)),c}function K(b,j,k){var q=void 0;if(k==l){if(Sb.trigger("swipeStatus",[j,Kb||null,Jb||0,Lb||0,Ub,Vb]),c.swipeStatus&&(q=c.swipeStatus.call(Sb,b,j,Kb||null,Jb||0,Lb||0,Ub,Vb),q===!1))return!1;if(j==w&&T()){if(Sb.trigger("swipe",[Kb,Jb,Lb,Ub,Vb]),c.swipe&&(q=c.swipe.call(Sb,b,Kb,Jb,Lb,Ub,Vb),q===!1))return!1;switch(Kb){case d:Sb.trigger("swipeLeft",[Kb,Jb,Lb,Ub,Vb]),c.swipeLeft&&(q=c.swipeLeft.call(Sb,b,Kb,Jb,Lb,Ub,Vb));break;case e:Sb.trigger("swipeRight",[Kb,Jb,Lb,Ub,Vb]),c.swipeRight&&(q=c.swipeRight.call(Sb,b,Kb,Jb,Lb,Ub,Vb));break;case f:Sb.trigger("swipeUp",[Kb,Jb,Lb,Ub,Vb]),c.swipeUp&&(q=c.swipeUp.call(Sb,b,Kb,Jb,Lb,Ub,Vb));break;case g:Sb.trigger("swipeDown",[Kb,Jb,Lb,Ub,Vb]),c.swipeDown&&(q=c.swipeDown.call(Sb,b,Kb,Jb,Lb,Ub,Vb))}}}if(k==m){if(Sb.trigger("pinchStatus",[j,Qb||null,Pb||0,Lb||0,Ub,Ob,Vb]),c.pinchStatus&&(q=c.pinchStatus.call(Sb,b,j,Qb||null,Pb||0,Lb||0,Ub,Ob,Vb),q===!1))return!1;if(j==w&&Q())switch(Qb){case h:Sb.trigger("pinchIn",[Qb||null,Pb||0,Lb||0,Ub,Ob,Vb]),c.pinchIn&&(q=c.pinchIn.call(Sb,b,Qb||null,Pb||0,Lb||0,Ub,Ob,Vb));break;case i:Sb.trigger("pinchOut",[Qb||null,Pb||0,Lb||0,Ub,Ob,Vb]),c.pinchOut&&(q=c.pinchOut.call(Sb,b,Qb||null,Pb||0,Lb||0,Ub,Ob,Vb))}}return k==n?(j===x||j===w)&&(clearTimeout(_b),clearTimeout(ac),Z()&&!ab()?($b=Ab(),_b=setTimeout(a.proxy(function(){$b=null,Sb.trigger("tap",[b.target]),c.tap&&(q=c.tap.call(Sb,b,b.target))},this),c.doubleTapThreshold)):($b=null,Sb.trigger("tap",[b.target]),c.tap&&(q=c.tap.call(Sb,b,b.target)))):k==o?(j===x||j===w)&&(clearTimeout(_b),$b=null,Sb.trigger("doubletap",[b.target]),c.doubleTap&&(q=c.doubleTap.call(Sb,b,b.target))):k==p&&(j===x||j===w)&&(clearTimeout(_b),$b=null,Sb.trigger("longtap",[b.target]),c.longTap&&(q=c.longTap.call(Sb,b,b.target))),q}function L(){var a=!0;return null!==c.threshold&&(a=Jb>=c.threshold),a}function M(){var a=!1;return null!==c.cancelThreshold&&null!==Kb&&(a=qb(Kb)-Jb>=c.cancelThreshold),a}function N(){return null!==c.pinchThreshold?Pb>=c.pinchThreshold:!0}function O(){var a;return a=c.maxTimeThreshold&&Lb>=c.maxTimeThreshold?!1:!0}function P(a,b){if(c.allowPageScroll===j||R())a.preventDefault();else{var h=c.allowPageScroll===k;switch(b){case d:(c.swipeLeft&&h||!h&&c.allowPageScroll!=q)&&a.preventDefault();break;case e:(c.swipeRight&&h||!h&&c.allowPageScroll!=q)&&a.preventDefault();break;case f:(c.swipeUp&&h||!h&&c.allowPageScroll!=r)&&a.preventDefault();break;case g:(c.swipeDown&&h||!h&&c.allowPageScroll!=r)&&a.preventDefault()}}}function Q(){var a=W(),b=X(),c=N();return a&&b&&c}function R(){return!!(c.pinchStatus||c.pinchIn||c.pinchOut)}function S(){return!(!Q()||!R())}function T(){var a=O(),b=L(),c=W(),d=X(),e=M(),f=!e&&d&&c&&b&&a;return f}function U(){return!!(c.swipe||c.swipeStatus||c.swipeLeft||c.swipeRight||c.swipeUp||c.swipeDown)}function V(){return!(!T()||!U())}function W(){return Ub===c.fingers||c.fingers===s||!y}function X(){return 0!==Vb[0].end.x}function Y(){return!!c.tap}function Z(){return!!c.doubleTap}function $(){return!!c.longTap}function _(){if(null==$b)return!1;var a=Ab();return Z()&&a-$b<=c.doubleTapThreshold}function ab(){return _()}function bb(){return(1===Ub||!y)&&(isNaN(Jb)||Jb<c.threshold)}function cb(){return Lb>c.longTapThreshold&&t>Jb}function db(){return!(!bb()||!Y())}function eb(){return!(!_()||!Z())}function fb(){return!(!cb()||!$())}function gb(){Yb=Ab(),Zb=event.touches.length+1}function hb(){Yb=0,Zb=0}function ib(){var a=!1;if(Yb){var b=Ab()-Yb;b<=c.fingerReleaseThreshold&&(a=!0)}return a}function jb(){return!(Sb.data(B+"_intouch")!==!0)}function kb(a){a===!0?(Sb.bind(Fb,D),Sb.bind(Gb,E),Hb&&Sb.bind(Hb,G)):(Sb.unbind(Fb,D,!1),Sb.unbind(Gb,E,!1),Hb&&Sb.unbind(Hb,G,!1)),Sb.data(B+"_intouch",a===!0)}function lb(a,b){var c=void 0!==b.identifier?b.identifier:0;return Vb[a].identifier=c,Vb[a].start.x=Vb[a].end.x=b.pageX||b.clientX,Vb[a].start.y=Vb[a].end.y=b.pageY||b.clientY,Vb[a]}function mb(a){var b=void 0!==a.identifier?a.identifier:0,c=nb(b);return c.end.x=a.pageX||a.clientX,c.end.y=a.pageY||a.clientY,c}function nb(a){for(var b=0;b<Vb.length;b++)if(Vb[b].identifier==a)return Vb[b]}function ob(){for(var a=[],b=0;5>=b;b++)a.push({start:{x:0,y:0},end:{x:0,y:0},identifier:0});return a}function pb(a,b){b=Math.max(b,qb(a)),Rb[a].distance=b}function qb(a){return Rb[a]?Rb[a].distance:void 0}function rb(){var a={};return a[d]=sb(d),a[e]=sb(e),a[f]=sb(f),a[g]=sb(g),a}function sb(a){return{direction:a,distance:0}}function tb(){return Xb-Wb}function ub(a,b){var c=Math.abs(a.x-b.x),d=Math.abs(a.y-b.y);return Math.round(Math.sqrt(c*c+d*d))}function vb(a,b){var c=b/a*1;return c.toFixed(2)}function wb(){return 1>Ob?i:h}function xb(a,b){return Math.round(Math.sqrt(Math.pow(b.x-a.x,2)+Math.pow(b.y-a.y,2)))}function yb(a,b){var c=a.x-b.x,d=b.y-a.y,e=Math.atan2(d,c),f=Math.round(180*e/Math.PI);return 0>f&&(f=360-Math.abs(f)),f}function zb(a,b){var c=yb(a,b);return 45>=c&&c>=0?d:360>=c&&c>=315?d:c>=135&&225>=c?e:c>45&&135>c?g:f}function Ab(){var a=new Date;return a.getTime()}function Bb(b){b=a(b);var c=b.offset(),d={left:c.left,right:c.left+b.outerWidth(),top:c.top,bottom:c.top+b.outerHeight()};return d}function Cb(a,b){return a.x>b.left&&a.x<b.right&&a.y>b.top&&a.y<b.bottom}var Db=y||A||!c.fallbackToMouseEvents,Eb=Db?A?z?"MSPointerDown":"pointerdown":"touchstart":"mousedown",Fb=Db?A?z?"MSPointerMove":"pointermove":"touchmove":"mousemove",Gb=Db?A?z?"MSPointerUp":"pointerup":"touchend":"mouseup",Hb=Db?null:"mouseleave",Ib=A?z?"MSPointerCancel":"pointercancel":"touchcancel",Jb=0,Kb=null,Lb=0,Mb=0,Nb=0,Ob=1,Pb=0,Qb=0,Rb=null,Sb=a(b),Tb="start",Ub=0,Vb=null,Wb=0,Xb=0,Yb=0,Zb=0,$b=0,_b=null,ac=null;try{Sb.bind(Eb,C),Sb.bind(Ib,F)}catch(bc){a.error("events not supported "+Eb+","+Ib+" on jQuery.swipe")}this.enable=function(){return Sb.bind(Eb,C),Sb.bind(Ib,F),Sb},this.disable=function(){return H(),Sb},this.destroy=function(){return H(),Sb.data(B,null),Sb},this.option=function(b,d){if(void 0!==c[b]){if(void 0===d)return c[b];c[b]=d}else a.error("Option "+b+" does not exist on jQuery.swipe.options");return null}}var d="left",e="right",f="up",g="down",h="in",i="out",j="none",k="auto",l="swipe",m="pinch",n="tap",o="doubletap",p="longtap",q="horizontal",r="vertical",s="all",t=10,u="start",v="move",w="end",x="cancel",y="ontouchstart"in window,z=window.navigator.msPointerEnabled&&!window.navigator.pointerEnabled,A=window.navigator.pointerEnabled||window.navigator.msPointerEnabled,B="TouchSwipe",C={fingers:1,threshold:75,cancelThreshold:null,pinchThreshold:20,maxTimeThreshold:null,fingerReleaseThreshold:250,longTapThreshold:500,doubleTapThreshold:200,swipe:null,swipeLeft:null,swipeRight:null,swipeUp:null,swipeDown:null,swipeStatus:null,pinchIn:null,pinchOut:null,pinchStatus:null,click:null,tap:null,doubleTap:null,longTap:null,hold:null,triggerOnTouchEnd:!0,triggerOnTouchLeave:!1,allowPageScroll:"auto",fallbackToMouseEvents:!0,excludedElements:"label, button, input, select, textarea, a, .noSwipe"};a.fn.swipe=function(c){var d=a(this),e=d.data(B);if(e&&"string"==typeof c){if(e[c])return e[c].apply(this,Array.prototype.slice.call(arguments,1));a.error("Method "+c+" does not exist on jQuery.swipe")}else if(!(e||"object"!=typeof c&&c))return b.apply(this,arguments);return d},a.fn.swipe.defaults=C,a.fn.swipe.phases={PHASE_START:u,PHASE_MOVE:v,PHASE_END:w,PHASE_CANCEL:x},a.fn.swipe.directions={LEFT:d,RIGHT:e,UP:f,DOWN:g,IN:h,OUT:i},a.fn.swipe.pageScroll={NONE:j,HORIZONTAL:q,VERTICAL:r,AUTO:k},a.fn.swipe.fingers={ONE:1,TWO:2,THREE:3,ALL:s}});