-# Nav is the main object for all cosmos:navigator packages
-# this package is the base package all others are built from.
+# Nav is the global object to control the browser location, location state,
+# and get its location reactively.
 Nav =
 
   # tells if Nav is currently running

    return origin

  _putState: (state, extraState={}) ->
    location = state?.location ? @_buildLocation()
    Nav.state = _.extend state, moreState
    @history.replaceState Nav.state, document.title, location
    return


      locationCount: 0 # TODO: use this ;)
      location: window?.history?.location ? window.location

    # store History object on Nav.
    # if there is a history pushState function then we're fine.
    if window?.history?.pushState?
      @history = window.history

    # there's no push state API, so, enable hashbangs now and provide an
    # alternate history implementation.
    # TODO: there's a history push state polyfill. add that with a conditional
    #       comment to support IE browsers. what about other old browsers? hmm.
    else
      @_setHashbangEnabled true
      # add NOOP implementations.
      # TODO:
      #  implement these for browsers which don't have a history API.
      #  we'd have to track our
      #  pushState should change the browser location with a hashbang location
      #  replaceState should only update the stored state for the location.
      #
      @history = {
        pushState:(->), replaceState:(->), back:(->), forward:(->)
      }

    @_decode = unless options?.decode then ((v)->v) else @_decodeThis

    unless options?.click is false # TODO: clicks element selector?
      @__handleClick ?= @_handleClick.bind Nav
      document.addEventListener @_clickType(), @__handleClick, false

    unless options?.popstate is false
      @__handlePopstate ?= @_handlePopstate.bind Nav
      window.addEventListener 'popstate', @__handlePopstate, false

    if options?.hashbang is true then @_setHashbangEnabled true

    if options?.basepath? then @_setBasepath options.basepath

    return true

  # get the which/button value
  _which: (event) -> # TODO:? shorten to: event?.which ? window?.event?.button
    event ?= window?.event
    return event?.which ? event.button
