     noughts.state.changeState(noughts.state.FACEBOOK_INVITE,
         noughts.state.UrlBehavior.PRESERVE_URL)
   else if path == ""
-    # The path is the string "null" when inside the Facebook iFrame
     games = noughts.Games.find({}, {sort: {lastModified: -1}}).fetch()
     myTurnGames = _.filter(games, myTurn)
     if myTurnGames.length > 0

# 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 onResetEvent
# of the new state.
noughts.state.changeState = (newState, urlBehavior) ->
  # TODO(dthurn): Handle a "cancel button" type of state transition which

displayNotice = (msg) -> $(".nNotification").text(msg)

noughts.Screen = Object.extend
  # Shows a specific screen (a child of nMain) matching the provided selector.
  showScreen: (selector) ->
    $(".nMain").children().not(selector).hide()
    $(selector).show()

  enterState: (urlBehavior) ->
    updateUrl = _.partial(noughts.state.updateUrl, urlBehavior)
    @onEnterState.apply(this, [updateUrl].concat(_.rest(arguments)))

noughts.LoadingScreen = noughts.Screen.extend
  onEnterState: ->
    @showScreen(".nScreenLoading")

# The "new game" menu
noughts.NewGameMenu = noughts.Screen.extend
  init: ->
    $(".nNewGameMenuCloseButton").on "click", =>
      if noughts.state.hasPreviousState()
        noughts.state.back()
      else
        noughts.state.changeState(noughts.state.INITIAL_PROMO)

    $(".nUrlInviteButton").on("click",
        _.bind(this.handleUrlInviteButtonClick_, this))
    $(".nFacebookInviteButton").on("click",
        _.bind(this.handleFacebookInviteButtonClick_, this))

  onEnterState: (updateUrl) ->
    updateUrl("/new")
    @showScreen(".nScreenNewGame")

  handleUrlInviteButtonClick_: ->
    Meteor.call "newGame", Session.get("facebookProfile"), (err, gameId) ->
      if err? then throw er
