 	# Menu Open/Close Button
 	# if ($(window).width() > ResponsiveWindowWidth)
 	$('.btn-menu').click ->
-		closeSpeed = $('.menu').data('closespeed')
-		openSpeed = $('.menu').data('openspeed')
 		menuWidth = $('.menu').data('menuwidth')
 		edgeLocation = $('.menu').data('edgelocation')
 		siteWidth = $('.menu').data('sitewidth')
 
-		if $(".menu").data("state") == "open"
-			$('.menu').animate(left:"-" + menuWidth, closeSpeed)
-			$('.siteContainer').animate(left:edgeLocation, closeSpeed)
-			if ($(window).width() < ResponsiveWindowWidth)
-				$('body').css('position', "relative")
-			$(".menu").data("state", "closed")
+		if $(".menu").data("state") == "open" && animationState != "inProgress"
+			animationState = "inProgress"
+			$('.menu').animate(left:"-" + menuWidth, speed)
+			$('.siteContainer').animate left:edgeLocation, speed, ->
+				if ($(window).width() < ResponsiveWindowWidth)
+					$('body').css('position', "relative")
+				$(".menu").data("state", "closed")
+				animationState = "done"
 
-		else if $(".menu").data("state") == "closed"
-			$('.menu').animate(left:edgeLocation, openSpeed)
-			$('.siteContainer').animate(left:siteWidth, openSpeed)
-			if ($(window).width() < ResponsiveWindowWidth)
-				$('body').css('position', "fixed")
-			$(".menu").data("state", "open")
+		else if $(".menu").data("state") == "closed" && animationState != "inProgress"
+			animationState = "inProgress"
+			$('.menu').animate(left:edgeLocation, speed)
+			$('.siteContainer').animate left:siteWidth, speed, ->
+				if ($(window).width() < ResponsiveWindowWidth)
+					$('body').css('position', "fixed")
+				$(".menu").data("state", "open")
+				animationState = "done"
 
 	# This closes the menu when a link is pressed before loading the next page
 	$(".menuLink").click (e) ->
 		e.preventDefault()
 		$('.siteContainer').animate(
-			left: $('.menu').data('edgelocation')
+			left: edgeLocation
 		, $('.menu').data('closespeed'))
 		$(".menu").animate
 			left: "-" + $('.menu').data('menuwidth')
 		, $('.menu').data('closespeed'), ->
 			document.location.href = $(".menuLink").attr('href')
 
-	# if ($(window).width() < ResponsiveWindowWidth)
-	# 	$(".menu, .siteContainer").on "swipeleft", ->
-	# 		console.log("swipe left");
-	# 		if $(".menu").data("state") == "open"
-	# 			$('.menu').animate left:"-80%", 200
-	# 			$('.siteContainer').animate left: "0%", 200
-	# 			$('body').css('position', "relative")
-	# 			$(".menu").data("state", "closed")
+	if touchToggle == "on"
+		$(".siteContainer").bind startEvent, (e) ->
+			startTime = e.timeStamp
+			startX = (if e.originalEvent.touches then e.originalEvent.touches[0].pageX else e.pageX)
 
-	# 	$(".siteContainer").on "swiperight", ->
-	# 		console.log("swipe right" );
-	# 		if $(".menu").data("state") == "closed"
-	# 			$('.menu').animate left: "0%", 200, ->
-	# 				console.log("menu animation finished")
-	# 			$('.siteContainer').animate left: "85%", 200, ->
-	# 				console.log("siteContainer animation finished")
-	# 			$('body').css 'position', "fixed", ->
-	# 				console.log("position fixed")
-	# 			$(".menu").data "state", "open", ->
-	# 				console.log("state open")
+		$(".siteContainer").bind endEvent, (e) ->
+			startTime = 0
+			startX = 0
 
