if(typeof MVC=="undefined"){MVC={}}MVC.Models={};MVC.Views={};MVC.Controllers={};(function(){MVC.mix=function(){var B=arguments;var A=B.length;var F;if(A==1){B=[this,B[0]];A++}var E=B[0];var G;for(var C=A-1;C>0;C--){F=B[C];for(var D in F){G=F[D];if(G!=undefined&&G!=null&&G!=E){if(typeof (G)=="object"&&E[D]){MVC.mix(E[D],G)}else{E[D]=G}}}}return E};MVC.mix(Function.prototype,{isProperty:function(){this.isProp=true;var A=[].slice.call(arguments,0);this.observerNames=this.observerNames!=undefined?this.observerNames.concat(A):A;return this},observes:function(){var A=[].slice.call(arguments,0);this.observerNames=this.observerNames!=undefined?this.observerNames.concat(A):A;return this},scope:function(A){var B=this;return function(){B.apply(A,arguments)}}});MVC.prop=function(A,B){return new MVC.Property(A,B)};MVC.Object=function(A){return new MVC.ObjectBase(A)};MVC.Class=function(A){A.construct=A.construct||function(){};var E=function(){this.__props__=this.__props__||{};this.construct.apply(this,arguments);this.initFnObservers()};if(arguments.callee===MVC.Class){E.prototype=new MVC.ObjectBase(A);delete E.prototype.__props__}else{var C=new this;var B;for(var D in A){C[D]=A[D]}E.prototype=C}E.constructor=E;return E};MVC.ObjectBase=function(A){var C;this.__props__={};for(var B in A){this[B]=A[B]}this.initFnObservers()};MVC.ObjectBase.prototype={get:function(A){return this._fromPath(A)},set:function(A,B){this._fromPath(A,B);return this},has:function(A){return this.__props__[A]!=undefined},observe:function(A,C,B){this.prop(A).observe(C,B);return this},bind:function(E,D,F){for(var C=0,B,A=arguments.length;C<A;C++){B=arguments[i];for(var G=0;G<A;G++){if(G!=C){this.bindTo(B,arguments[G])}}}return this},bindTo:function(D,F,E){var A=(D instanceof MVC.Property)?D:this.prop(D);for(var C=1,B;C<arguments.length;C++){B=arguments[C];B=(B instanceof MVC.Property)?B:this.prop(B);A.observe(B.set,B)}return this},prop:function(A){var B=this.__props__;B=B[A]||this._setProp(A,this[A]);return B},initFnObservers:function(){for(var A in this){this.initFnObserver(A,this[A])}},initFnObserver:function(A,B){if(typeof B=="function"&&B.observerNames){this.prop(A)}},_setProp:function(B,E){var D=this;var G=MVC.prop(B,E);if(typeof E=="function"&&(E.isProp||E.observerNames)){var F=E.observerNames||[];if(E.isProp){G.scope=this;G.fn=E;for(var C=0,A=F.length;C<A;C++){this.bindTo(F[C],G)}}else{for(var C=0,A=F.length;C<A;C++){this.prop(F[C]).observe(E,this)}}}else{if(typeof E=="function"){throw"You are trying to use a function named "+B+" that is unsupported for getters and setters.  Try setting the isProperty() method on the function definition";return }}this.__props__[B]=G;delete this[B];return G},_fromPath:function(C,E){var G=C.split(".");var F=this.prop(C);for(var D=1,B,A=G.length;D<A;D++){B=G[D];if(F.has&&F.has(B)){F=F.prop(B)}else{if(E==undefined){return F[C]}else{F[C]=E}}}if(E==undefined){return F.get(C)}else{F.set(E)}}};MVC.Property=function(A,B){this.name=A;this.value=B;this._observers={}};MVC.Property.prototype={get:function(){return this.fn.call(this.scope||this)},set:function(A){this.fn.call(this.scope||this,A,this.name);this._notify(this.get())},observe:function(B,A){this._observers[B.toString()]={fn:B,scope:A||{}};return this},unObserve:function(A){delete this._observers[A.toString()];return this},fn:function(A){if(A!==undefined){this.value=A}else{return this.value}},_notify:function(B){var C=this._observers;var A;for(var D in this._observers){A=C[D];A.fn.call(A.scope,B,this.name)}}};MVC.Controller=MVC.Class({construct:function(B,A){MVC.mix(this,A,{name:B,initialized:false,_observers:{},views:null,models:{}});MVC.Controller.addController(this)},Init:function(){if(this.actions.Init){this.views=MVC.View.getViews(this.name);return this.invokeAction("Init",{args:arguments});this.initialized=true}},invokeAction:function(C,E){var A=new MVC.ActionContext(this,E);if(!this.actions[C]){throw"The action name "+C+" does not exist"}var B=this.actions[C].apply(A,A.args);var D=this._observers[C];if(D!=undefined&&D.length>0){this._invokeobservers(A,D)}return B},routeAction:function(C,B){var A=this;B=B||{};return function(){return A.invokeAction(C,{originScope:this,args:arguments,data:B})}},getView:function(A){return this.views[A]},renderView:function(B,A){return this.getView(B).render(A.template,A.targets,A.data)},observeAction:function(B,A){this._observers[B]=this._observers[B]||[];this._observers[B].push(A)},_invokeobservers:function(D,E,B){B=B||[];for(var C=0,A=E.length;C<A;C++){E[C].apply(D,B)}}});MVC.mix(MVC.Controller,{controllers:{},create:function(A,B){return new MVC.Controller(A,B)},setup:function(A,B){if(A instanceof MVC.Controller){A=[A]}for(var C in A){ctrl=A[C];ctrl.Init(B[ctrl.name])}},addController:function(A){MVC.Controller.controllers[A.name]=A},getController:function(A){return MVC.Controller.controllers[A]},observeAction:function(C,B,A){MVC.Controller.getController(C).observeAction(B,A)}});MVC.ActionContext=MVC.Class({construct:function(B,A){this.controller=B;this.originScope=A.originScope;this.data=A.data||{};this.args=A.args||[]},get:function(A){if(A=="originScope"||A=="data"||A=="args"){return this[A]}return this.controller.get(A)},set:function(A,B){this.controller.set(A,B);return this},getView:function(A){return this.controller.getView(A)},renderView:function(B,A){return this.controller.renderView(B,A)},renderData:function(A,B){return this.views.renderData(A,B)},continueToAction:function(B,A){return this.controller.invokeAction(B,{originScope:this.originScope,args:A||this.args||[]})}});MVC.View=MVC.Class({construct:function(B,A){A.controllerName=A.controllerName||B;MVC.mix(this,A.helpers,{controllerName:A.controllerName,_init:A.init,template:A.template,name:B,initialized:false});MVC.View.addView(this)},Init:function(){this._init.apply(this,arguments);this.initialized=true},getController:function(){return MVC.Controller.getController(this.controllerName)},routeEvent:function(C,B){var A=this.getController();B=B||{};return function(){return A.invokeAction(C,{originScope:this,args:arguments,data:B})}},render:function(D,B,E){B=B.length!=undefined?B:[B];for(var C=0,A=B.length;C<A;C++){B[C].innerHTML=this.renderData(D,E)}},renderData:function(A,B){Sys.$.forEach(B,function(C,E){var D=new RegExp("{"+C+"}","g");A=A.replace(D,E)});return A}});MVC.mix(MVC.View,{views:{},create:function(A,C,B){return new MVC.View(A,C,B)},addView:function(A){MVC.View.views[A.controllerName]=MVC.View.views[A.controllerName]||{};MVC.View.views[A.controllerName][A.name]=A},getView:function(A,B){return MVC.View.views[A][B]},getViews:function(A){return MVC.View.views[A]}})})();(function(){require=function(K,L){var G=[];var M;if(typeof K!="string"){for(var J=0,F=K.length,I;J<F;J++){M=typeof L!="undefined"&&J+1==F?L:undefined;I=require(K[J],M);if(I.length>0){G=G.concat(I)}}}else{var H=include_once(K,L);if(H!=null){G.push(H)}}return G};include=function(K,H){var G=include.cache;var J="inc_script"+new Date().getTime()+1;var F=document.createElement("script");F.type="text/javascript";F.id=J;F.src=K;if(G[K]!=undefined){head.removeChild(document.getElementById(G[K]))}G[K]=J;include.head.appendChild(F);if(typeof H!="undefined"){include.queue.push(H);if(document.compatMode&&document.all){F.onreadystatechange=function(){if(/loaded|complete/.test(this.readyState)){setTimeout(include.load,0)}}}else{var I=document.createElement("script");I.type="text/javascript";I.appendChild(document.createTextNode("include.load()"));include.head.appendChild(I)}}return F};include_once=function(H,G){var F=include.scripts;if(F[H]!=undefined){return null}F[H]=H;return include(H,G)};include.head=document.getElementsByTagName("head")[0];include.scripts={};include.queue=[];include.cache={};include.load=function(){var F=include.queue;if(F.length==0){return }var G=F.shift();if(typeof G=="function"){G()}};if(typeof MVC.config!="undefined"&&typeof MVC.config.apps!="undefined"){var D=MVC.config.apps;var C=MVC.config.baseUrl||"/";C+="mvc/apps/";for(var B=0,A=D.length,E;B<A;B++){E=D[B];include_once(C+E+"/"+E+".js")}}})();