 Spine = @Spine   = {}
 module?.exports  = Spine
 
-Spine.version    = "2.0.0"
+Spine.version    = '2.0.1'
 Spine.isArray    = isArray
 Spine.$          = $
 Spine.Events     = Events


# Global events

Module.extend.apply(Spine, Events)
  
# JavaScript compatability


  # Private

  update: ->
    @trigger('beforeUpdate', @)
    records = @constructor.records
    records[@id].load @attributes()
    clone = records[@id].clone()
    @trigger('update', clone)
    @trigger('change', clone, 'update')

  create: ->
    @trigger('beforeCreate', @)
    @id          = guid() unless @id
    @newRecord   = false    
    records      = @constructor.records
    records[@id] = @dup(false)
    clone        = records[@id].clone()
    @trigger('create', clone)
    @trigger('change', clone, 'create')
  
  bind: (events, callback) ->
    @constructor.bind events, binder = (record) =>
      if record && @eql(record)
        callback.apply(@, arguments)
    @constructor.bind 'unbind', unbinder = (record) =>
      if record && @eql(record)
        @constructor.unbind(events, binder)
        @constructor.unbind('unbind', unbinder)
    binder
  
  trigger: ->
    @constructor.trigger(arguments...)
    
  unbind: ->
    @trigger('unbind', @)

class Controller extends Module
  @include Events
  @include Log
  
  eventSplitter: /^(\w+)\s*(.*)$/
  tag: 'div'
  
  constructor: (options) ->
    @options = options
