(function(){twentyc={cls:{make_name:function(a){var b=a.split(/[-\s]/);for(a=0;a<b.length;a++)0<a&&(b[a]=b[a].charAt(0).toUpperCase()+b[a].slice(1));return b.join("")},define:function(a,b){var c;a=twentyc.cls.make_name(a);if("function"==typeof b[a]){var d=b[a];delete b[a]}else d=function(){};for(c in b)d.prototype[c]=b[c];d.prototype._meta={name:a};return d},extend:function(a,b,c){var d;a=twentyc.cls.make_name(a);if("function"==typeof b[a]){var e=b[a];delete b[a]}else e=function(){c.apply(this,arguments)};
for(d in c.prototype)e.prototype[d]=c.prototype[d];for(d in b)"function"==typeof e.prototype[d]&&(e.prototype[c.prototype._meta.name+"_"+d]=c.prototype[d]),e.prototype[d]=b[d];e.prototype[c.prototype._meta.name]=c;e.prototype._meta={name:a,parent:c};return e},override:function(a,b,c){a.prototype[b]&&(a.prototype[a.prototype._meta.name+"_"+b]=a.prototype[b]);a.prototype[b]=c}}};twentyc.cls.Registry=twentyc.cls.define("Registry",{Registry:function(){this._classes={}},register:function(a,b,c){if(void 0!=
this._classes[a])throw"Class with name '"+a+"' already exists - name must be unique in the Registry";if(c&&"function"!=typeof this._classes[c])throw"Trying to extend from class unknown to this Registry: "+c;this._classes[a]=c?twentyc.cls.extend(a,b,this._classes[c]):twentyc.cls.define(a,b);return this._classes[a]},get:function(a){if("function"!=typeof this._classes[a])throw"Trying to retrieve class unknown to this Registry: "+a;return this._classes[a]},has:function(a){return"function"==typeof this._classes[a]}});
twentyc.util={get:function(a,b,c){return a&&void 0!=a[b]?a[b]:c},require_namespace:function(a){a=a.split(".");var b,c=window;for(b=0;b<a.length;b++){var d=a[b];"undefined"==typeof c[d]&&(c[d]={});c=c[d]}return c}};twentyc.data={_loading:{},_data:{},get:function(a){return tc.u.get(this._data,a,{})},has:function(a){return"object"==typeof this._data[a]},set:function(a,b){this._data[a]=b},update:function(a,b){var c=this.get(a);$.extend(c,b);this.set(a,c)},load:function(a,b){var c=tc.u.get(b,"callback");
if(this._data[a]&&!tc.u.get(b,"reload"))b={id:a,data:this._data[a]},$(this).trigger("load-"+a,b),c&&c(b);else{if(c)$(this).on("load-"+a,function(d,e){c(e)});this._loading[a]||(b=this.loaders.loader(a,b),this._loading[a]=(new Date).getTime(),b.load({success:function(d){twentyc.data.set(a,d);twentyc.data._loading[a]=!1;$(twentyc.data).trigger("load-"+a,{id:a,data:d});$(twentyc.data).off("load-"+a);twentyc.data.loading_done()}}))}},loading_done:function(a){var b;a&&($(this).on("done",a),$(this).on("done",
function(){$(twentyc.data).off("done",a)}));for(b in this._loading)if(twentyc.data._loading[b])return;$(this).trigger("done",{})}};twentyc.data.LoaderRegistry=twentyc.cls.extend("LoaderRegistry",{LoaderRegistry:function(){this.Registry();this._loaders={}},assigned:function(a){return"undefined"!=typeof this._loaders[a]},assign:function(a,b){this.get(b);this._loaders[a]=b},loader:function(a,b){if(!this._loaders[a])throw"Could not find suitable loader for data id "+a+", are you certain it's assigned?";
return new (this.get(this._loaders[a]))(a,b||{})}},twentyc.cls.Registry);twentyc.data.loaders=new twentyc.data.LoaderRegistry;twentyc.data.loaders.register("Base",{Base:function(a,b){this.dataId=a;this.config=b||{}},retrieve:function(a){return tc.u.get(a,this.dataId)},load:function(){throw"The load() function needs to be overwritten to do something";}});twentyc.data.loaders.register("XHRGet",{load:function(a){var b=tc.u.get(this.config,"url"),c=this;if(void 0==b)throw"XHRGet loader needs url, "+this._meta.name;
$.ajax({url:b,data:this.config.data,success:function(d){"function"==typeof a.success&&a.success(c.retrieve(d))}}).fail(function(d){a.error&&a.error(d)})}},"Base");twentyc.libraries={queue:[],index:{},require:function(a,b){a||this.index[b]||(a=new twentyc.libraries.Importer(b),this.index[b]=a,this.queue.push(a),this.load_next());return this},load_next:function(){this.queue.length&&this.queue[0].load(function(){this.queue.shift();this.load_next()}.bind(this))}};twentyc.libraries.Importer=twentyc.cls.define("Importer",
{Importer:function(a){this.url=a;this.status="waiting"},load:function(a,b){if("waiting"==this.status){b||(b=document.head);var c=document.createElement("script");c.onload=function(){this.status="loaded";a&&a()}.bind(this);c.type="text/javascript";c.src=this.url;this.status="loading";b.appendChild(c);return c}}});twentyc.util.SmartTimeout=twentyc.cls.define("SmartTimeout",{SmartTimeout:function(a,b){this.set(a,b)},set:function(a,b){this.cancel();this._timeout=setTimeout(a,b)},cancel:function(){this._timeout&&
(clearTimeout(this._timeout),this._timeout=null)}});twentyc.jq={plugin:function(a,b,c){if(!b.init)throw"Plugin definition for jQuery."+a+" missing init method";jQuery.fn[a]=function(d){if(b[d])return b[d].apply(this,Array.prototype.slice.call(arguments,1));if("object"!==typeof d&&d)throw"Method "+d+" does not exist on jQuery."+a;var e=jQuery.extend(c||{},d);return b.init.call(this,e)}}};tc={u:twentyc.util,def:twentyc.cls.define,ext:twentyc.cls.extend}})();