 
     false
 
+  ### 
+  Attempts to perform activation if the node is deactivated and vice versa.
+  @param [Node] node
+  ###
   @toggle: (node) ->
     if node.isActivated()
       return @deactivate node
     else
       return @activate node
 
+  ### 
+  Find out if the lineage of a node is busy. This will be true if a parent, sibling or child is currently transitioning.
+  @param [Node] node
+  ###
   @lineageIsBusy: (node)->
     if parent = node.parent()
       return true if parent.isBusy()

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

  @processAction: (action) ->
    if action.transition == Node.Transitions.ACTIVATE
        @activate(action.node)
      else if action.transition == Node.Transitions.DEACTIVATE
        @deactivate(action.node)

  # Instance functions

  constructor: (opts={})->
    parent = null
    __childMap = {}
    __defaultChild = null
    __nId = "exo##{Node.nextId()}"

    @nodeId = ->
      __nId

    @setNodeId = (nid)->
      parent?.onChildIdUpdated __nId, nid, @
      __nId = nid

    # Did we receive an array of children from the opts hash?
    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

    # Create and return the state machine instance
    smRef = null
    @sm = ->
      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

    # Add a callback lambda to the SM and map the two
    # state transitions to methods in this class.
    @sm().performTransition = (t) =>
      if t == Node.Transitions.ACTIVATE
        @beforeActivate()
        @doActivate()


    node.attemptTransition Node.Transitions.ACTIVATE

  ### 
  Attempt to deactivate a node instance.
  @param [Node] node
  ###
  @deactivate: (node) ->
    if node.isActivated() and not @lineageIsBusy(node)
      if node.mode() == Node.Modes.EXCLUSIVE
