zk.Event=zk.$extends(zk.Object,{$init:function(e,m,p,r,q){this.currentTarget=this.target=e;this.name=m;(this.data=p)&&"object"==typeof p&&!jq.isArray(p)&&zk.$default(this,p);this.opts=r||{rtags:{}};if(this.domEvent=q)this.domTarget=q.target},addOptions:function(e){this.opts=zk.copy(this.opts,e)},stop:function(e){var m=!e||!e.revoke;if(!e||e.propagation)this.stopped=m;if(!e||e.dom)this.domStopped=m;e&&e.au&&(this.auStopped=m)}});
zWatch=function(){function e(a,c,b,h,d){for(var f=0,k=c.length;f<k;){var g=c[f++];var l=b;var e=a;g=jq.isArray(g)?g[1]:l[e];if(!g)throw(l.className||l)+":"+e+" not found";l=g;d?d.push([l,b]):l.apply(b,h)}"onSize"==a&&(a=b.onAfterSize)&&a.apply(b,h)}function m(a,c,b,h){var d=[],f=b.bindLevel,k=u[a]&&{},g;if(b.isWatchable_)for(var l=c.length;l--;){var e=c[l],m=e[0];if(f>m.bindLevel)break;if(!g&&k){if(!(g=b.isWatchable_&&b.isWatchable_(a)))break;k[b.uuid]=!0}a:{var n=a;for(var p=b,r=k,q=m;q;q=q.parent)if(p==
q){n=!r||m.isWatchable_(n,p,r);break a}n=!1}n&&(h&&c.splice(l,1),d.unshift(e))}return d}function p(a,c){c=c.$clone();if(u[a])for(var b=c.length;b--;){var h=c[b][0];h.isWatchable_&&h.isWatchable_(a)||c.splice(b,1)}return c}function r(a){return jq.isArray(a)?a[0]:a}function q(){if(t){t=!1;for(var a in n){var c=n[a];c.length&&null!=c[0][0].bindLevel&&c.sort(z)}}}function v(a){return null==(a=a.bindLevel)||isNaN(a)?-1:a}function z(a,c){return v(a[0])-v(c[0])}function w(a,c){if(a)for(var b=a.length,h=
b-1,d,f,k;0<=b;){if(0>--b||d!=(k=a[b][1].parent)&&d){for(d=b;++d<=h;)f=a[d],f[0].apply(f[1],c);h=b}d=k}}function x(a,c,b,h){var d=n[a];if(d&&d.length){var f=b&&b.down&&null!=c.bindLevel;f&&q();var k=[],g=b&&b.reverse?[]:null,e=new y(a,f?m(a,d,c):p(a,d),k,c,g);k.push(e);d=2;for(f=h.length;d<f;)k.push(h[d++]);b&&0<=b.timeout?setTimeout(function(){e.fire();w(g,k);zk._zsyncFns(a,c)},b.timeout):(e.fire(),w(g,k),zk._zsyncFns(a,c))}else zk._zsyncFns(a,c)}var u={onFitSize:!0,onSize:!0,onShow:!0,onHide:!0,
beforeSize:!0,afterSize:!0},n={},t,y=zk.$extends(zk.Object,{$init:function(a,c,b,h,d){this.name=a;this.xinfs=c;this.args=b;this.origin=h;this.fns=d},fire:function(a){var c=this.name,b=this.xinfs,h=this.args,d=this.fns;if(a)for(var f=0,k=b.length;f<k;++f){if(b[f][0]==a){var g=b[f][1];b.splice(f--,1);--k;e(c,g,a,h,d)}}else for(;a=b.shift();)e(c,a[1],a[0],h,d)},fireDown:function(a){a&&null!=a.bindLevel||this.fire(a);(new y(this.name,m(this.name,this.xinfs,a,!0),this.args,this.origin,this.fns)).fire()}});
zk._zsyncFns=function(a,c){if("onSize"==a||"onShow"==a||"onHide"==a)jq.zsync(c),"onSize"==a&&setTimeout(zk.doAfterResize,20);"onResponse"==a&&jq.doSyncScroll()};return{listen:function(a){for(var c in a){var b=n[c],h=a[c],d=r(h),f=[d,[h]];if(b){var e=d.bindLevel;if(null!=e)for(var g=b.length;;){if(0>--g){b.unshift(f);break}if(b[g][0]==d){d=b[g][1];f=h;if(d)if(jq.isArray(f)){e=!1;for(var l=d.length;0<l;l--)if(jq.isArray(d[l])&&d[l].$equals(f)){e=!0;break}d=e}else d=d.$contains(f);else d=!1;d||b[g][1].push(h);
break}if(e>=b[g][0].bindLevel){b.splice(g+1,0,f);break}}else for(g=b.length;;){if(0>--g){b.push(f);break}if(b[g][0]==d){b[g][1].push(h);break}}}else n[c]=[f]}},unlisten:function(a){for(var c in a){var b=n[c];if(b)for(var e=a[c],d=r(e),f=b.length;f--;)if(b[f][0]==d&&b[f][1].$remove(e)){b[f][1].length||b.splice(f,1);break}}},unlistenAll:function(a){delete n[a]},fire:function(a,c,b){x(a,c,b,arguments)},fireDown:function(a,c,b){x(a,c,zk.copy(b,{down:!0}),arguments)},onBindLevelMove:function(){t=!0}}}();
zWatch.listen({onBindLevelMove:zWatch});
