   
   @onHasChanges = (fn) ->
     @_onHasChanges = fn
+
+  @onSyncStart = (fn) ->
+    @_onSyncStart = fn
 
   @onSyncComplete = (fn) ->
     @_onSyncComplete = fn

          )
          options.statusDisplay.append ' ', a
    
    sync = (async) ->
      ST.Model.sync(url, async, options.data || {})
    
    setInterval(->
      if sync(true)
        if options.statusDisplay
          count = ST.Model.changes()
          options.statusDisplay.html(
            ST.template(options.savingTemplate || 'Saving :count :changes...', {
              count:   count
              changes: if count == 1 then 'change' else 'changes'
            })
          )
    options.interval || 10000)
    
    if options.syncBeforeUnload
      window.onbeforeunload = (e) ->

      false
  
  @autoSync = (url, options={}) ->
    sync = (async) ->
      ST.Model.sync url, async, options.data || {}
    
    options.savingClass   ||= 'saving'
    options.completeClass ||= 'saved'
    options.errorClass    ||= 'failed'
    
    allClasses = "#{options.savingClass} #{options.completeClass} #{options.errorClass}"
    
    setDisplayClass = (newClass) ->
      if options.statusDisplay
        options.statusDisplay.removeClass allClasses
        options.statusDisplay.addClass newClass if newClass
    
    @onSyncStart (count) ->
      if options.statusDisplay
        options.statusDisplay.html(
          ST.template(options.savingTemplate || 'Saving :count :changes...', {
            count:   count
            changes: if count == 1 then 'change' else 'changes'
          })
        )
        setDisplayClass options.savingClass
    
    hideDisplayTimeout = null
    
    hideDisplay = ->
      options.statusDisplay.empty()
      setDisplayClass null 
    
    cancelHideDisplay = ->
      if hideDisplayTimeout
        clearTimeout hideDisplayTimeout
        hideDisplayTimeout = null
    
    setHideDisplay = ->
      cancelHideDisplay()
      hideDisplayTimeout = setTimeout(hideDisplay, 5000)
    
    @onSyncComplete ->
      if options.statusDisplay
        setDisplayClass options.completeClass
        options.statusDisplay.html(
          options.savedTemplate || 'Saved.'
        )
        setHideDisplay()
    
    @onSyncError (errors) ->
      if options.statusDisplay
        setDisplayClass options.errorClass
        options.statusDisplay.html(
          options.errorTemplate || 'Save failed!'
        )
