(function(a){if(typeof define==="function"&&define.amd){define(["jquery"],a)}else{a(jQuery)}})(function(v){var E="virtualMouseBindings",b="virtualTouchID",u="clientX clientY pageX pageY screenX screenY".split(" "),a="vmouseover vmousedown vmousemove vmouseup vclick vmouseout vmousecancel".split(" "),x=("altKey bubbles cancelable ctrlKey currentTarget detail eventPhase metaKey relatedTarget shiftKey target timeStamp view which").split(" "),B=v.event.mouseHooks?v.event.mouseHooks.props:[],w=x.concat(B),z={},F=0,q=0,p=0,n=false,I=[],f=false,P=false,s="addEventListener" in document,r=v(document),D=1,L=0,c,J;v.vmouse={moveDistanceThreshold:10,clickDistanceThreshold:10,resetTimerDuration:1500,maximumTimeBetweenTouches:100};function o(i){while(i&&typeof i.originalEvent!=="undefined"){i=i.originalEvent}return i}function g(R,S){var aa=R.type,ab,Z,T,Q,X,W,V,U,Y;R=v.Event(R);R.type=S;ab=R.originalEvent;Z=x;if(aa.search(/^(mouse|click)/)>-1){Z=w}if(ab){for(V=Z.length;V;){Q=Z[--V];R[Q]=ab[Q]}}if(aa.search(/mouse(down|up)|click/)>-1&&!R.which){R.which=1}if(aa.search(/^touch/)!==-1){T=o(ab);aa=T.touches;X=T.changedTouches;W=(aa&&aa.length)?aa[0]:((X&&X.length)?X[0]:undefined);if(W){for(U=0,Y=u.length;U<Y;U++){Q=u[U];R[Q]=W[Q]}}}return R}function N(S){var Q={},i,R;while(S){i=v.data(S,E);for(R in i){if(i[R]){Q[R]=Q.hasVirtualBinding=true}}S=S.parentNode}return Q}function A(R,Q){var i;while(R){i=v.data(R,E);if(i&&(!Q||i[Q])){return R}R=R.parentNode}return null}function H(){P=false}function j(){P=true}function O(){L=0;I.length=0;f=false;j()}function m(){H()}function y(){if(F){clearTimeout(F);F=0}}function t(){y();F=setTimeout(function(){F=0;O()},v.vmouse.resetTimerDuration)}function l(R,S,i){var Q;if((i&&i[R])||(!i&&A(S.target,R))){Q=g(S,R);v(S.target).trigger(Q)}return Q}function h(Q){var R=v.data(Q.target,b),i;if(Q.type==="click"&&v.data(Q.target,"lastTouchType")==="touchstart"){setTimeout(function(){if(v.data(Q.target,"lastTouchType")==="touchstart"){O();delete v.data(Q.target).lastTouchType;h(Q)}},v.vmouse.maximumTimeBetweenTouches)}if(!f&&(!L||L!==R)){i=l("v"+Q.type,Q);if(i){if(i.isDefaultPrevented()){Q.preventDefault()}if(i.isPropagationStopped()){Q.stopPropagation()}if(i.isImmediatePropagationStopped()){Q.stopImmediatePropagation()}}}}function M(R){var T=o(R).touches,S,i,Q;if(T&&T.length===1){S=R.target;i=N(S);v.data(R.target,"lastTouchType",R.type);if(i.hasVirtualBinding){L=D++;v.data(S,b,L);y();m();n=false;Q=o(R).touches[0];q=Q.pageX;p=Q.pageY;l("vmouseover",R,i);l("vmousedown",R,i)}}}function G(i){if(P){return}if(!n){l("vmousecancel",i,N(i.target))}v.data(i.target,"lastTouchType",i.type);n=true;t()}function d(T){if(P){return}var R=o(T).touches[0],Q=n,S=v.vmouse.moveDistanceThreshold,i=N(T.target);v.data(T.target,"lastTouchType",T.type);n=n||(Math.abs(R.pageX-q)>S||Math.abs(R.pageY-p)>S);if(n&&!Q){l("vmousecancel",T,i)}l("vmousemove",T,i);t()}function e(S){if(P||v.data(S.target,"lastTouchType")===undefined){return}j();delete v.data(S.target).lastTouchType;var i=N(S.target),Q,R;l("vmouseup",S,i);if(!n){Q=l("vclick",S,i);if(Q&&Q.isDefaultPrevented()){R=o(S).changedTouches[0];I.push({touchID:L,x:R.clientX,y:R.clientY});f=true}}l("vmouseout",S,i);n=false;t()}function C(Q){var R=v.data(Q,E),i;if(R){for(i in R){if(R[i]){return true}}}return false}function K(){}function k(i){var Q=i.substr(1);return{setup:function(){if(!C(this)){v.data(this,E,{})}var R=v.data(this,E);R[i]=true;z[i]=(z[i]||0)+1;if(z[i]===1){r.bind(Q,h)}v(this).bind(Q,K);if(s){z.touchstart=(z.touchstart||0)+1;if(z.touchstart===1){r.bind("touchstart",M).bind("touchend",e).bind("touchmove",d).bind("scroll",G)}}},teardown:function(){--z[i];if(!z[i]){r.unbind(Q,h)}if(s){--z.touchstart;if(!z.touchstart){r.unbind("touchstart",M).unbind("touchmove",d).unbind("touchend",e).unbind("scroll",G)}}var R=v(this),S=v.data(this,E);if(S){S[i]=false}R.unbind(Q,K);if(!C(this)){R.removeData(E)}}}}for(J=0;J<a.length;J++){v.event.special[a[J]]=k(a[J])}if(s){document.addEventListener("click",function(U){var R=I.length,V=U.target,X,W,Y,T,Q,S;if(R){X=U.clientX;W=U.clientY;c=v.vmouse.clickDistanceThreshold;Y=V;while(Y){for(T=0;T<R;T++){Q=I[T];S=0;if((Y===V&&Math.abs(Q.x-X)<c&&Math.abs(Q.y-W)<c)||v.data(Y,b)===Q.touchID){U.preventDefault();U.stopPropagation();return}}Y=Y.parentNode}}},true)}});