   init: ->
     $(".nNewGameMenuCloseButton").on "click", =>
       if noughts.state.hasPreviousState()
-        noughts.state.back()
+        noughts.state.back(-> setStateFromPath(""))
       else
         noughts.state.changeState(noughts.state.INITIAL_PROMO)
 

  FACEBOOK_INVITE: "FACEBOOK_INVITE" # Game state for showing new game menu
  LOADING: "LOADING" # Game loading state

# Changes the current game state to 'newState'. The optional "urlBehavior"
# parameter shoud be a noughts.state.UrlBehavior, and the browser URL will be
# modified accordingly. The default urlBehavior is noughts.state.UrlBehavior.
# PUSH_URL. Any additional arguments are also past through to the onEnterState
# of the new state.
noughts.state.changeState = (newState, urlBehavior) ->
  # TODO(dthurn): Handle a "cancel button" type of state transition which
  # takes the current state out of history.
  if me.state.currentStateConstant() != -1 and me.state.current().onExitState?
    me.state.current().onExitState()
  urlBehavior ||= noughts.state.UrlBehavior.PUSH_URL
  Session.set("state", newState)
  newScreen = noughts.state.stateMap[newState]
  # Arguments should be [urlBehavior, args[2], args[3], etc]
  newArgs = [urlBehavior].concat(_.toArray(arguments).slice(2))
  newScreen.enterState.apply(newScreen, newArgs)

# What a new state should do to the browser URL when entered.
noughts.state.UrlBehavior =


SPRITE_Z_INDEX = 2 # The Z-Index to add new sprites at

noughts.inIframe = -> return window != window.top

noughts.state =
  PLAY: "PLAY"
  INITIAL_PROMO: "INITIAL_PROMO" # Initial game description state
