     noughts.melonDeferred.resolve()
   me.loader.preload(gameResources)
 
-# Functions to run as soon as possible on startup. Defines the state map
-# and adds a melonjs callback.
+
+noughts.state.stateMap = {
+  PLAY: new noughts.PlayScreen()
+  NEW_GAME_MENU: new noughts.NewGameMenu()
+  INITIAL_PROMO: new noughts.InitialPromo()
+  FACEBOOK_INVITE: new noughts.FacebookInviteMenu()
+  LOADING: new noughts.LoadingScreen()
+}
+
+# Functions to run as soon as possible on startup. Switches to the loading state
+# and sets up some melonjs initialization.
 Meteor.startup ->
-  noughts.state.stateMap = {
-    PLAY: new noughts.PlayScreen()
-    NEW_GAME_MENU: new noughts.NewGameMenu()
-    INITIAL_PROMO: new noughts.InitialPromo()
-    FACEBOOK_INVITE: new noughts.FacebookInviteMenu()
-    LOADING: new noughts.LoadingScreen()
-  }
-
   noughts.state.changeState(noughts.state.LOADING,
       noughts.state.UrlBehavior.PRESERVE_URL)
 

# The initial promo for non-players that explains what's going on.
noughts.InitialPromo = noughts.Screen.extend
  init: ->
    $(".nNewGameButton").on "click", =>
      noughts.state.changeState(noughts.state.NEW_GAME_MENU)

  onEnterState: (updateUrl) ->
    updateUrl("/")

# The "new game" menu
noughts.NewGameMenu = noughts.Screen.extend
  init: ->
    Template.newGameMenu.events
      "click .nNewGameMenuCloseButton": =>
        if noughts.state.hasPreviousState()
          noughts.state.back(-> setStateFromPath(""))
        else
          setStateFromPath("")
      "click .nUrlInviteButton":
          _.bind(this.handleUrlInviteButtonClick_, this)
      "click .nFacebookInviteButton":
          _.bind(this.handleFacebookInviteButtonClick_, this)

  onEnterState: (updateUrl) ->
    updateUrl("/new")
