!function(){var moduleFactory=function($){var module=this;$.require().script("mvc/class").done(function(){var exports=function(){var isArray=$.isArray,isObject=function(obj){return"object"==typeof obj&&null!==obj&&obj},makeArray=$.makeArray,each=$.each,hookup=function(val,prop,parent){return val instanceof $.Observe?unhookup([val],parent._namespace):val=isArray(val)?new $.Observe.List(val):new $.Observe(val),val.bind("change"+parent._namespace,function(ev){var args=$.makeArray(arguments),ev=args.shift();args[0]="*"===prop?parent.indexOf(val)+"."+args[0]:prop+"."+args[0],$.event.trigger(ev,args,parent)
}),val},unhookup=function(items,namespace){for(var item,i=0;i<items.length;i++)item=items[i],item&&item.unbind&&item.unbind("change"+namespace)},id=0,collecting=null,collect=function(){return collecting?void 0:(collecting=[],!0)},trigger=function(item,event,args){return item._init?void 0:collecting?(collecting.push({t:item,ev:event,args:args}),void 0):$.event.trigger(event,args,item,!0)},batchNum=0,sendCollection=function(){var cur,len=collecting.length,items=collecting.slice(0);collecting=null,batchNum++;for(var i=0;len>i;i++)cur=items[i],$.event.trigger({type:cur.ev,batchNum:batchNum},cur.args,cur.t)
},serialize=function(observe,how,where){return observe.each(function(name,val){where[name]=isObject(val)&&"function"==typeof val[how]?val[how]():val}),where};$.Class($.globalNamespace+".Observe",{init:function(obj){this._data={},this._namespace=".observe"+ ++id,this._init=!0,this.attrs(obj),delete this._init},attr:function(attr,val){return void 0===val?this._get(attr):(this._set(attr,val),this)},each:function(){return each.apply(null,[this.__get()].concat(makeArray(arguments)))},removeAttr:function(attr){var parts=isArray(attr)?attr:attr.split("."),prop=parts.shift(),current=this._data[prop];
return parts.length?current.removeAttr(parts):(delete this._data[prop],trigger(this,"change",[prop,"remove",void 0,current]),current)},_get:function(attr){var parts=isArray(attr)?attr:(""+attr).split("."),current=this.__get(parts.shift());return parts.length?current?current._get(parts):void 0:current},__get:function(attr){return attr?this._data[attr]:this._data},_set:function(attr,value){var parts=isArray(attr)?attr:(""+attr).split("."),prop=parts.shift(),current=this.__get(prop);if(isObject(current)&&parts.length)current._set(parts,value);
else{if(parts.length)throw"jQuery.Observe: set a property on an object that does not exist";if(value!==current){var changeType=this.__get().hasOwnProperty(prop)?"set":"add";this.__set(prop,isObject(value)?hookup(value,prop,this):value),trigger(this,"change",[prop,changeType,value,current]),current&&unhookup([current],this._namespace)}}},__set:function(prop,val){this._data[prop]=val,prop in this.constructor.prototype||(this[prop]=val)},bind:function(){return $.fn.bind.apply($([this]),arguments),this},unbind:function(){return $.fn.unbind.apply($([this]),arguments),this
},serialize:function(){return serialize(this,"serialize",{})},attrs:function(props,remove){if(void 0===props)return serialize(this,"attrs",{});props=$.extend(!0,{},props);var prop,collectingStarted=collect();for(prop in this._data){var curVal=this._data[prop],newVal=props[prop];void 0!==newVal?(isObject(curVal)&&isObject(newVal)?curVal.attrs(newVal,remove):curVal!=newVal&&this._set(prop,newVal),delete props[prop]):remove&&this.removeAttr(prop)}for(var prop in props)newVal=props[prop],this._set(prop,newVal);collectingStarted&&sendCollection()
}});var list=$.Observe($.globalNamespace+".Observe.List",{init:function(instances,options){this.length=0,this._namespace=".list"+ ++id,this._init=!0,this.bind("change",this.proxy("_changes")),this.push.apply(this,makeArray(instances||[])),$.extend(this,options),this.comparator&&this.sort(),delete this._init},_changes:function(ev,attr,how,newVal,oldVal){if(this.comparator&&/^\d+./.test(attr)){var index=+/^\d+/.exec(attr)[0],item=this[index],newIndex=this.sortedIndex(item);if(newIndex!==index)return[].splice.call(this,index,1),[].splice.call(this,newIndex,0,item),trigger(this,"move",[item,newIndex,index]),ev.stopImmediatePropagation(),trigger(this,"change",[attr.replace(/^\d+/,newIndex),how,newVal,oldVal]),void 0
}-1===attr.indexOf(".")&&("add"===how?trigger(this,how,[newVal,+attr]):"remove"===how&&trigger(this,how,[oldVal,+attr]))},sortedIndex:function(item){for(var i,itemCompare=item.attr(this.comparator),equaled=0,i=0;i<this.length;i++)if(item!==this[i]){if(itemCompare<=this[i].attr(this.comparator))return i+equaled}else equaled=-1;return i+equaled},__get:function(attr){return attr?this[attr]:this},__set:function(attr,val){this[attr]=val},serialize:function(){return serialize(this,"serialize",[])},splice:function(index,count){var i,args=makeArray(arguments);
for(i=2;i<args.length;i++){var val=args[i];isObject(val)&&(args[i]=hookup(val,"*",this))}void 0===count&&(count=args[1]=this.length-index);var removed=[].splice.apply(this,args);return count>0&&(trigger(this,"change",[""+index,"remove",void 0,removed]),unhookup(removed,this._namespace)),args.length>2&&trigger(this,"change",[""+index,"add",args.slice(2),removed]),removed},attrs:function(props,remove){if(void 0===props)return serialize(this,"attrs",[]);props=props.slice(0);for(var len=Math.min(props.length,this.length),collectingStarted=collect(),prop=0;len>prop;prop++){var curVal=this[prop],newVal=props[prop];
isObject(curVal)&&isObject(newVal)?curVal.attrs(newVal,remove):curVal!=newVal&&this._set(prop,newVal)}props.length>this.length?this.push(props.slice(this.length)):props.length<this.length&&remove&&this.splice(props.length),collectingStarted&&sendCollection()},sort:function(method,silent){var comparator=this.comparator,args=comparator?[function(a,b){return a=a[comparator],b=b[comparator],a===b?0:b>a?-1:1}]:[];[].sort.apply(this,args),!silent&&trigger(this,"reset")}}),getArgs=function(args){return args[0]&&$.isArray(args[0])?args[0]:makeArray(args)
};each({push:"length",unshift:0},function(name,where){list.prototype[name]=function(){for(var args=getArgs(arguments),len=where?this.length:0,i=0;i<args.length;i++){var val=args[i];isObject(val)&&(args[i]=hookup(val,"*",this))}if(1==args.length&&this.comparator){var index=this.sortedIndex(args[0]);return this.splice(index,0,args[0]),this.length}var res=[][name].apply(this,args);return this.comparator&&args.length>1?(this.sort(null,!0),trigger(this,"reset",[args])):trigger(this,"change",[""+len,"add",args,void 0]),res
}}),each({pop:"length",shift:0},function(name,where){list.prototype[name]=function(){var args=getArgs(arguments),len=where&&this.length?this.length-1:0,res=[][name].apply(this,args);return trigger(this,"change",[""+len,"remove",void 0,[res]]),res&&res.unbind&&res.unbind("change"+this._namespace),res}}),list.prototype.indexOf=[].indexOf||function(item){return $.inArray(item,this)},$.O=function(data,options){return isArray(data)||data instanceof $.Observe.List?new $.Observe.List(data,options):new $.Observe(data,options)
}};exports(),module.resolveWith(exports)})};dispatch("mvc/lang.observe").containing(moduleFactory).to("Foundry/2.1 Modules")}();