define(["jquery","underscore","backbone"],function(e,t,n){var r;r=n.ajax,n.ajax=function(e){return this.ajax.queue(e)},n.ajax.pending=!1,n.ajax.requests=[],n.ajax.requestNext=function(){var e,t,n;return(e=this.requests.shift())?(t=e[0],n=e[1],this.request(t,n)):this.pending=!1},n.ajax.request=function(e,n,i){var s,o,u,a,f,l=this;return i==null&&(i=!0),u=t.extend({},e),f=u.success,o=u.error,s=u.complete,a={complete:function(e,t){var n;if(t==="timeout"){if(App.state.ajaxAttempts<App.ajax.maxAttempts)return r(a)}else{if(!(200<=(n=e.status)&&n<300))return l.pending=!1;s&&s.apply(l,arguments);if(i)return l.requestNext()}},success:function(){return f&&f.apply(this,arguments),n.resolveWith(this,arguments)},error:function(e,t,r){return t==="timeout"&&App.state.ajaxAttempts<App.ajax.maxAttempts?App.state.ajaxAttempts++:(o&&o.apply(this,arguments),n.rejectWith(this,arguments))}},a=t.extend(u,a),r(a),App.state.ajaxAttempts=1},n.ajax.queue=function(t){var n,r;return r=(t.type||"get").toLowerCase(),n=e.Deferred(),r==="get"?this.request(t,n,!1):this.pending?this.requests.push([t,n]):(this.pending=!0,this.request(t,n)),n}})