// Backbone may be freely distributed under the MIT license.
// For all details and documentation:
// http://documentcloud.github.com/backbone
(function(a,b){typeofexports!="undefined"?b(a,exports,require("underscore")):typeofdefine=="function"&&define.amd?define("backbone",["underscore","jquery","exports"],function(c,d,e){b(a,e,c,d)}):a.Backbone=b(a,{},a._,a.jQuery||a.Zepto||a.ender)})(this,function(a,b,c,d){vare=a.Backbone,f=Array.prototype.slice;b.VERSION="0.5.3",b.noConflict=function(){returna.Backbone=e,b},b.emulateHTTP=!1,b.emulateJSON=!1,b.Events={bind:function(a,b,c){vard=this._callbacks||(this._callbacks={}),e=d[a]||(d[a]={}),f=e.tail||(e.tail=e.next={});returnf.callback=b,f.context=c,e.tail=f.next={},this},unbind:function(a,b){varc,d,e;if(!a)this._callbacks=null;elseif(c=this._callbacks)if(!b)c[a]={};elseif(d=c[a])while((e=d)&&(d=d.next)){if(d.callback!==b)continue;e.next=d.next,d.context=d.callback=null;break}returnthis},trigger:function(a){varb,c,d,e,g,h=["all",a];if(!(c=this._callbacks))returnthis;while(g=h.pop()){if(!(b=c[g]))continue;e=g=="all"?arguments:f.call(arguments,1);while(b=b.next)(d=b.callback)&&d.apply(b.context||this,e)}returnthis}},b.Model=function(a,b){vard;a||(a={});if(d=this.defaults)c.isFunction(d)&&(d=d.call(this)),a=c.extend({},d,a);this.attributes={},this._escapedAttributes={},this.cid=c.uniqueId("c"),this.set(a,{silent:!0}),this._changed=!1,this._previousAttributes=c.clone(this.attributes),b&&b.collection&&(this.collection=b.collection),this.initialize(a,b)},c.extend(b.Model.prototype,b.Events,{_changed:!1,idAttribute:"id",initialize:function(){},toJSON:function(){returnc.clone(this.attributes)},get:function(a){returnthis.attributes[a]},escape:function(a){varb;if(b=this._escapedAttributes[a])returnb;vard=this.attributes[a];returnthis._escapedAttributes[a]=c.escape(d==null?"":""+d)},has:function(a){returnthis.attributes[a]!=null},set:function(a,b){b||(b={});if(!a)returnthis;a.attributes&&(a=a.attributes);vard=this.attributes,e=this._escapedAttributes;if(!b.silent&&this.validate&&!this._performValidation(a,b))return!1;this.idAttributeina&&(this.id=a[this.idAttribute]);varf=this._changing;this._changing=!0;for(vargina){varh=a[g];c.isEqual(d[g],h)||(d[g]=h,deletee[g],this._changed=!0,b.silent||this.trigger("change:"+g,this,h,b))}returnf||(!b.silent&&this._changed&&this.change(b),this._changing=!1),this},unset:function(a,b){if(ainthis.attributes){b||(b={});varc=this.attributes[a],d={};returnd[a]=void0,!b.silent&&this.validate&&!this._performValidation(d,b)?!1:((this._unsetAttributes||(this._unsetAttributes=[])).push(a),deletethis.attributes[a],deletethis._escapedAttributes[a],a==this.idAttribute&&deletethis.id,this._changed=!0,b.silent||(this.trigger("change:"+a,this,void0,b),this.change(b)),this)}returnthis},clear:function(a){a||(a={});varb,c=this.attributes,d={};for(binc)d[b]=void0;if(!a.silent&&this.validate&&!this._performValidation(d,a))return!1;this.attributes={},this._escapedAttributes={},this._changed=!0;if(!a.silent){for(binc)this.trigger("change:"+b,this,void0,a);this.change(a)}returnthis},fetch:function(a){a||(a={});varc=this,d=a.success;returna.success=function(b,e,f){if(!c.set(c.parse(b,f),a))return!1;d&&d(c,b)},a.error=w(a.error,c,a),(this.sync||b.sync).call(this,"read",this,a)},save:function(a,c){c||(c={});if(a&&!this.set(a,c))return!1;vard=this,e=c.success;c.success=function(a,b,f){if(!d.set(d.parse(a,f),c))return!1;e&&e(d,a,f)},c.error=w(c.error,d,c);varf=this.isNew()?"create":"update";return(this.sync||b.sync).call(this,f,this,c)},destroy:function(a){a||(a={});if(this.isNew())returnthis.trigger("destroy",this,this.collection,a);varc=this,d=a.success;returna.success=function(b){c.trigger("destroy",c,c.collection,a),d&&d(c,b)},a.error=w(a.error,c,a),(this.sync||b.sync).call(this,"delete",this,a)},url:function(){vara=u(this.collection)||this.urlRoot||v();returnthis.isNew()?a:a+(a.charAt(a.length-1)=="/"?"":"/")+encodeURIComponent(this.id)},parse:function(a,b){returna},clone:function(){returnnewthis.constructor(this)},isNew:function(){returnthis.id==null},change:function(a){this.trigger("change",this,a),this._previousAttributes=c.clone(this.attributes),this._unsetAttributes=null,this._changed=!1},hasChanged:function(a){returna?this._previousAttributes[a]!=this.attributes[a]:this._changed},changedAttributes:function(a){a||(a=this.attributes);varb=this._previousAttributes,d=this._unsetAttributes,e=!1;for(varfina)c.isEqual(b[f],a[f])||(e||(e={}),e[f]=a[f]);if(d){e||(e={});varg=d.length;while(g--)e[d[g]]=void0}returne},previous:function(a){return!a||!this._previousAttributes?null:this._previousAttributes[a]},previousAttributes:function(){returnc.clone(this._previousAttributes)},_performValidation:function(a,b){varc=this.validate(a);returnc?(b.error?b.error(this,c,b):this.trigger("error",this,c,b),!1):!0}}),b.Collection=function(a,b){b||(b={}),b.comparator&&(this.comparator=b.comparator),c.bindAll(this,"_onModelEvent","_removeReference"),this._reset(),a&&this.reset(a,{silent:!0}),this.initialize.apply(this,arguments)},c.extend(b.Collection.prototype,b.Events,{model:b.Model,initialize:function(){},toJSON:function(){returnthis.map(function(a){returna.toJSON()})},add:function(a,b){if(c.isArray(a))for(vard=0,e=a.length;d<e;d++)this._add(a[d],b);elsethis._add(a,b);returnthis},remove:function(a,b){if(c.isArray(a))for(vard=0,e=a.length;d<e;d++)this._remove(a[d],b);elsethis._remove(a,b);returnthis},get:function(a){returna==null?null:this._byId[a.id!=null?a.id:a]},getByCid:function(a){returna&&this._byCid[a.cid||a]},at:function(a){returnthis.models[a]},sort:function(a){a||(a={});if(!this.comparator)thrownewError("Cannot sort a set without a comparator");returnthis.models=this.sortBy(this.comparator),a.silent||this.trigger("reset",this,a),this},pluck:function(a){returnc.map(this.models,function(b){returnb.get(a)})},reset:function(a,b){returna||(a=[]),b||(b={}),this.each(this._removeReference),this._reset(),this.add(a,{silent:!0}),b.silent||this.trigger("reset",this,b),this},fetch:function(a){a||(a={});varc=this,d=a.success;returna.success=function(b,e,f){c[a.add?"add":"reset"](c.parse(b,f),a),d&&d(c,b)},a.error=w(a.error,c,a),(this.sync||b.sync).call(this,"read",this,a)},create:function(a,b){varc=this;b||(b={}),a=this._prepareModel(a,b);if(!a)return!1;vard=b.success;returnb.success=function(a,e,f){c.add(a,b),d&&d(a,e,f)},a.save(null,b),a},parse:function(a,b){returna},chain:function(){returnc(this.models).chain()},_reset:function(a){this.length=0,this.models=[],this._byId={},this._byCid={}},_prepareModel:function(a,c){if(ainstanceofb.Model)a.collection||(a.collection=this);else{vard=a;a=newthis.model(d,{collection:this}),a.validate&&!a._performValidation(a.attributes,c)&&(a=!1)}returna},_add:function(a,b){b||(b={}),a=this._prepareModel(a,b);if(!a)return!1;varc=this.getByCid(a);if(c)thrownewError(["Can't add the same model to a set twice",c.id]);this._byId[a.id]=a,this._byCid[a.cid]=a;vard=b.at!=null?b.at:this.comparator?this.sortedIndex(a,this.comparator):this.length;returnthis.models.splice(d,0,a),a.bind("all",this._onModelEvent),this.length++,b.index=d,b.silent||a.trigger("add",a,this,b),a},_remove:function(a,b){b||(b={}),a=this.getByCid(a)||this.get(a);if(!a)returnnull;deletethis._byId[a.id],deletethis._byCid[a.cid];varc=this.indexOf(a);returnthis.models.splice(c,1),this.length--,b.index=c,b.silent||a.trigger("remove",a,this,b),this._removeReference(a),a},_removeReference:function(a){this==a.collection&&deletea.collection,a.unbind("all",this._onModelEvent)},_onModelEvent:function(a,b,c,d){if(a!="add"&&a!="remove"||c==this)a=="destroy"&&this._remove(b,d),b&&a==="change:"+b.idAttribute&&(deletethis._byId[b.previous(b.idAttribute)],this._byId[b.id]=b),this.trigger.apply(this,arguments);elsereturn}});varg=["forEach","each","map","reduce","reduceRight","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","sortBy","sortedIndex","toArray","size","first","rest","last","without","indexOf","lastIndexOf","isEmpty","groupBy"];c.each(g,function(a){b.Collection.prototype[a]=function(){returnc[a].apply(c,[this.models].concat(c.toArray(arguments)))}}),b.Router=function(a){a||(a={}),a.routes&&(this.routes=a.routes),this._bindRoutes(),this.initialize.apply(this,arguments)};varh=/:([\w\d]+)/g,i=/\*([\w\d]+)/g,j=/[-[\]{}()+?.,\\^$|#\s]/g;c.extend(b.Router.prototype,b.Events,{initialize:function(){},route:function(a,d,e){b.history||(b.history=newb.History),c.isRegExp(a)||(a=this._routeToRegExp(a)),b.history.route(a,c.bind(function(b){varc=this._extractParameters(a,b);e&&e.apply(this,c),this.trigger.apply(this,["route:"+d].concat(c))},this))},navigate:function(a,c){b.history.navigate(a,c)},_bindRoutes:function(){if(!this.routes)return;vara=[];for(varbinthis.routes)a.unshift([b,this.routes[b]]);for(varc=0,d=a.length;c<d;c++)this.route(a[c][0],a[c][1],this[a[c][1]])},_routeToRegExp:function(a){returna=a.replace(j,"\\$&").replace(h,"([^/]*)").replace(i,"(.*?)"),newRegExp("^"+a+"$")},_extractParameters:function(a,b){returna.exec(b).slice(1)}}),b.History=function(){this.handlers=[],c.bindAll(this,"checkUrl")};vark=/^#*/,l=/msie [\w.]+/,m=!1;c.extend(b.History.prototype,{interval:50,getFragment:function(a,b){if(a==null)if(this._hasPushState||b){a=window.location.pathname;varc=window.location.search;c&&(a+=c)}elsea=window.location.hash;returna=decodeURIComponent(a.replace(k,"")),a.indexOf(this.options.root)||(a=a.substr(this.options.root.length)),a},start:function(a){if(m)thrownewError("Backbone.history has already been started");this.options=c.extend({},{root:"/"},this.options,a),this._wantsPushState=!!this.options.pushState,this._hasPushState=!!(this.options.pushState&&window.history&&window.history.pushState);varb=this.getFragment(),e=document.documentMode,f=l.exec(navigator.userAgent.toLowerCase())&&(!e||e<=7);f&&(this.iframe=d('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow,this.navigate(b)),this._hasPushState?d(window).bind("popstate",this.checkUrl):"onhashchange"inwindow&&!f?d(window).bind("hashchange",this.checkUrl):setInterval(this.checkUrl,this.interval),this.fragment=b,m=!0;varg=window.location,h=g.pathname==this.options.root;if(this._wantsPushState&&!this._hasPushState&&!h)returnthis.fragment=this.getFragment(null,!0),window.location.replace(this.options.root+"#"+this.fragment),!0;this._wantsPushState&&this._hasPushState&&h&&g.hash&&(this.fragment=g.hash.replace(k,""),window.history.replaceState({},document.title,g.protocol+"//"+g.host+this.options.root+this.fragment));if(!this.options.silent)returnthis.loadUrl()},route:function(a,b){this.handlers.unshift({route:a,callback:b})},checkUrl:function(a){varb=this.getFragment();b==this.fragment&&this.iframe&&(b=this.getFragment(this.iframe.location.hash));if(b==this.fragment||b==decodeURIComponent(this.fragment))return!1;this.iframe&&this.navigate(b),this.loadUrl()||this.loadUrl(window.location.hash)},loadUrl:function(a){varb=this.fragment=this.getFragment(a),d=c.any(this.handlers,function(a){if(a.route.test(b))returna.callback(b),!0});returnd},navigate:function(a,b){varc=(a||"").replace(k,"");if(this.fragment==c||this.fragment==decodeURIComponent(c))return;if(this._hasPushState){vard=window.location;c.indexOf(this.options.root)!=0&&(c=this.options.root+c),this.fragment=c,window.history.pushState({},document.title,d.protocol+"//"+d.host+c)}elsewindow.location.hash=this.fragment=c,this.iframe&&c!=this.getFragment(this.iframe.location.hash)&&(this.iframe.document.open().close(),this.iframe.location.hash=c);b&&this.loadUrl(a)}}),b.View=function(a){this.cid=c.uniqueId("view"),this._configure(a||{}),this._ensureElement(),this.delegateEvents(),this.initialize.apply(this,arguments)};varn=function(a){returnd(a,this.el)},o=/^(\S+)\s*(.*)$/,p=["model","collection","el","id","attributes","className","tagName"];c.extend(b.View.prototype,b.Events,{tagName:"div",$:n,initialize:function(){},render:function(){returnthis},remove:function(){returnd(this.el).remove(),this},make:function(a,b,c){vare=document.createElement(a);returnb&&d(e).attr(b),c&&d(e).html(c),e},delegateEvents:function(a){if(!a&&!(a=this.events))return;c.isFunction(a)&&(a=a.call(this)),this.undelegateEvents();for(varbina){vare=this[a[b]];if(!e)thrownewError('Event "'+a[b]+'" does not exist');varf=b.match(o),g=f[1],h=f[2];e=c.bind(e,this),g+=".delegateEvents"+this.cid,h===""?d(this.el).bind(g,e):d(this.el).delegate(h,g,e)}},undelegateEvents:function(){d(this.el).unbind(".delegateEvents"+this.cid)},_configure:function(a){this.options&&(a=c.extend({},this.options,a));for(varb=0,d=p.length;b<d;b++){vare=p[b];a[e]&&(this[e]=a[e])}this.options=a},_ensureElement:function(){if(!this.el){vara=this.attributes||{};this.id&&(a.id=this.id),this.className&&(a["class"]=this.className),this.el=this.make(this.tagName,a)}elsec.isString(this.el)&&(this.el=d(this.el).get(0))}});varq=function(a,b){varc=t(this,a,b);returnc.extend=this.extend,c};b.Model.extend=b.Collection.extend=b.Router.extend=b.View.extend=q;varr={create:"POST",update:"PUT","delete":"DELETE",read:"GET"};b.sync=function(a,e,f){varg=r[a],h={type:g,dataType:"json"};returnf.url||(h.url=u(e)||v()),!f.data&&e&&(a=="create"||a=="update")&&(h.contentType="application/json",h.data=JSON.stringify(e.toJSON())),b.emulateJSON&&(h.contentType="application/x-www-form-urlencoded",h.data=h.data?{model:h.data}:{}),b.emulateHTTP&&(g==="PUT"||g==="DELETE")&&(b.emulateJSON&&(h.data._method=g),h.type="POST",h.beforeSend=function(a){a.setRequestHeader("X-HTTP-Method-Override",g)}),h.type!=="GET"&&!b.emulateJSON&&(h.processData=!1),d.ajax(c.extend(h,f))};vars=function(){},t=function(a,b,d){vare;returnb&&b.hasOwnProperty("constructor")?e=b.constructor:e=function(){returna.apply(this,arguments)},c.extend(e,a),s.prototype=a.prototype,e.prototype=news,b&&c.extend(e.prototype,b),d&&c.extend(e,d),e.prototype.constructor=e,e.__super__=a.prototype,e},u=function(a){return!a||!a.url?null:c.isFunction(a.url)?a.url():a.url},v=function(){thrownewError('A "url" property or function must be specified')},w=function(a,b,c){returnfunction(d,e){vare=d===b?e:d;a?a(d,e,c):b.trigger("error",d,e,c)}};returnb})
s[i])i=z(e,a),b.depCallbacks[g](i);returnc?m[c]:void0}}functionA(){varb=p.waitSeconds*1E3,a=b&&g.startTime+b<(newDate).getTime(),b="",c=!1,h=!1,j;if(!(g.pausedCount>0)){if(p.priorityWait)if(k())w();elsereturn;for(jins)if(!(jinK)&&(c=!0,!s[j]))if(a)b+=j+"";else{h=!0;break}if(c||g.waitCount){if(a&&b)returnj=N("timeout","Load timeout for modules: "+b),j.requireType="timeout",j.requireModules=b,d.onError(j);if(h||g.scriptCount){if((G||ca)&&!W)W=setTimeout(function(){W=0;A()},50)}else{if(g.waitCount){for(H=
b,c);c=h(b,c);b=c.fullName;return!(binm)?d.onError(N("notloaded","Module name '"+c.fullName+"' has not been loaded yet for context: "+a)):m[b]}(b&&b.length||c)&&x(null,b,c,f);if(!g.requireWait)for(;!g.scriptCount&&g.paused.length;)g.takeGlobalQueue(),w();returng.require},takeGlobalQueue:function(){U.length&&(ha.apply(g.defQueue,[g.defQueue.length-1,0].concat(U)),U=[])},completeLoad:function(b){vara;for(g.takeGlobalQueue();P.length;)if(a=P.shift(),a[0]===null){a[0]=b;break}elseif(a[0]===b)break;
returnn[g]}}functionD(){varb=q.waitSeconds*1E3,b=b&&i.startTime+b<(newDate).getTime(),a="",c=!1,l=!1,k=[],h,e;if(!(i.pausedCount>0)){if(q.priorityWait)if(j())z();elsereturn;for(hinr)if(!(hinK)&&(c=!0,!r[h]))if(b)a+=h+"";elseif(l=!0,h.indexOf("!")===-1){k=[];break}else(e=L[h]&&L[h].moduleDeps)&&k.push.apply(k,e);if(c||i.waitCount){if(b&&a)returnb=O("timeout","Load timeout for modules: "+a),b.requireType="timeout",b.requireModules=a,b.contextName=i.contextName,d.onError(b);if(l&&k.length)for(a=
A},require:function(b,c,g){if(typeofb==="string"){if(J(c))returnd.onError(O("requireargs","Invalid require call"));if(d.get)returnd.get(i,b,c);c=l(b,c);b=c.fullName;return!(binn)?d.onError(O("notloaded","Module name '"+c.fullName+"' has not been loaded yet for context: "+a)):n[b]}(b&&b.length||c)&&B(null,b,c,g);if(!i.requireWait)for(;!i.scriptCount&&i.paused.length;)z();returni.require},takeGlobalQueue:function(){T.length&&(ia.apply(i.defQueue,[i.defQueue.length-1,0].concat(T)),T=[])},completeLoad:function(b){vara;
"undefined")returnnewXMLHttpRequest;elsefor(b=0;b<3;b++){c=k[b];try{a=newActiveXObject(c)}catch(e){}if(a){k=[c];break}}if(!a)throwError("createXhr(): XMLHttpRequest not available");returna},get:h,parseName:function(a){varb=!1,c=a.indexOf("."),e=a.substring(0,c),a=a.substring(c+1,a.length),c=a.indexOf("!");c!==-1&&(b=a.substring(c+1,a.length),b=b==="strip",a=a.substring(0,c));return{moduleName:e,ext:a,strip:b}},xdRegExp:/^((\w+)\:)?\/\/([^\/\\]+)/,useXhr:function(a,b,c,e){vard=g.xdRegExp.exec(a),
b;if(typeofXMLHttpRequest!=="undefined")returnnewXMLHttpRequest;elsefor(c=0;c<3;c++){b=k[c];try{a=newActiveXObject(b)}catch(e){}if(a){k=[b];break}}if(!a)throwError("createXhr(): XMLHttpRequest not available");returna},get:h,parseName:function(a){varc=!1,b=a.indexOf("."),e=a.substring(0,b),a=a.substring(b+1,a.length),b=a.indexOf("!");b!==-1&&(c=a.substring(b+1,a.length),c=c==="strip",a=a.substring(0,b));return{moduleName:e,ext:a,strip:c}},xdRegExp:/^((\w+)\:)?\/\/([^\/\\]+)/,useXhr:function(a,
d!==void0;a==null&&(a=[]);if(x&&a.reduce===x)returne&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)thrownewTypeError("Reduce of empty array with no initial value");returnd};b.reduceRight=b.foldr=function(a,c,d,e){a==null&&(a=[]);if(y&&a.reduceRight===y)returne&&(c=b.bind(c,e)),d!==void0?a.reduceRight(c,d):a.reduceRight(c);a=(b.isArray(a)?a.slice():b.toArray(a)).reverse();returnb.reduce(a,c,d,e)};b.find=b.detect=function(a,c,b){vare;