     EXCLUSIVE: 'exclusive'
     MULTI: 'multi'
 
+  ### 
+  Generate the next unique node ID string.
+  ###
+  @nextId: ->
+    Node.__currentId = Node.__currentId + 1
+
+    return Node.__currentId
+
+  ### 
+  Attempt to activate a node instance.
+  @param [Node] node
+  ###
   @activate: (node) ->
     return false if @lineageIsBusy(node) or node.isActivated()
 


    false

  @toggle: (node) ->
    if node.isActivated()
      return @deactivate node
    else
      return @activate node

  @lineageIsBusy: (node)->
    if parent = node.parent()
      return true if parent.isBusy()

    else if node.parent()?.defaultChild()
      Node.activate node.parent().defaultChild()

  ### 
  Process an action of activating or deactivating a node reference.
  @param [Object] action
  ###
  @processAction: (action) ->
    if action.transition == Node.Transitions.ACTIVATE
        @activate(action.node)
      else if action.transition == Node.Transitions.DEACTIVATE
        @deactivate(action.node)

  ### 
  Constructor
  @param [Object] options
  @option options [Array] children add children at instantiation.
  ###
  constructor: (opts={})->
    @_parent = null
    @_childMap = {}
    @_defaultChild = null
    @_nId = "exo##{Node.nextId()}"

    if opts.children
      for node in opts.children
        node.setParent @
        for child in opts.children
          @addChild child

    @_mode = opts.mode ||= Node.Modes.EXCLUSIVE
    @_initialState = opts.initialState ||= Node.States.DEACTIVATED

    # By default children automatically activate their parents
    # if they are not activated.
    if opts.childrenCanActivate == false
      @_childrenCanActivate = false
    else
      @_childrenCanActivate = true

    @_onActivatedAction = null
    @_onDeactivatedAction = null

  nodeId: ->
    @_nId

  setNodeId: (nid)->
    @_parent?.onChildIdUpdated @_nId, nid, @
    @_nId = nid

  sm: ->
    return @_smRef if @_smRef

    @_smRef = new Exo.StateMachine
      states: [Node.States.DEACTIVATED, Node.States.ACTIVATED]
      initialState: @_initialState
      transitions:
        activate:
          from: Node.States.DEACTIVATED
          to: Node.States.ACTIVATED
        deactivate:
          from: Node.States.ACTIVATED
          to: Node.States.DEACTIVATED

    @_smRef.performTransition = (t) =>
      if t == Node.Transitions.ACTIVATE
        @beforeActivate()
        @doActivate()
