(function(e){e.touchyOptions={useDelegation:!1,longpress:{requiredTouches:1,msThresh:800,triggerStartPhase:!1,data:{startDate:null},proxyEvents:["TouchStart","TouchEnd"]},drag:{requiredTouches:1,msHoldThresh:100,data:{startPoint:null,startDate:null,movePoint:null,moveDate:null,held:!1},proxyEvents:["TouchStart","TouchMove","TouchEnd"]},pinch:{pxThresh:0,data:{startPoint:null,startDate:null,movePoint:null,moveDate:null},proxyEvents:["TouchStart","TouchMove","GestureChange","TouchEnd"]},rotate:{requiredTouches:1, data:{},proxyEvents:["TouchStart","TouchMove","GestureChange","TouchEnd"]},swipe:{requiredTouches:1,velocityThresh:1,triggerOn:"touchmove",data:{startPoint:null,startDate:null,movePoint:null,moveDate:null},proxyEvents:["TouchStart","TouchMove","TouchEnd"]}};var t={handleTouchStart:function(a){var b=l(a,this.context);if(b){var d=a.originalEvent,c=d.targetTouches;d.preventDefault();switch(this.context){case "drag":d=b.data("touchyDrag");c.length===d.settings.requiredTouches&&(o(d,c,a.timeStamp),a=d.startPoint, b.trigger("touchy-drag",["start",b,{movePoint:a,lastMovePoint:a,startPoint:a,velocity:0}]));break;case "swipe":d=b.data("touchySwipe");c.length===d.settings.requiredTouches&&p(d,c,a.timeStamp);break;case "pinch":d=b.data("touchyPinch");if(c=m(a))d.startPoint={x:c.centerX,y:c.centerY},d.startDistance=Math.sqrt(Math.pow(c.x2-c.x1,2)+Math.pow(c.y2-c.y1,2));break;case "longpress":d=b.data("touchyLongpress");c.length===d.settings.requiredTouches&&(d.startPoint={x:c[0].pageX,y:c[0].pageY},d.startDate=a.timeStamp, d.settings.triggerStartPhase&&b.trigger("touchy-longpress",["start",b]),d.timer=setTimeout(e.proxy(function(){b.trigger("touchy-longpress",["end",b])},this),d.settings.msThresh));break;case "rotate":d=b.data("touchyRotate"),c.length===d.settings.requiredTouches&&(1===c.length?n(d,c,a.timeStamp):(c=m(a),d.startPoint={x:c.centerX,y:c.centerY},d.startDate=a.timeStamp),a=d.startPoint,b.trigger("touchy-rotate",["start",b,{startPoint:a,movePoint:a,lastMovePoint:a,velocity:0,degrees:0}]))}}},handleTouchMove:function(a){var b= this.context,d=l(a,b);if(d){var c=a.originalEvent,f=c.targetTouches;c.preventDefault();switch(b){case "drag":b=d.data("touchyDrag");if(f.length===b.settings.requiredTouches){o(b,f,a.timeStamp);var c=b.movePoint,g=b.lastMovePoint,e=c.x===g.x&&c.y===g.y?0:Math.sqrt(Math.pow(c.x-g.x,2)+Math.pow(c.y-g.y,2)),h=b.moveDate-b.lastMoveDate;b.held&&d.trigger("touchy-drag",["move",d,{movePoint:c,lastMovePoint:g,startPoint:b.startPoint,velocity:0===h?0:e/h}])}break;case "swipe":b=d.data("touchySwipe");f.length=== b.settings.requiredTouches&&(p(b,f,a.timeStamp),!b.swipeExecuted&&(b.swiped&&"touchmove"===b.settings.triggerOn)&&(b.swipeExecuted=!0,q(b,d)));break;case "pinch":b=d.data("touchyPinch");if(a=m(a))b.currentPoint={x:a.centerX,y:a.centerY},"object"!=typeof window.ongesturechange&&(h=Math.sqrt(Math.pow(a.x2-a.x1,2)+Math.pow(a.y2-a.y1,2)),c=b.previousScale=b.scale||1,g=b.startDistance,h=b.scale=h/g,h*g>b.settings.pxThresh&&d.trigger("touchy-pinch",[d,{scale:h,previousScale:c,currentPoint:b.currentPoint, startPoint:b.startPoint,startDistance:g}]));break;case "rotate":if(b=d.data("touchyRotate"),f.length===b.settings.requiredTouches){var i,g=b.lastMovePoint=b.movePoint||b.startPoint,h=b.lastMoveDate=b.moveDate||b.startDate,c=b.movePoint={x:f[0].pageX,y:f[0].pageY},e=b.moveDate=a.timeStamp;if(1===f.length)a=b.targetPageCoords=b.targetPageCoords||s(a.target),a=b.centerCoords=b.centerCoords||{x:a.x+0.5*d.width(),y:a.y+0.5*d.height()};else if(a=m(a),a=b.centerCoords={x:a.centerX,y:a.centerY},"object"== typeof window.ongesturechange)break;f=Math.atan2(c.y-a.y,c.x-a.x);i=b.lastDegrees=b.degrees;f=b.degrees=f*(180/Math.PI);i=i?f-i:0;h=e-h;h=b.velocity=0===h?0:i/h;d.trigger("touchy-rotate",["move",d,{startPoint:b.startPoint,startDate:b.startDate,movePoint:c,lastMovePoint:g,centerCoords:a,degrees:f,degreeDelta:i,velocity:h}])}}}},handleGestureChange:function(a){var b=this.context,d=l(a,b);if(d){var d=e(a.target),c=a.originalEvent;c.preventDefault();switch(b){case "pinch":var b=d.data("touchyPinch"), a=b.previousScale=b.scale||1,c=b.scale=c.scale,f=b.startPoint,g=b.currentPoint||f,k=b.startDistance;c*k>b.settings.pxThresh&&d.trigger("touchy-pinch",[d,{scale:c,previousScale:a,currentPoint:g,startPoint:f,startDistance:k}]);break;case "rotate":b=d.data("touchyRotate"),f=b.lastDegrees=b.degrees,a=b.degrees=c.rotation,c=f?a-f:0,f=b.moveDate-b.lastMoveDate,f=b.velocity=0===f?0:c/f,d.trigger("touchy-rotate",["move",d,{startPoint:b.startPoint,startDate:b.startDate,movePoint:b.movePoint,lastMovePoint:b.lastMovePoint, centerCoords:b.centerCoords,degrees:a,degreeDelta:c,velocity:f}])}}},handleTouchEnd:function(a){var b=this.context,d=l(a,b);if(d)switch(a.originalEvent.preventDefault(),b){case "drag":a=d.data("touchyDrag");if(a.held){var b=a.movePoint||a.startPoint,c=a.lastMovePoint||a.startPoint,f=b.x===c.x&&b.y===c.y?0:Math.sqrt(Math.pow(b.x-c.x,2)+Math.pow(b.y-c.y,2)),g=a.moveDate-a.lastMoveDate;d.trigger("touchy-drag",["end",d,{movePoint:b,lastMovePoint:c,startPoint:a.startPoint,velocity:0===g?0:f/g}])}e.extend(a, {startPoint:null,startDate:null,movePoint:null,moveDate:null,lastMovePoint:null,lastMoveDate:null,held:!1});break;case "swipe":a=d.data("touchySwipe");a.swiped&&"touchend"===a.settings.triggerOn&&q(a,d);e.extend(a,{startPoint:null,startDate:null,movePoint:null,moveDate:null,lastMovePoint:null,lastMoveDate:null,swiped:!1,swipeExecuted:!1});break;case "pinch":a=d.data("touchyPinch");e.extend(a,{startPoint:null,startDistance:0,currentPoint:null,pinched:!1,scale:1,previousScale:null});break;case "longpress":a= d.data("touchyLongpress");clearTimeout(a.timer);e.extend(a,{startDate:null});break;case "rotate":a=d.data("touchyRotate"),d.trigger("touchy-rotate",["end",d,{startPoint:a.startPoint,startDate:a.startDate,movePoint:a.movePoint,lastMovePoint:a.lastMovePoint,degrees:a.degrees,degreeDelta:a.lastDegrees?a.degrees-a.lastDegrees:0,velocity:a.velocity}]),e.extend(a,{startPoint:null,startDate:null,movePoint:null,moveDate:null,lastMovePoint:null,lastMoveDate:null,targetPageCoords:null,centerCoords:null,degrees:null, lastDegrees:null,velocity:null})}}},o=function(a,b,d){n(a,b,d);var c=a.moveDate||a.startDate;a.held||d-c>a.settings.msHoldThresh?e.extend(a,{held:!0,lastMoveDate:c,lastMovePoint:a.movePoint&&a.movePoint.x?a.movePoint:a.startPoint,moveDate:d,movePoint:{x:b[0].pageX,y:b[0].pageY}}):e.extend(a,{held:!1,lastMoveDate:0,lastMovePoint:a.startPoint,moveDate:0,movePoint:a.startPoint})},p=function(a,b,d){n(a,b,d);var c=a.startPoint,f=a.moveDate||a.startDate,b={x:b[0].pageX,y:b[0].pageY},g=b.x-c.x,c=b.y-c.y, k=d-f;e.extend(a,{lastMoveDate:f,lastMovePoint:a.movePoint&&a.movePoint.x?a.movePoint:a.startPoint,moveDate:d,movePoint:b,hDistance:g,vDistance:c});if(!a.swiped&&(Math.abs(g)/k>a.settings.velocityThresh||Math.abs(c)/k>a.settings.velocityThresh))a.swiped=!0},q=function(a,b){var d=a.movePoint,c=a.lastMovePoint,f=d.x===c.x&&d.y===c.y?0:Math.sqrt(Math.pow(d.x-c.x,2)+Math.pow(d.y-c.y,2)),g=a.moveDate-a.lastMoveDate,f=0===g?0:f/g,g=a.hDistance,e=a.vDistance;f>a.settings.velocityThresh&&(g=Math.abs(g)>Math.abs(e)? 0