!function(){function e(a,b){function c(b){arguments.length?(c.old_value=c.value,c.value=d?b:a(b),c.emitset()):(j.checking&&j.emit("get",c),d||(c.value=a()));return c.value}var d="function"!=typeof a;d?c.value=a:(c.dependencies=[],s(j(c),function(a){c.dependencies.push(a);a.change(function(){c.emitset()})}));h(c,n,v);b&&(c.type=b);return c}function j(a){function b(b){var f;a:if(f=c,f.indexOf)f=f.indexOf(b,void 0);else{for(var i=0,e=f.length;i<e;i++)if(f[i]===b){f=i;break a}f=-1}0>f&&b!=a&&c.push(b)}
var c=[];j.checking=!0;j.on("get",b);j.lastResult=a();j.off("get",b);j.checking=!1;return c}function w(a){if(!a)return[];var a=o(a).split(";"),b=[],c,d,f;for(c=0;c<a.length;c++)if(f=o(a[c])){f=o(f).split(":");d=o;for(var e=[],k=0;k<f.length;k++)e[k]=d(f[k],k);d=e;f=o(d.shift());d=o(d.join(":"))||f;b.push([f,d])}return b}function p(a){var b=a.data("o_O:template");null==b&&(b=a.html(),a.html(""),a.data("o_O:template",b));return b}function x(a,b){return function(){return a.apply(b,arguments)}}function g(a,
b){if(!(this instanceof g))return new g(a,b);a=a||{};this.properties=[];for(var c in a)g.addProperty(this,c,a[c]),g.observeProperty(this,c);var d=this.constructor.defaults;for(c in d)c in a||(g.addProperty(this,c,d[c]),g.observeProperty(this,c));b&&h(this,b);this.initialize.apply(this,arguments)}function l(a){if(!(this instanceof l))return new l(a);var b=this;this.items=[];this.count=e(0);this.length=0;this.count.change(function(a){b.length=a});if(a)for(var c=0;c<a.length;c++)this.push(a[c]);this.initialize()}
function h(a){for(var b=t.call(arguments,1),c=0;c<b.length;c++){var d=b[c],f;for(f in d)a[f]=d[f]}return a}function s(a,b){if(a.forEach)return a.forEach(b);for(var c=0,d=a.length;c<d;c++)c in a&&b.call(null,a[c],c,a)}function o(a){return a.replace(/^\s+|\s+$/g,"")}function u(){}function r(a,b,c){var d=function(b,c){if(this instanceof d)a.apply(this,arguments);else return new d(b,c)};b&&b.hasOwnProperty("constructor")&&(d=b.constructor);h(d,a);u.prototype=a.prototype;d.prototype=new u;b&&h(d.prototype,
b);c&&h(d,c);d.prototype.constructor=d;d.__super__=a.prototype;return d}var t=Array.prototype.slice,n={on:function(a,b,c){for(var d,a=a.split(/\s+/),f=this._callbacks||(this._callbacks={});d=a.shift();){d=f[d]||(f[d]={});var e=d.tail||(d.tail=d.next={});e.callback=b;e.context=c;d.tail=e.next={}}return this},off:function(a,b,c){var d,f,e;if(a){if(f=this._callbacks)for(a=a.split(/\s+/);d=a.shift();)if(e=f[d],delete f[d],b&&e)for(;(e=e.next)&&e.next;)if(!(e.callback===b&&(!c||e.context===c)))this.on(d,
e.callback,e.context)}else delete this._callbacks;return this},emit:function(a){var b,c,d,e;if(!(d=this._callbacks))return this;e=d.all;for((a=a.split(/\s+/)).push(null);b=a.shift();)e&&a.push({next:e.next,tail:e.tail,event:b}),(c=d[b])&&a.push({next:c.next,tail:c.tail});for(e=t.call(arguments,1);c=a.pop();){b=c.tail;for(d=c.event?[c.event].concat(e):e;(c=c.next)!==b;)c.callback.apply(c.context||this,d)}return this}},v={incr:function(a){return this(this.value+(a||1))},scale:function(a){return this(this.value*
(a||1))},toggle:function(){return this(!this.value)},change:function(a){a?this.on("set",a):this.emit("set",this(),this.old_val);return this},mirror:function(a,b){a.change(function(a){a!=this.value&&this(a)});a.change();b&&a.mirror(this);return this},toString:function(){return"<"+(this.type?this.type+":":"")+this.value+">"},bind:function(a){e.bind(this,a);return this},emitset:function(){this._emitting||(this._emitting=!0,this.emit("set",this(),this.old_value),delete this._emitting)},constructor:e};
h(j,n);e.dependencies=j;e.expression=function(a){e.expression.last=a;return new Function("o_O","with(this) { return ("+a+"); } ")};e.nextFrame=function(){function a(){for(;b.length;)b.shift()();c=null}var b=[],c,d=this,e=d.requestAnimationFrame||d.webkitRequestAnimationFrame||d.mozRequestAnimationFrame||d.oRequestAnimationFrame||d.msRequestAnimationFrame||function(a){d.setTimeout(a,1E3/60)};return function(d){b.push(d);c=c||e(a)}}();e.bindRuleToElement=function(a,b,c,d){function f(){m=i.call(c,e.helpers);
m instanceof String&&(m=m.toString())}var i=e.expression(b),k=e.createBinding(a),g=$(d),m;if("outbound"==k.type)f(),k.call(c,m,g);else{a=j(f);"function"==typeof m&&"twoway"!=k.type&&(i=e.expression("("+b+")()"),a=j(f));k.call(c,m,g);var h;s(a,function(a){a.change(function(){f();if(!h){h=true;e.nextFrame(function(){k.call(c,m,g);h=false})}})})}};e.bind=function(a,b,c){b=$(b);c||(a.el=b[0]);for(var c=!0,d=w(b.attr(e.bindingAttribute)),f=0;f<d.length;f++){var i=d[f][0],g=d[f][1];if("with"==i||"foreach"==
i)c=!1;'"class"'==i&&(i="class");e.bindRuleToElement(i,g,a,b)}e.removeBindingAttribute&&b.attr(e.bindingAttribute,null);c&&b.children().each(function(b,c){e.bind(a,c,true)})};e.helpers={value:function(a){return function(b){return a.call(this,$(b.currentTarget).val(),b)}},position:function(a){return function(b){var c=$(b.currentTarget).offset();a.call(this,b.pageX-c.left,b.pageY-c.top,b)}}};e.bindings={visible:function(a,b){a?b.show():b.hide()},"if":function(a,b){var c=p(b);b.html(a?c:"")},unless:function(a,
b){return e.bindings["if"](!a,b)},"with":function(a,b){var c=p(b);b.html(a?c:"");a&&e.bind(a,b)},options:function(a,b){var c=a instanceof Array;$.each(a,function(a,e){var i=c?e:a;b.append($("<option>").attr("value",e).html(i))})},foreach:function(a,b){function c(a){$(d).each(function(c,d){var f=$(d);f.appendTo(b);e.bind(a,f)})}var d=p(b),f=a.renderItem||c;b.html("");a.forEach(function(c,d){f.call(a,c,b,d)});a.onbind&&a.onbind(b)},log:function(a,b){console.log("o_O",a,b,this)}};e.bindings.call=function(a,
b){a.call(this,b)};e.bindings.call.type="outbound";e.bindings.value=function(a,b){b.change(function(b){var d="checkbox"==$(this).attr("type")?!!$(this).attr("checked"):$(this).val();a(d,b)});a.constructor==e&&(a.on("set",function(a){"checkbox"==b.attr("type")?b.attr("checked",a?"checked":null):b.val(a)}),a.change())};e.bindings.value.type="twoway";e.bindingTypes={focus:"outbound",blur:"outbound",change:"outbound",submit:"outbound",keypress:"outbound",keydown:"outbound",keyup:"outbound",click:"outbound",
mouseover:"outbound",mouseout:"outbound",mousedown:"outbound",mousemove:"outbound",mouseup:"outbound",dblclick:"outbound",load:"outbound"};e.createBinding=function(a){var b;b=e.bindings[a]?e.bindings[a]:a in $.prototype?function(b,d){"function"==typeof b&&(b=x(b,this));return d[a](b)}:function(b,d){return d.attr(a,b)};b.type=b.type||e.bindingTypes[a]||"inbound";return b};h(g,n,{observeProperty:function(a,b){a[b].on("set",function(c,d){a.emit("set:"+b,a,c,d);if(c!==d){var e={},g={};e[b]=c;g[b]=d;a.emit("update",
a,e,g)}})},addProperty:function(a,b,c){a[b]=e(c);a.properties.push(b)},defaults:{},types:{},extend:function(a,b,c){a=a||{};b=r(this,b,c);b.defaults=a;b.extend=this.extend;a.type&&(g.types[a.type]=b);return b},create:function(a){var a=a||{},b=this==g?g.types[a.type]:this;if(!b)throw Error("no such Model with type: "+a.type);return new b(a)}});h(g.prototype,n,{toString:function(){return"#<"+(this.type?this.type():"model")+">"},bind:function(a){e.bind(this,a);return this},initialize:function(){},valid:function(){return!0},
update:function(a){var b={},c=this.constructor.defaults,d;for(d in a)d in c&&(b[d]=this[d].value,this[d].value=a[d]);if(this.valid()){for(d in b)this[d].value=b[d],this[d](a[d]);this.emit("update",this,a,b);return b}for(d in b)this[d](b[d]);return!1},destroy:function(){this.emit("destroy",this)},toJSON:function(){for(var a={},b=0;b<this.properties.length;b++){var c=this.properties[b];a[c]=this[c]()}return a},clone:function(){return g.create(this.toJSON())}});e.model=g;h(l,{add:function(a,b,c){a.count.incr();
b.on&&b.emit?(b.on("all",a._onevent,a),b.emit("add",b,a,c)):a.emit("add",b,a,c);return a.items.length},remove:function(a,b,c){a.count.incr(-1);b.off&&b.emit?(b.emit("remove",b,a,c),b.off("all",a._onevent,a)):a.emit("remove",b,c);return b},extend:function(a,b){var c=r(this,a,b);c.extend=this.extend;return c}});h(l.prototype,n,{type:"o_O.array",initialize:function(){},_onevent:function(a,b,c){("add"==a||"remove"==a)&&c!=this||("destroy"==a&&this.remove(b),this.emit.apply(this,arguments))},bind:function(a){e.bind(this,
a);return this},indexOf:function(a){return this.items.indexOf(a)},filter:function(a){return this.items.filter(a)},find:function(a){for(var b=0;b<this.items.length;b++){var c=this.items[b];if(a(c,b))return c}},map:function(a){this.count();for(var b=[],c=0;c<this.length;c++){var d=a.call(this,this.items[c],c);b.push(d)}return b},push:function(a){return this.insert(a,this.length)},unshift:function(a){return this.insert(a,0)},pop:function(){return this.removeAt(this.length-1)},shift:function(){return this.removeAt(0)},
at:function(a){return this.items[a]},insert:function(a,b){if(0>b||b>this.count())return!1;this.items.splice(b,0,a);l.add(this,a,b);return a},removeAt:function(a){if(0>a||a>this.count())return!1;var b=this.items[a];this.items.splice(a,1);l.remove(this,b,a);return b},remove:function(a){for(var b="function"===typeof a,a=b?this.items.filter(a):[a],c,d=a.length,e=0;e<d;e++)c=this.indexOf(a[e]),-1!==c&&this.removeAt(c);return b?a:a[0]},renderItem:function(a,b,c){var d=$(p(b));(c=this.at(c).el||b.children()[c])?
d.insertBefore(c):b.append(d);e.bind(a,d)},onbind:function(a){var b=this;this.on("add",function(c,d,e){b.renderItem(c,a,e)});this.on("remove",this.removeElement,this);this.el=a[0]},removeElement:function(a,b){$(a.el||$(this.el).children()[b]).remove()},toString:function(){return"#<"+this.type+":"+this.length+">"},toJSON:function(){return this.map(function(a){return a.toJSON?a.toJSON():a})}});l.prototype.each=l.prototype.forEach=l.prototype.map;e.array=l;e.uuid=function(){return Math.random().toString(36).slice(2)};
h(e,{bindingAttribute:"data-bind",removeBindingAttribute:!0,inherits:r,extend:h,Events:n,VERSION:"0.2.6"});if("undefined"==typeof module){var q=document.getElementsByTagName("script"),q=q[q.length-1].src.split("?")[1];window[q||"o_O"]=e}else module.exports=e}();
