function addSwipeListener(el, listener) {
     var startX;
	  var startY;
     var dx;
	  var dy;
     var directionX;
	  var directionY;

	function cancelTouch() {
		el.removeEventListener('touchmove', onTouchMove);
		el.removeEventListener('touchend', onTouchEnd);
		startX = null;
		startY = null;
		directionX = null;
		directionY = null;		
	}

     function onTouchMove(e) {
		if (e.touches.length > 1) {
		cancelTouch();
      	} else {
			dx = e.touches[0].pageX - startX;
			dy = e.touches[0].pageY - startY;
			if (directionX == null) {
				directionX = dx;
			} else if ((directionX < 0 && dx > 0) || (directionX > 0 && dx < 0) || Math.abs(dy) > 400) {
				//cancelTouch();
			}
			if (directionY == null) {
				directionY = dy;
			} else if ((directionY < 0 && dx > 0) || (directionY > 0 && dy < 0) || Math.abs(dy) > 400) {
				//cancelTouch();
			}			
		}
	}

	function onTouchEnd(e) {
		cancelTouch();
		//if (Math.abs(dx) > 30) {
			listener({ target: el, directionX: dx > 0 ? 'right' : 'left', directionY: dy > 0 ? 'down' : 'up' });
			dx = 0;
		//}
	}

	function onTouchStart(e) {
		//e.preventDefault();
		//e.stopPropagation();
		if (e.touches.length == 1) {
			startX = e.touches[0].pageX;
			startY = e.touches[0].pageY;
			el.addEventListener('touchmove', onTouchMove, false);
			el.addEventListener('touchend', onTouchEnd, false);
		}
	}
	
	el.addEventListener('touchstart', onTouchStart, false);
}
