/*
*jQuery Mobile Framework 1.1.0 db342b1f315c282692791aa870455901fdb46a55
*http://jquerymobile.com
*
*Copyright 2011(c)jQuery Project
*Dual licensed under the MIT or GPL Version 2 licenses.
*http://jquery.org/license
*
*/
;(function($){var touchStopEvent,touchMoveEvent,touchStartEvent,horizontalDistanceThreshold = 4,verticalDistanceThreshold=4,horizontalDistanceDampenner=1,verticalDistanceDampenner=.9,scrollSupressionThreshold=2,durationThreshold=3000;
if("ontouchend" in document){touchStopEvent="touchend.cj_swp";touchMoveEvent="touchmove.cj_swp";touchStartEvent="touchstart.cj_swp";}
else {touchStopEvent="mouseup.cj_swp";touchMoveEvent="mousemove.cj_swp";touchStartEvent="mousedown.cj_swp";}
$.fn.touchSwipe=function(cb,prevent,callonstart,useDurationThreshold){if(prevent)this.data("stopPropagation",true);if(useDurationThreshold)durationThreshold=useDurationThreshold;if(callonstart)this.data("swipeStart",[cb]);if(cb)return this.each(swipeBoth,[cb]);}
$.fn.touchSwipeLeft=function(cb,prevent,callonstart,useDurationThreshold){if(prevent)this.data("stopPropagation",true);if(useDurationThreshold)durationThreshold=useDurationThreshold;if(callonstart)this.data("swipeStart",[cb]);if(cb)return this.each(swipeLeft ,[cb]);}
$.fn.touchSwipeRight=function(cb,prevent,callonstart,useDurationThreshold){if(prevent)this.data("stopPropagation",true);if(useDurationThreshold)durationThreshold=useDurationThreshold;if(callonstart)this.data("swipeStart",[cb]);if(cb)return this.each(swipeRight,[cb]);}
function swipeBoth(cb){$(this).touchSwipeLeft(cb).touchSwipeRight(cb);}
function swipeLeft(cb){var $this=$(this);
if(!$this.data("swipeLeft"))$this.data("swipeLeft",cb);
if(!$this.data("swipeRight"))addSwipe($this);}
function swipeRight(cb){var $this=$(this);
if(!$this.data("swipeRight"))$this.data("swipeRight",cb);
if(!$this.data("swipeLeft"))addSwipe($this);}
$.fn.unbindSwipeLeft=function(){this.removeData("swipeLeft");
if(!this.data("swipeRight"))this.unbindSwipe(true);}
$.fn.unbindSwipeRight=function(){this.removeData("swipeRight");
if(!this.data("swipeLeft"))this.unbindSwipe(true);}
$.fn.unbindSwipe=function(changeData){if(!changeData)this.removeData("swipeLeft swipeRight stopPropagation");
return this.unbind(touchStartEvent+" "+touchMoveEvent+" "+touchStopEvent);}
function addSwipe($this){$this.unbindSwipe(true).bind(touchStartEvent,touchStart);}
function touchStart(event){
var time=new Date().getTime(),
data=event.originalEvent.touches?event.originalEvent.touches[0]:event,
$this=$(this).bind(touchMoveEvent,moveHandler).one(touchStopEvent,touchEnded),
pageX=data.pageX,pageY=data.pageY,newPageX,newPageY,newTime;
if($this.data("stopPropagation"))event.stopImmediatePropagation();
if($this.data("swipeStart"))$this.data("swipeStart")[0]($this,"start");
function touchEnded(event){$this.unbind(touchMoveEvent);
if(time&&newTime){var timeDiff=newTime-time;if(timeDiff<durationThreshold){var diffX=Math.abs(pageX - newPageX);var diffY=Math.abs(pageY - newPageY);
if((diffX>horizontalDistanceThreshold || diffY>verticalDistanceThreshold)&&diffY!=0){if((diffX*horizontalDistanceDampenner/diffY*verticalDistanceDampenner)>1){if(pageX>newPageX){if($this.data("swipeLeft"))$this.data("swipeLeft")($this,"left",timeDiff);
} else { if($this.data("swipeRight"))$this.data("swipeRight")($this,"right",timeDiff);
}}else { 
if(pageY>newPageY){ if($this.data("swipeLeft"))$this.data("swipeLeft")($this,"up",timeDiff);
} else { if($this.data("swipeRight"))$this.data("swipeRight")($this,"down",timeDiff);}}}}}
if($this.data("swipeStart"))$this.data("swipeStart")[0]($this,"end",timeDiff);
time=newTime=null;}
function moveHandler(event){if(time){data=event.originalEvent.touches?event.originalEvent.touches[0]:event;
newTime=new Date().getTime();
newPageX=data.pageX;newPageY=data.pageY;
if(Math.abs(pageX - newPageX)>scrollSupressionThreshold)event.preventDefault();}
if($this.data("swipeStart")) $this.data("swipeStart")[0]($this,"move",newTime-time);
}}
window.simpleSwipe={};})(jQuery);

