 util = require 'util'
 _ = require 'underscore'
+Backbone = require 'backbone'
 
 AjaxCursor = require './lib/ajax_cursor'
 Schema = require 'backbone-orm/lib/schema'

    ###################################
    return if sync[method] then sync[method].apply(sync, Array::slice.call(arguments, 1)) else undefined

  require('backbone-orm/lib/model_extensions')(model_type) # mixin extensions
  return require('backbone-orm/lib/cache').configureSync(model_type, sync_fn)

        return callback(new Error "Ajax failed with status #{res.status} for #{'destroy'} with: #{util.inspect(res.body)}") unless res.ok
        callback()

module.exports = (type) ->
  if (new type()) instanceof Backbone.Collection # collection
    model_type = Utils.configureCollectionModelType(type, module.exports)
    return type::sync = model_type::sync

  sync = new AjaxSync(type)
  type::sync = sync_fn = (method, model, options={}) -> # save for access by model extensions
    sync.initialize()

    return module.exports.apply(null, Array::slice.call(arguments, 1)) if method is 'createSync' # create a new sync
