(function(Spine, $){
  
var Model = Spine.Model;

var getUrl = function(object){
  if (!(object && object.url)) return null;
  return $.isFunction(object.url) ? object.url() : object.url;
};

var methodMap = {
  "create":  "POST",
  "update":  "PUT",
  "destroy": "DELETE",
  "read":    "GET"
};

var urlError = function() {
  throw new Error("A 'url' property or function must be specified");
};

var ajaxSync = function(method, record){
  if (Model._noSync) return;
  
  var params = {
    type:          methodMap[method],
    contentType:  "application/json",
    dataType:     "json",
    processData:  false
  };
    
  if (method == "create" && record.model)
    params.url = getUrl(record.parent);
  else
    params.url = getUrl(record);

  if (!params.url) throw("Invalid URL");
    
  if (method == "create" || method == "update") {
    var data = record;
    if (Model.ajaxPrefix)
      data = {record.parent.name.toLowerCase(): record};
    
    params.data = JSON.stringify(data);
  }
    
  if (method == "read")
    params.success = function(data){
      (record.refresh || record.load).call(record, data);
    };

  params.error = function(xhr, s, e){
    record.trigger("ajaxError", xhr, s, e);
  };
  
  $.ajax(params);
};

Model.Ajax = {
  extended: function(){    
    this.sync(ajaxSync);
    this.fetch(this.proxy(function(){
      ajaxSync("read", this);
    }));
  }
};

Model.extend({
  ajaxPrefix: false,
  
  url: function() {
    return "/" + this.name.toLowerCase() + "s"
  },
  
  noSync: function(callback){
    Model._noSync = true;
    callback.apply(callback, arguments);
    Model._noSync = false;
  }
});

Model.include({
  url: function(){
    var base = getUrl(this.parent);
    base += (base.charAt(base.length - 1) == "/" ? "" : "/");
    base += encodeURIComponent(this.id);
    return base;        
  }  
});

})(Spine, jQuery);
@@ -130,32 +130,41 @@
 turn
- $.isFunction(object.url
+((typeof object.url == %22function%22
 ) ? 
@@ -188,16 +188,17 @@
 ject.url
+)
 ;%0A%7D;%0A%0Ava
@@ -865,15 +865,16 @@
 a = 
-record;
+%7B%7D;%0A    
 %0A   
@@ -899,23 +899,30 @@
 fix)
+ %7B
 %0A      
-data
+var prefix
  = 
-%7B
 reco
@@ -953,18 +953,78 @@
 se()
-: record%7D;
+;%0A      data%5Bprefix%5D = record;%0A    %7D else %7B%0A      data = record;%0A    %7D
 %0A   
@@ -1937,12 +1937,13 @@
 ne, 
-jQuery
+Spine.$
 );

fix ajax prefixing