text: (function(){var e,i=this,t=i.Backbone,o=Array.prototype.slice,a=Array.prototype.splice;e="undefined"!=typeof exports?exports:i.Backbone={},e.VERSION="0.9.2";var l=i._;l||"undefined"==typeof require||(l=require("alloy/underscore"));var r=i.jQuery||i.Zepto||i.ender;e.setDomLibrary=function(e){r=e},e.noConflict=function(){return i.Backbone=t,this},e.emulateHTTP=!1,e.emulateJSON=!1;var _=/\s+/,d=e.Events={on:function(e,i,t){var o,a,l,r,d;if(!i)return this;for(e=e.split(_),o=this._callbacks||(this._callbacks={});a=e.shift();)d=o[a],l=d?d.tail:{},l.next=r={},l.context=t,l.callback=i,o[a]={tail:r,next:d?d.next:l};return this},off:function(e,i,t){var o,a,r,d,s,n;if(a=this._callbacks){if(!(e||i||t))return delete this._callbacks,this;for(e=e?e.split(_):l.keys(a);o=e.shift();)if(r=a[o],delete a[o],r&&(i||t))for(d=r.tail;(r=r.next)!==d;)s=r.callback,n=r.context,(i&&s!==i||t&&n!==t)&&this.on(o,s,n);return this}},trigger:function(e){var i,t,a,l,r,d,s;if(!(a=this._callbacks))return this;for(d=a.all,e=e.split(_),s=o.call(arguments,1);i=e.shift();){if(t=a[i])for(l=t.tail;(t=t.next)!==l;)t.callback.apply(t.context||this,s);if(t=d)for(l=t.tail,r=[i].concat(s);(t=t.next)!==l;)t.callback.apply(t.context||this,r)}return this}};d.bind=d.on,d.unbind=d.off;var s=e.Model=function(e,i){var t;e||(e={}),i&&i.parse&&(e=this.parse(e)),(t=k(this,"defaults"))&&(e=l.extend({},t,e)),i&&i.collection&&(this.collection=i.collection),this.attributes={},this._escapedAttributes={},this.cid=l.uniqueId("c"),this.changed={},this._silent={},this._pending={},this.set(e,{silent:!0}),this.changed={},this._silent={},this._pending={},this._previousAttributes=l.clone(this.attributes),this.initialize.apply(this,arguments)};l.extend(s.prototype,d,{changed:null,_silent:null,_pending:null,idAttribute:"id",initialize:function(){},toJSON:function(){return l.clone(this.attributes)},get:function(e){return this.attributes[e]},escape:function(e){var i;if(i=this._escapedAttributes[e])return i;var t=this.get(e);return this._escapedAttributes[e]=l.escape(null==t?"":""+t)},has:function(e){return null!=this.get(e)},set:function(e,i,t){var o,a,r;if(l.isObject(e)||null==e?(o=e,t=i):(o={},o[e]=i),t||(t={}),!o)return this;if(o instanceof s&&(o=o.attributes),t.unset)for(a in o)o[a]=void 0;if(!this._validate(o,t))return!1;this.idAttribute in o&&(this.id=o[this.idAttribute]);var _=t.changes={},d=this.attributes,n=this._escapedAttributes,c=this._previousAttributes||{};for(a in o)r=o[a],(!l.isEqual(d[a],r)||t.unset&&l.has(d,a))&&(delete n[a],(t.silent?this._silent:_)[a]=!0),t.unset?delete d[a]:d[a]=r,l.isEqual(c[a],r)&&l.has(d,a)==l.has(c,a)?(delete this.changed[a],delete this._pending[a]):(this.changed[a]=r,t.silent||(this._pending[a]=!0));return t.silent||this.change(t),this},unset:function(e,i){return(i||(i={})).unset=!0,this.set(e,null,i)},clear:function(e){return(e||(e={})).unset=!0,this.set(l.clone(this.attributes),e)},fetch:function(i){i=i?l.clone(i):{};var t=this,o=i.success;return i.success=function(e,a,l){return t.set(t.parse(e,l),i)?void(o&&o(t,e)):!1},i.error=e.wrapError(i.error,t,i),(this.sync||e.sync).call(this,"read",this,i)},save:function(i,t,o){var a,r;if(l.isObject(i)||null==i?(a=i,o=t):(a={},a[i]=t),o=o?l.clone(o):{},o.wait){if(!this._validate(a,o))return!1;r=l.clone(this.attributes)}var _=l.extend({},o,{silent:!0});if(a&&!this.set(a,o.wait?_:o))return!1;var d=this,s=o.success;o.success=function(e,i,t){var r=d.parse(e,t);return o.wait&&(delete o.wait,r=l.extend(a||{},r)),d.set(r,o)?void(s?s(d,e):d.trigger("sync",d,e,o)):!1},o.error=e.wrapError(o.error,d,o);var n=this.isNew()?"create":"update",c=(this.sync||e.sync).call(this,n,this,o);return o.wait&&this.set(r,_),c},destroy:function(i){i=i?l.clone(i):{};var t=this,o=i.success,a=function(){t.trigger("destroy",t,t.collection,i)};if(this.isNew())return a(),!1;i.success=function(e){i.wait&&a(),o?o(t,e):t.trigger("sync",t,e,i)},i.error=e.wrapError(i.error,t,i);var r=(this.sync||e.sync).call(this,"delete",this,i);return i.wait||a(),r},url:function(){var e=k(this,"urlRoot")||k(this.collection,"url")||A();return this.isNew()?e:e+("/"==e.charAt(e.length-1)?"":"/")+encodeURIComponent(this.id)},parse:function(e){return e},clone:function(){return new this.constructor(this.attributes)},isNew:function(){return null==this.id},change:function(e){e||(e={});var i=this._changing;this._changing=!0;for(var t in this._silent)this._pending[t]=!0;var o=l.extend({},e.changes,this._silent);this._silent={};for(var t in o)this.trigger("change:"+t,this,this.get(t),e);if(i)return this;for(;!l.isEmpty(this._pending);){this._pending={},this.trigger("change",this,e);for(var t in this.changed)this._pending[t]||this._silent[t]||delete this.changed[t];this._previousAttributes=l.clone(this.attributes)}return this._changing=!1,this},hasChanged:function(e){return arguments.length?l.has(this.changed,e):!l.isEmpty(this.changed)},changedAttributes:function(e){if(!e)return this.hasChanged()?l.clone(this.changed):!1;var i,t=!1,o=this._previousAttributes;for(var a in e)l.isEqual(o[a],i=e[a])||((t||(t={}))[a]=i);return t},previous:function(e){return arguments.length&&this._previousAttributes?this._previousAttributes[e]:null},previousAttributes:function(){return l.clone(this._previousAttributes)},isValid:function(){return!this.validate(this.attributes)},_validate:function(e,i){if(i.silent||!this.validate)return!0;e=l.extend({},this.attributes,e);var t=this.validate(e,i);return t?(i&&i.error?i.error(this,t,i):this.trigger("error",this,t,i),!1):!0}});var n=e.Collection=function(e,i){i||(i={}),i.model&&(this.model=i.model),i.comparator&&(this.comparator=i.comparator),this._reset(),this.initialize.apply(this,arguments),e&&this.reset(e,{silent:!0,parse:i.parse})};l.extend(n.prototype,d,{model:s,initialize:function(){},toJSON:function(e){return this.map(function(i){return i.toJSON(e)})},add:function(e,i){var t,o,r,_,d,s,n={},c={},f=[];for(i||(i={}),e=l.isArray(e)?e.slice():[e],t=0,r=e.length;r>t;t++){if(!(_=e[t]=this._prepareModel(e[t],i)))throw new Error("Can't add an invalid model to a collection");d=_.cid,s=_.id,n[d]||this._byCid[d]||null!=s&&(c[s]||this._byId[s])?f.push(t):n[d]=c[s]=_}for(t=f.length;t--;)e.splice(f[t],1);for(t=0,r=e.length;r>t;t++)(_=e[t]).on("all",this._onModelEvent,this),this._byCid[_.cid]=_,null!=_.id&&(this._byId[_.id]=_);if(this.length+=r,o=null!=i.at?i.at:this.models.length,a.apply(this.models,[o,0].concat(e)),this.comparator&&this.sort({silent:!0}),i.silent)return this;for(t=0,r=this.models.length;r>t;t++)n[(_=this.models[t]).cid]&&(i.index=t,_.trigger("add",_,this,i));return this},remove:function(e,i){var t,o,a,r;for(i||(i={}),e=l.isArray(e)?e.slice():[e],t=0,o=e.length;o>t;t++)r=this.getByCid(e[t])||this.get(e[t]),r&&(delete this._byId[r.id],delete this._byCid[r.cid],a=this.indexOf(r),this.models.splice(a,1),this.length--,i.silent||(i.index=a,r.trigger("remove",r,this,i)),this._removeReference(r));return this},push:function(e,i){return e=this._prepareModel(e,i),this.add(e,i),e},pop:function(e){var i=this.at(this.length-1);return this.remove(i,e),i},unshift:function(e,i){return e=this._prepareModel(e,i),this.add(e,l.extend({at:0},i)),e},shift:function(e){var i=this.at(0);return this.remove(i,e),i},get:function(e){return null==e?void 0:this._byId[null!=e.id?e.id:e]},getByCid:function(e){return e&&this._byCid[e.cid||e]},at:function(e){return this.models[e]},where:function(e){return l.isEmpty(e)?[]:this.filter(function(i){for(var t in e)if(e[t]!==i.get(t))return!1;return!0})},sort:function(e){if(e||(e={}),!this.comparator)throw new Error("Cannot sort a set without a comparator");var i=l.bind(this.comparator,this);return 1==this.comparator.length?this.models=this.sortBy(i):this.models.sort(i),e.silent||this.trigger("reset",this,e),this},pluck:function(e){return l.map(this.models,function(i){return i.get(e)})},reset:function(e,i){e||(e=[]),i||(i={});for(var t=0,o=this.models.length;o>t;t++)this._removeReference(this.models[t]);return this._reset(),this.add(e,l.extend({silent:!0},i)),i.silent||this.trigger("reset",this,i),this},fetch:function(i){i=i?l.clone(i):{},void 0===i.parse&&(i.parse=!0);var t=this,o=i.success;return i.success=function(e,a,l){t[i.add?"add":"reset"](t.parse(e,l),i),o&&o(t,e)},i.error=e.wrapError(i.error,t,i),(this.sync||e.sync).call(this,"read",this,i)},create:function(e,i){var t=this;if(i=i?l.clone(i):{},e=this._prepareModel(e,i),!e)return!1;i.wait||t.add(e,i);var o=i.success;return i.success=function(a,l){i.wait&&t.add(a,i),o?o(a,l):a.trigger("sync",e,l,i)},e.save(null,i),e},parse:function(e){return e},chain:function(){return l(this.models).chain()},_reset:function(){this.length=0,this.models=[],this._byId={},this._byCid={}},_prepareModel:function(e,i){if(i||(i={}),e instanceof s)e.collection||(e.collection=this);else{var t=e;i.collection=this,e=new this.model(t,i),e._validate(e.attributes,i)||(e=!1)}return e},_removeReference:function(e){this==e.collection&&delete e.collection,e.off("all",this._onModelEvent,this)},_onModelEvent:function(e,i,t,o){("add"!=e&&"remove"!=e||t==this)&&("destroy"==e&&this.remove(i,o),i&&e==="change:"+i.idAttribute&&(delete this._byId[i.previous(i.idAttribute)],this._byId[i.id]=i),this.trigger.apply(this,arguments))}});var c=["forEach","each","map","reduce","reduceRight","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","max","min","sortBy","sortedIndex","toArray","size","first","initial","rest","last","without","indexOf","shuffle","lastIndexOf","isEmpty","groupBy"];l.each(c,function(e){n.prototype[e]=function(){return l[e].apply(l,[this.models].concat(l.toArray(arguments)))}});var f=e.Router=function(e){e||(e={}),e.routes&&(this.routes=e.routes),this._bindRoutes(),this.initialize.apply(this,arguments)},p=/:\w+/g,h=/\*\w+/g,g=/[-[\]{}()+?.,\\^$|#\s]/g;l.extend(f.prototype,d,{initialize:function(){},route:function(i,t,o){return e.history||(e.history=new y),l.isRegExp(i)||(i=this._routeToRegExp(i)),o||(o=this[t]),e.history.route(i,l.bind(function(a){var l=this._extractParameters(i,a);o&&o.apply(this,l),this.trigger.apply(this,["route:"+t].concat(l)),e.history.trigger("route",this,t,l)},this)),this},navigate:function(i,t){e.history.navigate(i,t)},_bindRoutes:function(){if(this.routes){var e=[];for(var i in this.routes)e.unshift([i,this.routes[i]]);for(var t=0,o=e.length;o>t;t++)this.route(e[t][0],e[t][1],this[e[t][1]])}},_routeToRegExp:function(e){return e=e.replace(g,"\\$&").replace(p,"([^/]+)").replace(h,"(.*?)"),new RegExp("^"+e+"$")},_extractParameters:function(e,i){return e.exec(i).slice(1)}});var y=e.History=function(){this.handlers=[],l.bindAll(this,"checkUrl")},I=/^[#\/]/,u=/msie [\w.]+/;y.started=!1,l.extend(y.prototype,d,{interval:50,getHash:function(e){var i=e?e.location:window.location,t=i.href.match(/#(.*)$/);return t?t[1]:""},getFragment:function(e,i){if(null==e)if(this._hasPushState||i){e=window.location.pathname;var t=window.location.search;t&&(e+=t)}else e=this.getHash();return e.indexOf(this.options.root)||(e=e.substr(this.options.root.length)),e.replace(I,"")},start:function(e){if(y.started)throw new Error("Backbone.history has already been started");y.started=!0,this.options=l.extend({},{root:"/"},this.options,e),this._wantsHashChange=this.options.hashChange!==!1,this._wantsPushState=!!this.options.pushState,this._hasPushState=!!(this.options.pushState&&window.history&&window.history.pushState);var i=this.getFragment(),t=document.documentMode,o=u.exec(navigator.userAgent.toLowerCase())&&(!t||7>=t);o&&(this.iframe=r('<iframe src="javascript:0" tabindex="-1" />').hide().appendTo("body")[0].contentWindow,this.navigate(i)),this._hasPushState?r(window).bind("popstate",this.checkUrl):this._wantsHashChange&&"onhashchange"in window&&!o?r(window).bind("hashchange",this.checkUrl):this._wantsHashChange&&(this._checkUrlInterval=setInterval(this.checkUrl,this.interval)),this.fragment=i;var a=window.location,_=a.pathname==this.options.root;return this._wantsHashChange&&this._wantsPushState&&!this._hasPushState&&!_?(this.fragment=this.getFragment(null,!0),window.location.replace(this.options.root+"#"+this.fragment),!0):(this._wantsPushState&&this._hasPushState&&_&&a.hash&&(this.fragment=this.getHash().replace(I,""),window.history.replaceState({},document.title,a.protocol+"//"+a.host+this.options.root+this.fragment)),this.options.silent?void 0:this.loadUrl())},stop:function(){r(window).unbind("popstate",this.checkUrl).unbind("hashchange",this.checkUrl),clearInterval(this._checkUrlInterval),y.started=!1},route:function(e,i){this.handlers.unshift({route:e,callback:i})},checkUrl:function(){var e=this.getFragment();return e==this.fragment&&this.iframe&&(e=this.getFragment(this.getHash(this.iframe))),e==this.fragment?!1:(this.iframe&&this.navigate(e),void(this.loadUrl()||this.loadUrl(this.getHash())))},loadUrl:function(e){var i=this.fragment=this.getFragment(e),t=l.any(this.handlers,function(e){return e.route.test(i)?(e.callback(i),!0):void 0});return t},navigate:function(e,i){if(!y.started)return!1;i&&i!==!0||(i={trigger:i});var t=(e||"").replace(I,"");this.fragment!=t&&(this._hasPushState?(0!=t.indexOf(this.options.root)&&(t=this.options.root+t),this.fragment=t,window.history[i.replace?"replaceState":"pushState"]({},document.title,t)):this._wantsHashChange?(this.fragment=t,this._updateHash(window.location,t,i.replace),this.iframe&&t!=this.getFragment(this.getHash(this.iframe))&&(i.replace||this.iframe.document.open().close(),this._updateHash(this.iframe.location,t,i.replace))):window.location.assign(this.options.root+e),i.trigger&&this.loadUrl(e))},_updateHash:function(e,i,t){t?e.replace(e.toString().replace(/(javascript:|#).*$/,"")+"#"+i):e.hash=i}});var w=e.View=function(e){this.cid=l.uniqueId("view"),this._configure(e||{}),this._ensureElement(),this.initialize.apply(this,arguments),this.delegateEvents()},T=/^(\S+)\s*(.*)$/,b=["model","collection","el","id","attributes","className","tagName"];l.extend(w.prototype,d,{tagName:"div",$:function(e){return this.$el.find(e)},initialize:function(){},render:function(){return this},remove:function(){return this.$el.remove(),this},make:function(e,i,t){var o=document.createElement(e);return i&&r(o).attr(i),t&&r(o).html(t),o},setElement:function(e,i){return this.$el&&this.undelegateEvents(),this.$el=e instanceof r?e:r(e),this.el=this.$el[0],i!==!1&&this.delegateEvents(),this},delegateEvents:function(e){if(e||(e=k(this,"events"))){this.undelegateEvents();for(var i in e){var t=e[i];if(l.isFunction(t)||(t=this[e[i]]),!t)throw new Error('Method "'+e[i]+'" does not exist');var o=i.match(T),a=o[1],r=o[2];t=l.bind(t,this),a+=".delegateEvents"+this.cid,""===r?this.$el.bind(a,t):this.$el.delegate(r,a,t)}}},undelegateEvents:function(){this.$el.unbind(".delegateEvents"+this.cid)},_configure:function(e){this.options&&(e=l.extend({},this.options,e));for(var i=0,t=b.length;t>i;i++){var o=b[i];e[o]&&(this[o]=e[o])}this.options=e},_ensureElement:function(){if(this.el)this.setElement(this.el,!1);else{var e=k(this,"attributes")||{};this.id&&(e.id=this.id),this.className&&(e["class"]=this.className),this.setElement(this.make(this.tagName,e),!1)}}});var v=function(e,i){var t=C(this,e,i);return t.extend=this.extend,t};s.extend=n.extend=f.extend=w.extend=v;var m={create:"POST",update:"PUT","delete":"DELETE",read:"GET"};e.sync=function(i,t,o){var a=m[i];o||(o={});var _={type:a,dataType:"json"};return o.url||(_.url=k(t,"url")||A()),o.data||!t||"create"!=i&&"update"!=i||(_.contentType="application/json",_.data=JSON.stringify(t.toJSON())),e.emulateJSON&&(_.contentType="application/x-www-form-urlencoded",_.data=_.data?{model:_.data}:{}),e.emulateHTTP&&("PUT"===a||"DELETE"===a)&&(e.emulateJSON&&(_.data._method=a),_.type="POST",_.beforeSend=function(e){e.setRequestHeader("X-HTTP-Method-Override",a)}),"GET"===_.type||e.emulateJSON||(_.processData=!1),r.ajax(l.extend(_,o))},e.wrapError=function(e,i,t){return function(o,a){a=o===i?a:o,e?e(i,a,t):i.trigger("error",i,a,t)}};var E=function(){},C=function(e,i,t){var o;return o=i&&i.hasOwnProperty("constructor")?i.constructor:function(){e.apply(this,arguments)},l.extend(o,e),E.prototype=e.prototype,o.prototype=new E,i&&l.extend(o.prototype,i),t&&l.extend(o,t),o.prototype.constructor=o,o.__super__=e.prototype,o},k=function(e,i){return e&&e[i]?l.isFunction(e[i])?e[i]():e[i]:null},A=function(){throw new Error('A "url" property or function must be specified')}}).call(this);