function AdfSafariTouchMoveManager(a,b,d){AdfAssert.assertDomNode(a,"Must have a DOM element to register a touch move with.");this.Init(a,b,d)}AdfObject.createSubclass(AdfSafariTouchMoveManager,AdfTouchMoveManager);
AdfSafariTouchMoveManager.prototype.Init=function(a,b,d){AdfSafariTouchMoveManager.superclass.Init.call(this,a,b,d);this._touchCount=d;this._handlerCallback=b;this._element=a;this._touchMap={};this._handleTouchStartCallaback=this.createCallback(this._handleTouchStart);this._handleTouchEndCallaback=this.createCallback(this._handleTouchEnd);this._handleTouchCancelCallaback=this.createCallback(this._handleTouchCancel);this._handleTouchMoveCallaback=this.createCallback(this._handleTouchMove);a.addEventListener("touchstart",
this._handleTouchStartCallaback,!0);a.addEventListener("touchend",this._handleTouchEndCallaback,!0);a.addEventListener("touchcancel",this._handleTouchEndCallaback,!0);a.addEventListener("touchmove",this._handleTouchMoveCallaback,!0);b=AdfAgent.AGENT.getComputedStyle(a).overflow;"scroll"!=b&&(a.style.overflow="scroll",this._originalOverflowValue=b)};
AdfSafariTouchMoveManager.prototype.unregister=function(){var a=this._element;a.removeEventListener("touchstart",this._handleTouchStartCallaback,!0);a.removeEventListener("touchend",this._handleTouchEndCallaback,!0);a.removeEventListener("touchcancel",this._handleTouchEndCallaback,!0);a.removeEventListener("touchmove",this._handleTouchMoveCallaback,!0);delete this._handleTouchStartCallaback;delete this._handleTouchEndCallaback;delete this._handleTouchCancelCallaback;delete this._handleTouchMoveCallaback;
delete this._touchMap;delete this._element;delete this._handlerCallback;delete this._touchCount;this._longTouchTimer&&AdfPage.PAGE.cancelTimer(this._longTouchTimer);delete this._longTouchTimer;delete this._longTouchEventCallback;null!=this._originalOverflowValue&&(a.style.overflow=this._originalOverflowValue,delete this._originalOverflowValue)};AdfSafariTouchMoveManager.prototype.setLongTouchEventCallback=function(a){this._longTouchEventCallback=a};
AdfSafariTouchMoveManager.prototype._handleTouchStart=function(a){for(var b=AdfAgent.AGENT,d=a.changedTouches,e,f=0;f<d.length;f++){e=d[f];var g=e.screenX,h=e.screenY;e=e.identifier;this._touchMap[e]={x:g,y:h,t:(new Date).getTime(),dx:0,dy:0,touchtype:null,target:b.getEventTarget(a)}}1==d.length&&this._longTouchEventCallback&&(this._longTouchTimer=AdfPage.PAGE.scheduleTimer(this,this._handleLongTouchStart,e,500))};
AdfSafariTouchMoveManager.prototype._handleLongTouchStart=function(a){this._longTouchTimer=null;a=this._touchMap[a];this._longTouchEventCallback&&a&&(a.touchtype="longtouch",this._longTouchEventCallback(a))};
AdfSafariTouchMoveManager.prototype._handleTouchEnd=function(a){this._longTouchTimer&&(AdfPage.PAGE.cancelTimer(this._longTouchTimer),delete this._longTouchTimer);a=a.changedTouches;for(var b=0;b<a.length;b++){var d=this._touchMap[a[b].identifier];"longtouch"==d.touchtype&&this._handleLongTouchEnd();delete d}};AdfSafariTouchMoveManager.prototype._handleLongTouchEnd=function(){this._longTouchEventCallback&&this._longTouchEventCallback()};AdfSafariTouchMoveManager.prototype._handleTouchCancel=function(a){this._handleTouchEnd(a)};
AdfSafariTouchMoveManager.prototype._handleTouchMove=function(a){var b=a.touches;this._longTouchTimer&&(AdfPage.PAGE.cancelTimer(this._longTouchTimer),delete this._longTouchTimer);if(b&&b.length==this._touchCount){var d=(new Date).getTime(),e=a.changedTouches,f,g,h;for(f=0;f<e.length;f++){g=e[f];var k=g.screenX,l=g.screenY,m=g.identifier;g=this._touchMap[m];var n=0,q=0,r=null,t=null;h=null;g&&(n=k-g.x,q=l-g.y,r=g.origx,t=g.origy,h=g.touchtype);null==r&&(r=k,t=l);this._touchMap[m]={x:k,y:l,t:d,dx:n,
dy:q,origx:r,origy:t,touchtype:h}}e=[];for(f in this._touchMap)g=this._touchMap[f],500>d-g.t&&e.push(g);if(2==this._touchCount){g=this._touchMap[b[0].identifier];d=this._touchMap[b[1].identifier];if(null==g||null==d)return;null==g.touchtype&&(b=this._determineTouchDirection(g),null!=b&&(d=this._determineTouchDirection(d),null!=d&&(h=this._isSameDirection(b,d)?"scroll":"pinch",g.touchtype=h)));h=g.touchtype;if(null==h||"pinch"==h)return}if(e.length<=this._touchCount){for(h=d=b=0;h<e.length;h++)g=e[h],
b+=g.dx,d+=g.dy;b/=this._touchCount;d/=this._touchCount;k=!0;for(h=0;h<e.length;h++)if(g=e[h],20<Math.abs(g.dx-b)||20<Math.abs(g.dy-d)){k=!1;break}k&&(AdfAgent.AGENT.preventDefault(a),0!=b||0!=d)&&(a=window.outerWidth/window.innerWidth,this._handlerCallback(b*a,d*a));for(f in this._touchMap)this._touchMap[f].t=0}}};
AdfSafariTouchMoveManager.prototype._isSameDirection=function(a,b){return a==b?!0:2==a.length&&1==b.length?a.charAt(0)==b||a.charAt(1)==b:1==a.length&&2==b.length?a==b.charAt(0)||b==a.charAt(1):!1};
AdfSafariTouchMoveManager.prototype._determineTouchDirection=function(a){var b=a.origx,d=a.origy;if(null==b||null==d)return null;b=a.x-b;a=a.y-d;if(Math.sqrt(Math.pow(b,2)+Math.pow(a,2))<.01*window.innerWidth)return null;d=null;.25<=Math.abs(b/a)&&(d=0>b?"l":"r");var e=null;.25<=Math.abs(a/b)&&(e=0>a?"u":"d");return null!=d&&null!=e?e+d:null==d?e:null==e?d:null};