(function(a){Type.registerNamespace("Telerik.Web.UI");
var b=Telerik.Web.UI;
var c=false;
Telerik.Web.UI.TouchScrollExtender=function(d){this._containerElements=a(d);
var e=arguments[1]||{};
this._autoScan="autoScan" in e?e.autoScan:false;
this._showScrollHints="showScrollHints" in e?e.showScrollHints:true;
this._useRoundedHints="useRoundedHints" in e?e.useRoundedHints:true;
this._hasHorizontalScrollHint=false;
this._hasVerticalScrollHint=false;
this._verticalScrollHint=false;
this._horizontalScrollHint=false;
this._lastAnimator=false;
this._dragCanceled=false;
this._currentTouches=0;
this.containers=[];
this._enableTouchScroll=true;
this._unbindBeforeDragging=false;
};
Telerik.Web.UI.TouchScrollExtender._getNeedsScrollExtender=function(){return $telerik.isTouchDevice;
};
Telerik.Web.UI.TouchScrollExtender.prototype={initialize:function(){if(this._enableTouchScroll){if(this._autoScan){this._containerElements=this._containerElements.add(a("*",this._containerElements)).filter(function(){return(a(this).css("overflow")=="scroll"||a(this).css("overflow")=="auto");
});
}var d=this;
this._containerElements.each(function(){this.style.overflow="hidden";
var e=a(this).addClass("RadTouchExtender").css("-webkit-tap-highlight-color","rgba(0, 0, 0, 0);");
var f={element:e.stop(),horizontalScrollHint:a('<div id="horizontalScrollHint" style="position: absolute; display: none; z-index: 200000; font-size: 0; height: 3px; border: 1px solid #333; background: #777; " />').appendTo(this.parentNode),verticalScrollHint:a('<div id="verticalScrollHint" style="position: absolute; display: none; z-index: 200000; width: 3px; border: 1px solid #333; background: #777; " />').appendTo(this.parentNode)};
if(d._useRoundedHints){f.horizontalScrollHint.css({"-moz-border-radius":"3px","-webkit-border-radius":"3px","border-radius":"3px"});
f.verticalScrollHint.css({"-moz-border-radius":"3px","-webkit-border-radius":"3px","border-radius":"3px"});
}e.data("dragID",d.containers.push(f)-1);
});
this._startDragProxy=a.proxy(this._startDrag,this);
if(b.TouchScrollExtender._getNeedsScrollExtender()){this._onGestureStartProxy=a.proxy(this._onGestureStart,this);
this._onGestureEndProxy=a.proxy(this._onGestureEnd,this);
this._containerElements.bind("touchstart",this._startDragProxy);
this._containerElements.bind("gesturestart",this._onGestureStartProxy);
this._containerElements.bind("gestureend",this._onGestureEndProxy);
}else{this._containerElements.bind("mousedown",this._startDragProxy);
}this._storeLastLocation=a.throttle(100,function(e){this._lastAnimator.kX=e.x;
this._lastAnimator.kY=e.y;
});
this._alignScrollHints=a.throttle(20,function(){var h=0;
var i=0;
var f=this._lastAnimator.element[0];
var j=this._lastAnimator.horizontalScrollHint;
var k=this._lastAnimator.verticalScrollHint;
var e=this._getBorderBox(f);
var g=a(f).position();
if(this._hasHorizontalScrollHint&&j){h=Math.abs(f.scrollLeft)*this._widthConstant+g.left+e.left;
j.css({left:h});
}if(this._hasVerticalScrollHint&&k){i=Math.abs(f.scrollTop)*this._heightConstant+g.top+e.top;
k.css({top:i});
}});
this._throttleScroll=a.throttle(10,function(e){this._lastAnimator.element[0].scrollLeft=this._lastAnimator.dragStartX-e.x;
this._lastAnimator.element[0].scrollTop=this._lastAnimator.dragStartY-e.y;
});
}this._scrollEndedDelegate=Function.createDelegate(this,this._scrollEnded);
},dispose:function(){this.disable();
this._detachInitilalEvents();
this.containers=null;
this._containerElements=null;
this._events=null;
this._scrollEndedDelegate=null;
},_detachInitilalEvents:function(){if(this._containerElements){if(this._startDragProxy){this._containerElements.unbind("mousedown",this._startDragProxy);
}if(this._onGestureStartProxy){this._containerElements.unbind("gesturestart",this._onGestureStartProxy);
}if(this._onGestureEndProxy){this._containerElements.unbind("gestureend",this._onGestureEndProxy);
}}},_startDrag:function(g){if(this._preventMultiTouch(g)){this._detachEvents();
c=false;
return;
}if(this._dragCanceled){return;
}if(c){return;
}var d=a(g.target);
var f=d.parents(".RadTouchExtender");
if(d.hasClass("RadTouchExtender")){f=f.add(d);
}var h=this._lastAnimator=this.containers[f.data("dragID")];
var i=h.element[0];
this._hasHorizontalScrollHint=i.offsetWidth<i.scrollWidth;
this._hasVerticalScrollHint=i.offsetHeight<i.scrollHeight;
h.hasDragged=false;
if(this._hasHorizontalScrollHint||this._hasVerticalScrollHint){c=true;
h.element.stop(true);
h.originalEvent=g.originalEvent;
if(!b.TouchScrollExtender._getNeedsScrollExtender()){this._cancelEvents(g);
}var k=$telerik.getTouchEventLocation(g);
h.kX=k.x;
h.kY=k.y;
var j=i.scrollLeft||0;
var l=i.scrollTop||0;
h.dragStartX=(j>0?j:0)+k.x;
h.dragStartY=(l>0?l:0)+k.y;
if(b.TouchScrollExtender._getNeedsScrollExtender()){if(this._unbindBeforeDragging){a(document.body).unbind({touchmove:a.proxy(this._compositeDragger,this),touchend:a.proxy(this._endDrag,this)});
}a(document.body).bind({touchmove:a.proxy(this._compositeDragger,this),touchend:a.proxy(this._endDrag,this)});
}else{a(document.body).bind({mousemove:a.proxy(this._compositeDragger,this),mouseup:a.proxy(this._endDrag,this)});
}}},_preventMultiTouch:function(d){if(d.originalEvent.touches&&d.originalEvent.touches.length>1){return true;
}},_getBorderBox:function(f){var d={left:0,top:0,right:0,bottom:0,horizontal:0,vertical:0};
if(window.getComputedStyle){var e=window.getComputedStyle(f,null);
d.left=parseInt(e.getPropertyValue("border-left-width"),10);
d.right=parseInt(e.getPropertyValue("border-right-width"),10);
d.top=parseInt(e.getPropertyValue("border-top-width"),10);
d.bottom=parseInt(e.getPropertyValue("border-bottom-width"),10);
}else{d.left=f.currentStyle.borderLeftWidth;
d.right=f.currentStyle.borderRightWidth;
d.top=f.currentStyle.borderTopWidth;
d.bottom=f.currentStyle.borderBottomWidth;
}d.horizontal=d.left+d.right;
d.vertical=d.top+d.bottom;
return d;
},_addScrollHints:function(){if(this._showScrollHints){var k=0;
var l=0;
var i=this._lastAnimator;
var e=i.element[0];
var d=this._getBorderBox(e);
var g=a(e).position();
if(this._hasHorizontalScrollHint){var h=i.element.innerWidth();
var m=~~((h/e.scrollWidth)*h)-2;
this._widthConstant=(m/h);
setTimeout(function(){k=Math.abs(e.scrollLeft)*(m/h)+g.left+d.left;
l=e.offsetHeight+g.top+d.top-7;
i.horizontalScrollHint.width(m).css({left:k,top:l});
},0);
i.horizontalScrollHint.fadeTo(200,0.5);
}if(this._hasVerticalScrollHint){var f=i.element.innerHeight();
var j=~~((f/e.scrollHeight)*f)-2;
this._heightConstant=(j/f);
setTimeout(function(){l=Math.abs(e.scrollTop)*(j/f)+g.top+d.top;
k=e.offsetWidth+g.left+d.left-7;
i.verticalScrollHint.height(j).css({left:k,top:l});
},0);
i.verticalScrollHint.fadeTo(200,0.5);
}}},_removeScrollHints:function(){if(this._showScrollHints){var d=this._lastAnimator.horizontalScrollHint;
var e=this._lastAnimator.verticalScrollHint;
if(this._hasHorizontalScrollHint&&d){d.hide();
}if(this._hasVerticalScrollHint&&e){e.hide();
}}},_simpleDragger:function(d){if(this._dragCanceled){return;
}this._cancelEvents(d);
var f=$telerik.getTouchEventLocation(d);
if(this._lastAnimator.element.length){this._throttleScroll(f);
this._alignScrollHints();
}this._storeLastLocation(f);
},_compositeDragger:function(d){if(this._dragCanceled){return;
}var h=$telerik.getTouchEventLocation(d);
var f=this._lastAnimator;
var g=f.element[0];
this._cancelEvents(d,f,h,"compositeDragger");
if(Math.abs(f.kX-h.x)>10||Math.abs(f.kY-h.y)>10){f.hasDragged=true;
this._addScrollHints();
if(b.TouchScrollExtender._getNeedsScrollExtender()){a(document.body).unbind("touchmove",this._compositeDragger).bind("touchmove",a.proxy(this._simpleDragger,this));
}else{a(document.body).unbind("mousemove",this._compositeDragger).bind("mousemove",a.proxy(this._simpleDragger,this));
}if($telerik.isIE){f.element.bind("click",this._cancelEvents);
g.setCapture(true);
}else{g.addEventListener("click",this._cancelEvents,true);
}}},disable:function(){this._detachEvents();
c=false;
this._dragCanceled=true;
},enable:function(){this._dragCanceled=false;
},_onGestureStart:function(){this._detachEvents();
c=false;
this._dragCanceled=true;
},_onGestureEnd:function(){this._dragCanceled=false;
},_endDrag:function(d){if(this._dragCanceled){return;
}c=false;
this._cancelEvents(d);
this._detachEvents();
if(b.TouchScrollExtender._getNeedsScrollExtender()){if(this._lastAnimator.originalEvent.touches.length==1&&!this._lastAnimator.hasDragged){var i=this._lastAnimator.originalEvent;
var f=document.createEvent("MouseEvents");
f.initMouseEvent("click",i.bubbles,i.cancelable,i.view,i.detail,i.screenX,i.screenY,i.clientX,i.clientY,false,false,false,false,i.button,i.relatedTarget);
i.target.dispatchEvent(f);
}}var j=this;
var h=$telerik.getTouchEventLocation(d);
var g=this._lastAnimator;
if($telerik.isIE){setTimeout(function(){g.element.unbind("click",j._cancelEvents);
document.releaseCapture();
},10);
}else{setTimeout(function(){g.element[0].removeEventListener("click",j._cancelEvents,true);
},0);
}if(g.hasDragged){if(g.element.length){g.endX=h.x;
g.endY=h.y;
}this._finishDrag(g);
}},_detachEvents:function(){if(b.TouchScrollExtender._getNeedsScrollExtender()){a(document.body).unbind("touchmove",this._simpleDragger).unbind("touchmove",this._compositeDragger).unbind("touchend",this._endDrag);
}else{a(document.body).unbind("mousemove",this._simpleDragger).unbind("mousemove",this._compositeDragger).unbind("mouseup",this._endDrag);
}},_finishDrag:function(d){var f=d.element[0].scrollLeft+d.kX-d.endX;
var g=d.element[0].scrollTop+d.kY-d.endY;
d.kX=0;
d.kY=0;
var e=this;
d.element.stop(true).animate({scrollLeft:f,scrollTop:g},{duration:500,easing:"easeOutQuad",complete:function(){e._removeScrollHints();
e._scrollEndedDelegate();
},step:function(){e._alignScrollHints();
}});
if(this._hasHorizontalScrollHint&&d.horizontalScrollHint){d.horizontalScrollHint.stop().css("opacity",0.5).fadeTo(450,0);
}if(this._hasVerticalScrollHint&&d.verticalScrollHint){d.verticalScrollHint.stop().css("opacity",0.5).fadeTo(450,0);
}},_cancelEvents:function(d){d.stopPropagation();
d.preventDefault();
},_setUnbindBeforeDragging:function(d){this._unbindBeforeDragging=d;
},get_events:function(){if(!this._events){this._events=new Sys.EventHandlerList();
}return this._events;
},_scrollEnded:function(){this._raiseEvent("scrollEnded",Sys.EventArgs.Empty);
},add_scrollEnded:function(d){this.get_events().addHandler("scrollEnded",d);
},remove_scrollEnded:function(d){this.get_events().removeHandler("scrollEnded",d);
},_raiseEvent:function(e,d){var f=this.get_events().getHandler(e);
if(f){if(!d){d=Sys.EventArgs.Empty;
}f(this,d);
}}};
Telerik.Web.UI.TouchScrollExtender.registerClass("Telerik.Web.UI.TouchScrollExtender",null,Sys.IDisposable);
})($telerik.$);