+# Site 
+# ====
+# This module is actually just a DOM-ready script for various bits of site
+# functionality supporting the actual game.
+
 define [
   'app/defines'
 ], (defines) ->
 
   'use strict'
 
+  # We'll need a reference to the main game object, specifically to check state.
   _game = null
 
+  # Add a class for use in styling.
   document.body.className = 'ready'
+
+  # Use Modernizr to do browser feature detection. Except if a browser feature
+  # does not exist, the related feature just gets disabled. Not worth it to
+  # write fallback behavior mostly just for IE9.
   {classlist, csstransitions, history, prefixedCSS} = Modernizr
 
-  # Fiddle:
+  # Fiddle
+  # ------
+  # This feature allows the player to configure game variables to experiment and
+  # do more complex play-testing.
 
+  # The History API will be required. Start off with fiddle flag off.
   if history
     window.history.replaceState { fiddle: off }, document.title
 
+    # The fiddle button just allows access to global developing flag, which gets
+    # used throughout the game code. State is visually represented by the url
+    # updating and the button disabling (it's styled to become invisible).
+    # Note that because there's no server code, going directly to the `/fiddle`-
+    # appended url won't work.
     fiddle = document.querySelector '#fiddle'
     fiddle.addEventListener 'click', ->
       defines.developing = on
       window.history.pushState { fiddle: on }, "#{document.title} (fiddling)", 'fiddle'
       fiddle.setAttribute 'disabled', ''
 
+    # With url integration, hitting the back button will turn off fiddling,
+    # since the button gets disabled. But if the game is already being played, a
+    # reload will be needed to reset game state so re-initialization can occur
+    # with the updated developing flag.
     window.addEventListener 'popstate', (e) ->
       if _game.state.current is 'play'
         window.location.reload()

        defines.developing = off
        fiddle.removeAttribute 'disabled'

    gameParent = document.querySelector '#morning-stroll'
    gameParent.addEventListener 'state:play', ->
      fiddle.setAttribute 'disabled', ''

    gameParent.addEventListener 'state:menu', ->
      fiddle.removeAttribute 'disabled'
      window.history.back() if window.history.state.fiddle is on

  # About:

  if classlist and csstransitions
    style = window.getComputedStyle document.querySelector('#framed') 
    flipDuration = (
      parseFloat(style[prefixedCSS('transition-duration')]) +
      parseFloat(style[prefixedCSS('transition-delay')])
    ) * 1000
    frame = document.querySelector '#frame'
    toggleAbout = document.querySelector '#toggle-about'

    toggleAbout.addEventListener 'click', ->
      frame.classList.toggle 'flipped'


        toggleAbout.removeAttribute 'disabled'
      , flipDuration

  # Dependencies
  # ------------

  site =
    setGame: (game) -> _game = game
