(function(n,t,i){typeof define=="function"&&define.amd?define(["jquery"],function(r){return i(r,n,t),r.mobile}):i(n.jQuery,n,t)})(this,document,function(n,t,i){(function(n,t,i,r){function h(n){while(n&&typeof n.originalEvent!="undefined")n=n.originalEvent;return n}function vt(t,i){var u=t.type,e,o,l,f,s,a,v,c,y;if(t=n.Event(t),t.type=i,e=t.originalEvent,o=n.event.props,u.search(/^(mouse|click)/)>-1&&(o=gt),e)for(v=o.length,f;v;)f=o[--v],t[f]=e[f];if(u.search(/mouse(down|up)|click/)>-1&&!t.which&&(t.which=1),u.search(/^touch/)!==-1&&(l=h(e),u=l.touches,s=l.changedTouches,a=u&&u.length?u[0]:s&&s.length?s[0]:r,a))for(c=0,y=ct.length;c<y;c++)f=ct[c],t[f]=a[f];return t}function v(t){for(var i={},r,u;t;){r=n.data(t,o);for(u in r)r[u]&&(i[u]=i.hasVirtualBinding=!0);t=t.parentNode}return i}function yt(t,i){for(var r;t;){if(r=n.data(t,o),r&&(!i||r[i]))return t;t=t.parentNode}return null}function pt(){l=!1}function tt(){l=!0}function wt(){s=0;y.length=0;d=!1;tt()}function bt(){pt()}function w(){it();c=setTimeout(function(){c=0;wt()},n.vmouse.resetTimerDuration)}function it(){c&&(clearTimeout(c),c=0)}function f(t,i,r){var u;return(r&&r[t]||!r&&yt(i.target,t))&&(u=vt(i,t),n(i.target).trigger(u)),u}function rt(t){var r=n.data(t.target,b),i;d||s&&s===r||(i=f("v"+t.type,t),i&&(i.isDefaultPrevented()&&t.preventDefault(),i.isPropagationStopped()&&t.stopPropagation(),i.isImmediatePropagationStopped()&&t.stopImmediatePropagation()))}function ut(t){var o=h(t).touches,r,i,u;o&&o.length===1&&(r=t.target,i=v(r),i.hasVirtualBinding&&(s=ni++,n.data(r,b,s),it(),bt(),e=!1,u=h(t).touches[0],lt=u.pageX,at=u.pageY,f("vmouseover",t,i),f("vmousedown",t,i)))}function ft(n){l||(e||f("vmousecancel",n,v(n.target)),e=!0,w())}function et(t){if(!l){var i=h(t).touches[0],o=e,r=n.vmouse.moveDistanceThreshold,u=v(t.target);e=e||Math.abs(i.pageX-lt)>r||Math.abs(i.pageY-at)>r;e&&!o&&f("vmousecancel",t,u);f("vmousemove",t,u);w()}}function ot(n){if(!l){tt();var t=v(n.target),i,r;f("vmouseup",n,t);e||(i=f("vclick",n,t),i&&i.isDefaultPrevented()&&(r=h(n).changedTouches[0],y.push({touchID:s,x:r.clientX,y:r.clientY}),d=!0));f("vmouseout",n,t);e=!1;w()}}function st(t){var i=n.data(t,o),r;if(i)for(r in i)if(i[r])return!0;return!1}function ht(){}function kt(t){var i=t.substr(1);return{setup:function(){st(this)||n.data(this,o,{});var r=n.data(this,o);r[t]=!0;u[t]=(u[t]||0)+1;u[t]===1&&p.bind(i,rt);n(this).bind(i,ht);g&&(u.touchstart=(u.touchstart||0)+1,u.touchstart===1&&p.bind("touchstart",ut).bind("touchend",ot).bind("touchmove",et).bind("scroll",ft))},teardown:function(){--u[t];u[t]||p.unbind(i,rt);g&&(--u.touchstart,u.touchstart||p.unbind("touchstart",ut).unbind("touchmove",et).unbind("touchend",ot).unbind("scroll",ft));var r=n(this),f=n.data(this,o);f&&(f[t]=!1);r.unbind(i,ht);st(this)||r.removeData(o)}}}var o="virtualMouseBindings",b="virtualTouchID",k="vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel".split(" "),ct="clientX clientY pageX pageY screenX screenY".split(" "),dt=n.event.mouseHooks?n.event.mouseHooks.props:[],gt=n.event.props.concat(dt),u={},c=0,lt=0,at=0,e=!1,y=[],d=!1,l=!1,g="addEventListener"in i,p=n(i),ni=1,s=0,nt,a;for(n.vmouse={moveDistanceThreshold:10,clickDistanceThreshold:10,resetTimerDuration:1500},a=0;a<k.length;a++)n.event.special[k[a]]=kt(k[a]);g&&i.addEventListener("click",function(t){var f=y.length,e=t.target,o,s,i,r,u,h;if(f)for(o=t.clientX,s=t.clientY,nt=n.vmouse.clickDistanceThreshold,i=e;i;){for(r=0;r<f;r++)if(u=y[r],h=0,i===e&&Math.abs(u.x-o)<nt&&Math.abs(u.y-s)<nt||n.data(i,b)===u.touchID){t.preventDefault();t.stopPropagation();return}i=i.parentNode}},!0)})(n,t,i),function(n){n.mobile={}}(n),function(n){var t={touch:"ontouchend"in i};n.mobile.support=n.mobile.support||{};n.extend(n.support,t);n.extend(n.mobile.support,t)}(n),function(n,t,r){function f(t,i,u,f){var e=u.type;u.type=i;f?n.event.trigger(u,r,t):n.event.dispatch.call(t,u);u.type=e}var u=n(i),e=n.mobile.support.touch,s="touchmove scroll",h=e?"touchstart":"mousedown",c=e?"touchend":"mouseup",o=e?"touchmove":"mousemove";n.each("touchstart touchmove touchend tap taphold swipe swipeleft swiperight scrollstart scrollstop".split(" "),function(t,i){n.fn[i]=function(n){return n?this.bind(i,n):this.trigger(i)};n.attrFn&&(n.attrFn[i]=!0)});n.event.special.scrollstart={enabled:!0,setup:function(){function i(n,i){t=i;f(r,t?"scrollstart":"scrollstop",n)}var r=this,e=n(r),t,u;e.bind(s,function(r){n.event.special.scrollstart.enabled&&(t||i(r,!0),clearTimeout(u),u=setTimeout(function(){i(r,!1)},50))})},teardown:function(){n(this).unbind(s)}};n.event.special.tap={tapholdThreshold:750,emitTapOnTaphold:!0,setup:function(){var i=this,r=n(i),t=!1;r.bind("vmousedown",function(e){function o(){clearTimeout(l)}function s(){o();r.unbind("vclick",h).unbind("vmouseup",o);u.unbind("vmousecancel",s)}function h(n){s();!t&&c===n.target?f(i,"tap",n):t&&n.preventDefault()}if(t=!1,e.which&&e.which!==1)return!1;var c=e.target,l;r.bind("vmouseup",o).bind("vclick",h);u.bind("vmousecancel",s);l=setTimeout(function(){n.event.special.tap.emitTapOnTaphold||(t=!0);f(i,"taphold",n.Event("taphold",{target:c}))},n.event.special.tap.tapholdThreshold)})},teardown:function(){n(this).unbind("vmousedown").unbind("vclick").unbind("vmouseup");u.unbind("vmousecancel")}};n.event.special.swipe={scrollSupressionThreshold:30,durationThreshold:1e3,horizontalDistanceThreshold:30,verticalDistanceThreshold:30,getLocation:function(n){var u=t.pageXOffset,f=t.pageYOffset,i=n.clientX,r=n.clientY;return n.pageY===0&&Math.floor(r)>Math.floor(n.pageY)||n.pageX===0&&Math.floor(i)>Math.floor(n.pageX)?(i-=u,r-=f):(r<n.pageY-f||i<n.pageX-u)&&(i=n.pageX-u,r=n.pageY-f),{x:i,y:r}},start:function(t){var r=t.originalEvent.touches?t.originalEvent.touches[0]:t,i=n.event.special.swipe.getLocation(r);return{time:(new Date).getTime(),coords:[i.x,i.y],origin:n(t.target)}},stop:function(t){var r=t.originalEvent.touches?t.originalEvent.touches[0]:t,i=n.event.special.swipe.getLocation(r);return{time:(new Date).getTime(),coords:[i.x,i.y]}},handleSwipe:function(t,i,r,u){if(i.time-t.time<n.event.special.swipe.durationThreshold&&Math.abs(t.coords[0]-i.coords[0])>n.event.special.swipe.horizontalDistanceThreshold&&Math.abs(t.coords[1]-i.coords[1])<n.event.special.swipe.verticalDistanceThreshold){var e=t.coords[0]>i.coords[0]?"swipeleft":"swiperight";return f(r,"swipe",n.Event("swipe",{target:u,swipestart:t,swipestop:i}),!0),f(r,e,n.Event(e,{target:u,swipestart:t,swipestop:i}),!0),!0}return!1},eventInProgress:!1,setup:function(){var i,r=this,f=n(r),t={};i=n.data(this,"mobile-events");i||(i={length:0},n.data(this,"mobile-events",i));i.length++;i.swipe=t;t.start=function(i){if(!n.event.special.swipe.eventInProgress){n.event.special.swipe.eventInProgress=!0;var e,s=n.event.special.swipe.start(i),h=i.target,f=!1;t.move=function(t){s&&!t.isDefaultPrevented()&&(e=n.event.special.swipe.stop(t),f||(f=n.event.special.swipe.handleSwipe(s,e,r,h),f&&(n.event.special.swipe.eventInProgress=!1)),Math.abs(s.coords[0]-e.coords[0])>n.event.special.swipe.scrollSupressionThreshold&&t.preventDefault())};t.stop=function(){f=!0;n.event.special.swipe.eventInProgress=!1;u.off(o,t.move);t.move=null};u.on(o,t.move).one(c,t.stop)}};f.on(h,t.start)},teardown:function(){var i,t;i=n.data(this,"mobile-events");i&&(t=i.swipe,delete i.swipe,i.length--,i.length===0&&n.removeData(this,"mobile-events"));t&&(t.start&&n(this).off(h,t.start),t.move&&u.off(o,t.move),t.stop&&u.off(c,t.stop))}};n.each({scrollstop:"scrollstart",taphold:"tap",swipeleft:"swipe.left",swiperight:"swipe.right"},function(t,i){n.event.special[t]={setup:function(){n(this).bind(i,n.noop)},teardown:function(){n(this).unbind(i)}}})}(n,this)})