(function(g){function Y(c){!c||void 0!==c.allowPageScroll||void 0===c.swipe&&void 0===c.swipeStatus||(c.allowPageScroll=K);c||(c={});c=g.extend({},g.fn.swipe.defaults,c);return this.each(function(){var b=g(this),f=b.data(A);f||(f=new Z(this,c),b.data(A,f))})}function Z(c,b){function f(a){a=a.originalEvent;var c,S=q?a.touches[0]:a;d=T;q?h=a.touches.length:a.preventDefault();k=0;l=null;m=0;q&&h!==b.fingers&&b.fingers!==B?v(a):(w=r=S.pageX,x=t=S.pageY,C=(new Date).getTime(),b.swipeStatus&&(c=n(a,d))); if(!1===c)return d=p,n(a,d),c;e.bind(L,M);e.bind(N,O)}function M(a){a=a.originalEvent;if(d!==u&&d!==p){var c,e=q?a.touches[0]:a;r=e.pageX;t=e.pageY;y=(new Date).getTime();l=U();q&&(h=a.touches.length);d=D;var e=a,g=l;if(b.allowPageScroll===K)e.preventDefault();else{var f=b.allowPageScroll===V;switch(g){case z:(b.swipeLeft&&f||!f&&b.allowPageScroll!=P)&&e.preventDefault();break;case E:(b.swipeRight&&f||!f&&b.allowPageScroll!=P)&&e.preventDefault();break;case F:(b.swipeUp&&f||!f&&b.allowPageScroll!= Q)&&e.preventDefault();break;case G:(b.swipeDown&&f||!f&&b.allowPageScroll!=Q)&&e.preventDefault()}}h!==b.fingers&&b.fingers!==B&&q?(d=p,n(a,d)):(k=W(),m=y-C,b.swipeStatus&&(c=n(a,d,l,k,m)),b.triggerOnTouchEnd||(e=!(b.maxTimeThreshold?!(m>=b.maxTimeThreshold):1),!0===H()?(d=u,c=n(a,d)):e&&(d=p,n(a,d))));!1===c&&(d=p,n(a,d))}}function O(a){a=a.originalEvent;a.preventDefault();y=(new Date).getTime();k=W();l=U();m=y-C;if(b.triggerOnTouchEnd||!1===b.triggerOnTouchEnd&&d===D)if(d=u,h!==b.fingers&&b.fingers!== B&&q||0===r)d=p,n(a,d);else{var c=!(b.maxTimeThreshold?!(m>=b.maxTimeThreshold):1);if((!0===H()||null===H())&&!c)n(a,d);else if(c||!1===H())d=p,n(a,d)}else d===D&&(d=p,n(a,d));e.unbind(L,M,!1);e.unbind(N,O,!1)}function v(){C=y=t=r=x=w=h=0}function n(a,c){var d=void 0;b.swipeStatus&&(d=b.swipeStatus.call(e,a,c,l||null,k||0,m||0,h));c!==p||!b.click||1!==h&&q||!isNaN(k)&&0!==k||(d=b.click.call(e,a,a.target));if(c==u)switch(b.swipe&&(d=b.swipe.call(e,a,l,k,m,h)),l){case z:b.swipeLeft&&(d=b.swipeLeft.call(e, a,l,k,m,h));break;case E:b.swipeRight&&(d=b.swipeRight.call(e,a,l,k,m,h));break;case F:b.swipeUp&&(d=b.swipeUp.call(e,a,l,k,m,h));break;case G:b.swipeDown&&(d=b.swipeDown.call(e,a,l,k,m,h))}c!==p&&c!==u||v(a);return d}function H(){return null!==b.threshold?k>=b.threshold:null}function W(){return Math.round(Math.sqrt(Math.pow(r-w,2)+Math.pow(t-x,2)))}function U(){var a;a=Math.atan2(t-x,w-r);a=Math.round(180*a/Math.PI);0>a&&(a=360-Math.abs(a));return 45>=a&&0<=a?z:360>=a&&315<=a?z:135<=a&&225>=a?E: 45a?G:F}function X(){e.unbind(I,f);e.unbind(J,v);e.unbind(L,M);e.unbind(N,O)}var r,t,w,x,R=q||!b.fallbackToMouseEvents,I=R?"touchstart":"mousedown",L=R?"touchmove":"mousemove",N=R?"touchend":"mouseup",J="touchcancel",k=0,l=null,m=0,e=g(c),d="start",h=0,C=t=r=x=w=0,y=0;try{e.bind(I,f),e.bind(J,v)}catch(a){g.error("events not supported "+I+","+J+" on jQuery.swipe")}this.enable=function(){e.bind(I,f);e.bind(J,v);return e};this.disable=function(){X();return e};this.destroy=function(){X();e.data(A, null);return e}}var z="left",E="right",F="up",G="down",K="none",V="auto",P="horizontal",Q="vertical",B="all",T="start",D="move",u="end",p="cancel",q="ontouchstart"in window,A="TouchSwipe";g.fn.swipe=function(c){var b=g(this),f=b.data(A);if(f&&"string"===typeof c){if(f[c])return f[c].apply(this,Array.prototype.slice.call(arguments,1));g.error("Method "+c+" does not exist on jQuery.swipe")}else if(!(f||"object"!==typeof c&&c))return Y.apply(this,arguments);return b};g.fn.swipe.defaults={fingers:1,threshold:75, maxTimeThreshold:null,swipe:null,swipeLeft:null,swipeRight:null,swipeUp:null,swipeDown:null,swipeStatus:null,click:null,triggerOnTouchEnd:!0,allowPageScroll:"auto",fallbackToMouseEvents:!0};g.fn.swipe.phases={PHASE_START:T,PHASE_MOVE:D,PHASE_END:u,PHASE_CANCEL:p};g.fn.swipe.directions={LEFT:z,RIGHT:E,UP:F,DOWN:G};g.fn.swipe.pageScroll={NONE:K,HORIZONTAL:P,VERTICAL:Q,AUTO:V};g.fn.swipe.fingers={ONE:1,TWO:2,THREE:3,ALL:B}})(jQuery);