-	# 	$('.btn-menu').click ->
-	# 		if $(".menu").data("state") == "open"
-	# 			$('.menu').animate left:"-" + $('.menu').data('menuwidth'), 200, ->
-	# 				$('body').css('position', "relative")
-	# 				$(".menu").data("state", "closed")
-	# 			$('.siteContainer').animate(left: $('.menu').data('edgelocation'), 200)
-
-	# 		else if $(".menu").data("state") == "closed"
-	# 			$('.menu').animate left: $('.menu').data('edgelocation'), 200, ->
-	# 				$('body').css('position', "fixed")
-	# 				$(".menu").data("state", "open")
-	# 			$('.siteContainer').animate(left: $('.menu').data('sitewidth'), 200)
-
-# maxTime = 1000
-# maxDistance = 50
-# startX = 0
-# startTime = 0
-# touch = "ontouchend" of document
-# startEvent = (if (touch) then "touchstart" else "mousedown")
-# moveEvent = (if (touch) then "touchmove" else "mousemove")
-# endEvent = (if (touch) then "touchend" else "mouseup")
-
-# jQuery ->
-# 	$(".siteContainer").bind startEvent, (e) ->
-# 		startTime = e.timeStamp
-# 		startX = (if e.originalEvent.touches then e.originalEvent.touches[0].pageX else e.pageX)
-
-# 	$(".siteContainer").bind endEvent, (e) ->
-# 		startTime = 0
-# 		startX = 0
-
-# 	$(".siteContainer").bind moveEvent, (e) ->
-# 		currentX = (if e.originalEvent.touches then e.originalEvent.touches[0].pageX else e.pageX)
-# 		currentDistance = (if (startX is 0) then 0 else Math.abs(currentX - startX))
-# 		currentTime = e.timeStamp
-# 		if startTime != 0 && currentTime - startTime < maxTime && currentDistance > maxDistance
-# 			if($(window).width() <= ResponsiveWindowWidth)
-# 				if currentX < startX
-# 					if $(".menu").data("state") == "open"
-# 						$('.menu').animate(left:"-" + mobileMenuWidth, 200)
-# 						$('.siteContainer').animate(left:edgeLocation, 200)
-# 						$('body').css('position', "relative")
-# 						$(".menu").data("state", "closed")
-# 				if currentX > startX
-# 					if $(".menu").data("state") == "closed"
-# 						$('.menu').animate(left:edgeLocation, 200)
-# 						$('.siteContainer').animate(left:mobileSiteWidth, 200)
-# 						$('body').css('position', "fixed")
-# 						$(".menu").data("state", "open")+		$(".siteContainer").bind moveEvent, (e) ->
+			currentX = (if e.originalEvent.touches then e.originalEvent.touches[0].pageX else e.pageX)
+			currentDistance = (if (startX is 0) then 0 else Math.abs(currentX - startX))
+			currentTime = e.timeStamp
+			if startTime != 0 && currentTime - startTime < maxTime && currentDistance > maxDistance && animationState != "inProgress" && $(window).width() < ResponsiveWindowWidth
+				if currentX < startX
+					if $(".menu").data("state") == open
+						animationState = "inProgress"
+						$('.menu').animate left:negMobileMenuWidth, speed
+						$('.siteContainer').animate left:edgeLocation, speed, ->
+							$('body').css "position", relative
+							$(".menu").data "state", closed
+							animationState = "done"
+				if currentX > startX
+					if $(".menu").data("state") == closed
+						animationState = "inProgress"
+						$('.menu').stop().animate left:edgeLocation, speed
+						$('.siteContainer').animate left:mobileSiteWidth, speed, ->
+							$('body').css "position", fixed
+							$(".menu").data "state", open
+							animationState = "done" 
#Menu Characteristics
edgeLocation = "0%"
mobileMenuWidth = "80%"
desktopMenuWidth = "20%"
mobileSiteWidth = "85%"

changeMenuWidth = (e) ->
	if ($(window).width() < ResponsiveWindowWidth)

		$('.menu').data('sitewidth', mobileSiteWidth)
		$(".menu").css("width", mobileMenuWidth)
		$(".menu").css("left", "-" + mobileMenuWidth)
		$('.siteContainer').css 'left', edgeLocation, ->
			$('body').css('position', "relative")
			$(".menu").data("state", "closed")
			animationState = "done"

	if ($(window).width() > ResponsiveWindowWidth)
		$(".menu").data("menuwidth", desktopMenuWidth)
		$('.menu').data('sitewidth', desktopMenuWidth)
		$(".menu").css("width", desktopMenuWidth)
		$(".menu").css("left", "-" + desktopMenuWidth)
		$('.siteContainer').css 'left', edgeLocation, ->
			$('body').css('position', "relative")
			$(".menu").data("state", "closed")
			animationState = "done"

jQuery ->
	$(window).bind("load", changeMenuWidth)
