(function(){var e=function(e){var t=this;e.require().script("mvc/model").done(function(){var n=function(){var t=function(t){return t[0]&&e.isArray(t[0])?t[0]:t[0]instanceof e.Model.List?e.makeArray(t[0]):e.makeArray(t)},n=0,r=function(e){return e[e.constructor.id]},i=e.expando,s=e.each,o=e.Model._ajax,u={update:function(e){return function(t,n,r,i){return o(e,{ids:t,attrs:n},r,i,"-updateAll","put")}},destroy:function(e){return function(t,n,r){return o(e,t,n,r,"-destroyAll","post")}}};e.Class(e.globalNamespace+".Model.List",{setup:function(){for(var e in u)typeof this[e]!="function"&&(this[e]=u[e](this[e]))}},{init:function(t,r){this.length=0,this._data={},this._namespace=".list"+ ++n,this.push.apply(this,e.makeArray(t||[]))},slice:function(){return new this.Class(Array.prototype.slice.apply(this,arguments))},match:function(e,t){return this.grep(function(n){return n[e]==t})},grep:function(t,n){return new this.Class(e.grep(this,t,n))},_makeData:function(){var e=this._data={};this.each(function(t,n){e[n[n.constructor.id]]=n})},get:function(){if(!this.length)return new this.Class([]);this._changed&&this._makeData();var e=[],n=this[0].constructor,r=n._fullName,i=n.id,s=RegExp(r+"_([^ ]+)"),o,u,a=t(arguments);for(var f=0;f<a.length;f++)a[f].nodeName&&(o=a[f].className.match(s))?u=this._data[o[1]]:u=this._data[typeof a[f]=="string"||typeof a[f]=="number"?a[f]:a[f][i]],u&&e.push(u);return new this.Class(e)},remove:function(n){if(!this.length)return[];var r=[],i=this[0].constructor,s=i._fullName,o=i.id,u=RegExp(s+"_([^ ]+)"),a,f;n=t(arguments);var l=0;while(l<this.length){var c=this[l],h=!1;for(var p=0;p<n.length;p++){var d=n[p].nodeName&&(a=n[p].className.match(u))&&a[1]||(typeof n[p]=="string"||typeof n[p]=="number"?n[p]:n[p][o]);if(c[o]==d){r.push.apply(r,this.splice(l,1)),n.splice(p,1),h=!0;break}}h||l++}var v=new this.Class(r);return v.length&&e([this]).trigger("remove",[v]),v},elements:function(t){return e(this.map(function(e){return"."+e.identity()}).join(","),t)},model:function(){return this.constructor.namespace},findAll:function(e,t,n){var r=this;this.model().findAll(e,function(e){r.push(e),t&&t(r)},n)},destroy:function(e,t){var n=this.map(r),i=this.slice(0,this.length);return n.length?this.constructor.destroy(n,function(){s(i,function(){this.destroyed()}),e&&e(i)},t):e&&e(this),this},update:function(t,n,i){var o=this.map(r),u=this.slice(0,this.length);return o.length?this.constructor.update(o,t,function(r){var i=e.extend(t,r||{});s(u,function(){this.updated(i)}),n&&n(u)},i):n&&n(this),this},bind:function(){return this[i]===undefined&&this.bindings(this),e.fn.bind.apply(e([this]),arguments),this},unbind:function(){return e.fn.unbind.apply(e([this]),arguments),this[i]===undefined&&e(this).unbind(this._namespace),this},bindings:function(t){var n=this;e(t).bind("destroyed"+this._namespace,function(){n.remove(this)}).bind("updated"+this._namespace,function(){e([n]).trigger("updated",this)})},push:function(){var n=t(arguments);this[i]!==undefined&&this.bindings(n),this._changed=!0;var r=a.apply(this,n);return this[i]&&n.length&&e([this]).trigger("add",[n]),r},serialize:function(){return this.map(function(e){return e.serialize()})}});var a=[].push,f={pop:[].pop,shift:[].shift,unshift:[].unshift,splice:[].splice,sort:[].sort,reverse:[].reverse};s(f,function(t,n){e.Model.List.prototype[t]=function(){return this._changed=!0,n.apply(this,arguments)}}),s(["each","map"],function(t,n){e.Model.List.prototype[n]=function(t,r){return e[n](this,t,r)}})};n(),t.resolveWith(n)})};dispatch("mvc/model.list").containing(e).to("Foundry/2.1 Modules")})();