 
 				backButton.on Events.Click, =>
 					@back()
+
+	_getOppositeDirection: (initialDirection) ->
+		if initialDirection is DIR.UP
+			return DIR.DOWN
+		else if initialDirection is DIR.DOWN
+			return DIR.UP
+		else if initialDirection is DIR.RIGHT
+			return DIR.LEFT
+		else if initialDirection is DIR.LEFT
+			return DIR.RIGHT
+		else
+			return DIR.LEFT
 		
     
 

# 	width:  Screen.width
# 	height: Screen.height
# 	backgroundColor: "red"
# 	superLayer: vnc
	
# view2 = new Layer
# 	width:  Screen.width
# 	height: Screen.height
# 	backgroundColor: "green"
# 	superLayer: vnc

# view1.on Events.Click, -> vnc.transition view2
# view2.on Events.Click, -> vnc.back()

		view.states.switch PUSH.CENTER
		# currentView is now our previousView
		@previousView = @currentView
		# Save transition direction to the layer's custom properties
		@previousView.custom =
			lastTransition: direction
		# Set our currentView to the view we've brought in
		@currentView = view

		# Store the last view in history
		@history.push @previousView if preventHistory is false
		
		# Emit an event so the prototype can react to a view change
		@emit "change:view"

	removeBackButton: (view) ->
		Utils.delay 0, =>
			view.subLayersByName(BACKBUTTON_VIEW_NAME)[0].visible = false

	back: () ->
		lastView = @_getLastHistoryItem()
		lastTransition = lastView.custom.lastTransition
		oppositeTransition = @_getOppositeDirection(lastTransition)
		@transition(lastView, direction = oppositeTransition, switchInstant = false, preventHistory = true)
		@history.pop()

	_getLastHistoryItem: () ->
		return @history[@history.length - 1]

	_applyBackButton: (view, frame = @backButtonFrame) ->
