function sidebarNav(){
		if (page === "routes") {
			sideMenuClose();
			departList();
		}
		else if (page === "settings") {
			$('#depart-content').load('settings.html',function() {
				//declare what settings div to show!
				$("#ios-maps-setting").children().removeAttr("selected");

				if(window.localStorage.iosMapsSetting === "appleMaps") {
					$("#ios-maps-setting").val("appleMaps");
				} else if (window.localStorage.iosMapsSetting === "googleMaps") {
					$("#ios-maps-setting").val("googleMaps");
				}

				//listener for change on the maps service box.
				$("#ios-maps-setting").change(function() {
					window.localStorage.iosMapsSetting = $(this).val();
					mapsUrlChange();
				});
			});
			$('#arrive-content').empty();
			$('#schedule-content').empty();

			sideMenuClose();

			/*Android Backstack Things*/
			$(document).off('backbutton').on("backbutton", function(e) {
				e.preventDefault();
				departList();
			});
		}
		else if (page === "freestickers") {
			$('#depart-content').load('freestickers.html');
			$('#arrive-content').empty();
			$('#schedule-content').empty();

			sideMenuClose();

			/*Android Backstack Things*/
			$(document).off('backbutton').on("backbutton", function(e) {
				e.preventDefault();
				departList();
				});

			$("#content").bind('webkitTransitionEnd', function(){
			});
		}
		else if (page === "upgrade") {
			$('#depart-content').load('upgrade.html');
			$('#arrive-content').empty();
			$('#schedule-content').empty();
			sideMenuClose();

			/*Android Backstack Things*/
			$(document).off('backbutton').on("backbutton", function(e) {
				e.preventDefault();
				departList();
				});

			$("#content").bind('webkitTransitionEnd', function(){
			});
		}
		
		else if (page === "favourites") {
			favouritesList();
			sideMenuClose();

			/*Android Backstack Things*/
			$(document).off('backbutton').on("backbutton", function(e) {
				e.preventDefault();
				departList();
				});

			$("#content").bind('webkitTransitionEnd', function(){
			});
		}

		else {
			sideMenuClose();
		}
	}

function sidebarLinks() {
	$("#sidemenu-list").on("click", "a", function () {
		window.page = $(this).attr("val");
		sidebarNav(page);
	});
}

function sideMenuClose() {
	$("#content").css({"transform":"translate3d(0,0,0)","-webkit-transform":"translate3d(0,0,0)"});
	$(".top-bar").css({"transform":"translate3d(0,0,0)","-webkit-transform":"translate3d(0,0,0)"});
	$("#content").bind('webkitTransitionEnd', function(){
	$("#sidemenu").hide();
	});
	$('#menu').attr('data-slideopen','false');
	departLinks();
	if (tablet === true) {
		$('.content').css("overflow-y","auto");
	}
	else {
		$('#depart-content').css("overflow-y","auto");
		$('#depart-content').css("position","relative");
		$('#depart-content').css("width","100%");
		$('#depart-content').css("height","100%");
	}
}

function sideMenuOpen() {
	/*Backstack for Android*/
	$(document).off('backbutton').on("backbutton", function(e) {
			e.preventDefault();
			sideMenuClose();
		});
	$("#content").unbind();
	$("#sidemenu").show();
	$("#content").css({"transform":"translate3d(60%,0,0)","-webkit-transform":"translate3d(60%,0,0)"});
	$(".top-bar").css({"transform":"translate3d(60%,0,0)","-webkit-transform":"translate3d(60%,0,0)"});
	$('#menu').attr('data-slideopen',"true");
	//Unbind all the current anchor tags
	$("#depart-content").unbind();
	//Bind the body of the page to closing
	$("#content").click( function() {
		sideMenuClose();

	});

	//Make swipes close the panel


	$$(document).off('swipeLeft').on('swipeLeft', function(){
		sideMenuClose();
	});


	if (tablet === true) {
		$('.content').css("overflow-y","hidden");
	}
	else {
		//Prevent scrolling on the body
		$('#depart-content').css("overflow-y","hidden");
		$('body').css("overflow","hidden");
		$('#content').css("overflow","hidden");
		$('#depart-content').css("position","fixed");
	}


	//Make things linky!
	sidebarLinks();
}

function sideMenu(){
	if ($('#menu').attr('data-slideopen') === "false") {
		sideMenuOpen();
	}
	else if ($('#menu').attr('data-slideopen') === "true"){
		sideMenuClose();
	}
}