
  
  
   
  //iOS swiping
  
                        
  	//Assign handlers to the simple direction handlers.
			var swipeOptions=
			{
				triggerOnTouchEnd : true,	
				swipeStatus : swipeStatus,
				allowPageScroll:"auto",
				threshold:40
			}
			
			var scrollOptions=
			{
				triggerOnTouchEnd : true,	
				allowPageScroll:"auto",
				swipeStatus : scrollStatus,
				threshold:40
			}
			
			var noscrollOptions=
			{
				triggerOnTouchEnd : true,	
				allowPageScroll:"none",
				threshold:40
			}
			
			$(function()
			{			
				//Enable swiping...
				$("#wrapper").swipe( swipeOptions );
				$("#content").swipe( scrollOptions );
				$("body").swipe( noscrollOptions );
				
			});
			
			var scrollstart;
			var duration=60;
			var scrollmove;
			
						function scrollStatus(event, phase, direction, distance)
			{
				
				
				//If we are moving before swipe, and we are going Lor R in X mode, or U or D in Y mode then drag.
				if( phase=="start")
				{
					scrollstart = new Date().getTime();
				}
				
				if( phase=="move" && (direction=="up" || direction=="down") )
				{	
		
					distance = (Math.abs(distance).toString())/duration;
					
					scrollmove = $("#content").scrollTop();
					
					if (direction == "up"){
						scrollmove = scrollmove + distance;
						
				}
					else if (direction == "down"){
						scrollmove = scrollmove - distance;
					
					}		
						$("#content").css("-webkit-transition-duration", "1s");
						$("#content").css("-webkit-transition-timing-function", "ease-out");
						$("#content").scrollTop(scrollmove);
				}
				
				else if ( phase == "cancel")
				{

				}
				
				else if ( phase =="end" )
				{
					scrollmove = $("#content").scrollTop();
					var scrollend = new Date().getTime() - scrollstart;
					
					//distance = (Math.abs(distance).toString())/duration;
					
					distance=(distance*10)/(scrollend/100);
					
					if (direction == "up"){
						
						scrollmove = scrollmove + distance;
					}
					else if (direction == "down"){
						scrollmove = scrollmove - distance;
					
					}
						
					if (scrollend < 600){    
					    //scrollmove=((scrollmove)/scrollend)*scrollmove;
					    
						//$("#content").css("-webkit-transition-duration", "10s");
						$("#content").css("-webkit-transition-timing-function", "ease-out");
						$("#content").animate({scrollTop:scrollmove}, '800');
					}
				}
			}
			
			
			var speed=500;
			
			function swipeStatus(event, phase, direction, distance)
			{
				//If we are moving before swipe, and we are going Lor R in X mode, or U or D in Y mode then drag.
				if( phase=="move" && (direction=="left" || direction=="right") )
				{
					var duration=0;
					var IMG_WIDTH = 0;
								
					if (direction == "left"){
						scrollImages(IMG_WIDTH + distance, duration);
				}
					else if (direction == "right"){
						
						scrollImages(IMG_WIDTH - distance, duration);
					}
				}
				
				else if ( phase == "cancel")
				{
					//scrollImages(IMG_WIDTH, speed);
					$("#frame").css("-webkit-transition-duration", "0.2s");
					$("#frame").css("-webkit-transform", "translate3d(0px,0px,0px)");
				}
				
				else if ( phase =="end" )
				{
					
					if (direction == "right"){
						scrollImages(-1000, speed);	
			
						$('#prev').trigger('click');
						$("#frame").css("-webkit-transition-duration", "0.1s");
							
					}
				
					else if (direction == "left")	{
						scrollImages(1000, speed);
	
							$('#next').trigger('click');		
							$("#frame").css("-webkit-transition-duration", "0.1s");
					}
				}
			}
			
			
			
				/**
			* Manuallt update the position of the imgs on drag
			*/
			function scrollImages(distance, duration)
			{
				$("#frame").css("-webkit-transition-duration", (duration/1000).toFixed(1) + "s");
				//inverse the number we set in the css
				var value = (distance<0 ? "" : "-") + Math.abs(distance).toString();
				
				$("#frame").css("-webkit-transform", "translate3d("+value +"px,0px,0px)");
			}
			
