/* Namespace.js */

window.Namespace="Global";var BB={Namespace:"BB",Interfaces:{Namespace:"Interfaces",Geom:{Namespace:"Geom"}},App:{Namespace:"App"},Core:{Namespace:"Core"},Forms:{Namespace:"Forms"},Geom:{Namespace:"Geom"},Helpers:{Namespace:"Helpers",App:{Namespace:"App"},Core:{Namespace:"Core"},Geom:{Namespace:"Geom"},UI:{Namespace:"UI"},Util:{Namespace:"Util"},Const:{Namespace:"Const"}},UI:{Namespace:"UI"},Util:{Namespace:"Util"},Const:{Namespace:"Const",appPath:"http://assets.bodybuilding.com/javascript/applications/",CSS_VER:"",DEPOT_PATH:"http://assets.bodybuilding.com/javascript/depots/",WIDGET_PATH:"http://assets.bodybuilding.com/javascript/"},Instances:{Namespace:"Instances"},Controller:{Namespace:"Controllers"},Log:{Namespace:"Log"}};

BB.Core.AddEvent=function(c,b,a){if(c.addEventListener){c.addEventListener(b,a,false);BB.Core.AddEvent.EventCache.add(c,b,a);}else{if(c.attachEvent){c["e"+b+a]=a;c[b+a]=function(d){c["e"+b+a](window.event||d);};c.attachEvent("on"+b,c[b+a]);BB.Core.AddEvent.EventCache.add(c,b,a);}else{c["on"+b]=c["e"+b+a];}}};BB.Core.AddEvent.EventCache={listEvents:[],add:function(a,c,b){BB.Core.AddEvent.EventCache.listEvents.push(arguments);},flush:function(){var a,b;for(a=BB.Core.AddEvent.EventCache.listEvents.length-1;a>=0;a-=1){b=BB.Core.AddEvent.EventCache.listEvents[a];if(b[0].removeEventListener){b[0].removeEventListener(b[1],b[2],b[3]);}if(b[1].substring(0,2)!=="on"){b[1]="on"+b[1];}if(b[0].detachEvent){b[0].detachEvent(b[1],b[2]);}b[0][b[1]]=null;}}};Function.prototype.attach=function(b,a){BB.Core.AddEvent(b,a,this);};
var Interface=function(c,b){if(arguments.length!==2){throw new Error("Interface constructor called with "+arguments.length+"arguments, but expected exactly 2.");}this.name=c;this.methods=[];for(var d=0,a=b.length;d<a;d+=1){if(typeof b[d]!=="string"){throw new Error("Interface constructor expects method names to be passed in as a string.");}this.methods.push(b[d]);}};Interface.ensureImplements=function(c){if(arguments.length<2){throw new Error("Function Interface.ensureImplements called with "+arguments.length+"arguments, but expected at least 2.");}for(var d=1,a=arguments.length;d<a;d+=1){var f=arguments[d];if(f.constructor!==Interface){throw new Error("Function Interface.ensureImplements expects arguments two and above to be instances of Interface.");}for(var b=0,e=f.methods.length;b<e;b+=1){var g=f.methods[b];if(!c[g]||typeof c[g]!=="function"){throw new Error("Function Interface.ensureImplements: object does not implement the "+f.name+" interface. Method "+g+" was not found.");}}}return true;};
var memcache={datastore:{},get:function(a){return this.datastore[a];},set:function(b,d,c){var a=this.datastore;if(typeof c==="undefined"){c=120000;}a[b]=d;if(c){setTimeout(function(){delete a[b];},c);}},remove:function(a){delete this.datastore[a];},clear:function(){this.datastore={};}};

Function.prototype.extend=function(){var a=function(){};a.prototype=arguments[0].prototype;this.prototype=new a();this.prototype.constructor=this;};
var Publisher=function(){this.subscribers=[];};Publisher.prototype.add=function(c){if(typeof c==="function"){for(var b=0,a=this.subscribers.length;b<a;b+=1){if(this.subscribers[b]===c){return;}}this.subscribers.push(c);}};Publisher.prototype.remove=function(c){if(typeof c==="function"){for(var b=0,a=this.subscribers.length;b<a;b+=1){if(this.subscribers[b]===c){this.subscribers.splice(b,1);}}}};Publisher.prototype.deliver=function(c){for(var b=0,a=this.subscribers.length;b<a;b+=1){this.subscribers[b](c);}return this;};Function.prototype.subscribe=function(a){a.add(this);return this;};Function.prototype.unsubscribe=function(a){a.remove(this);return this;};
BB.Geom.Point=function(a,b){if(typeof a==="number"&&typeof a==="number"){this.x=a;this.y=b;}else{if(typeof a==="object"&&typeof a.x==="number"&&typeof a.y==="number"){this.x=a.x;this.y=a.y;}else{throw new Error("BB.Geom.Point expected a coordinate pair");}}return true;};BB.Geom.Point.prototype={setX:function(a){this.x=a;return true;},setY:function(a){this.y=a;return true;},getX:function(){return this.x;},getY:function(){return this.y;},setLocation:function(a,b){if(typeof a==="number"&&typeof a==="number"){this.x=a;this.y=b;}else{if(typeof a==="object"&&typeof a.x==="number"&&typeof a.y==="number"){this.x=a.x;this.y=a.y;}}return true;},getLocation:function(){return{x:this.x,y:this.y};}};BB.Interfaces.Geom.Point=new Interface("BB.Geom.Point",["setX","setY","getX","getY","setLocation","getLocation"]);
BB.Geom.Rectangle=function(b,c,a,d){if(isNaN(b)||isNaN(c)||isNaN(a)||isNaN(d)||typeof b!=="number"||typeof c!=="number"||typeof a!=="number"||typeof d!=="number"){return false;}else{this.height=b;this.width=c;BB.Geom.Point.call(this,a,d);}};BB.Geom.Rectangle.extend(BB.Geom.Point);BB.Geom.Rectangle.prototype.getHeight=function(){return this.height;};BB.Geom.Rectangle.prototype.getWidth=function(){return this.width;};BB.Geom.Rectangle.prototype.getSize=function(){return{height:this.height,width:this.width};};BB.Geom.Rectangle.prototype.setHeight=function(a){if(!isNaN(a)&&typeof a==="number"&&a>=0&&a!==Infinity){this.height=a;return true;}else{return false;}};BB.Geom.Rectangle.prototype.setWidth=function(a){if(!isNaN(a)&&typeof a==="number"&&a>=0&&a!==Infinity){this.width=a;return true;}else{return false;}};BB.Geom.Rectangle.prototype.setSize=function(a,b){if(!isNaN(b)&&typeof b==="number"&&b>=0&&b!==Infinity&&!isNaN(a)&&typeof a==="number"&&a>=0&&a!==Infinity){this.width=b;this.height=a;return true;}else{return false;}};BB.Geom.Rectangle.prototype.getCenter=function(){return{x:this.x+(this.width/2),y:this.y+(this.height/2)};};BB.Geom.Rectangle.prototype.getBounds=function(){return{height:this.height,width:this.width,x:this.x,y:this.y};};BB.Geom.Rectangle.prototype.setBounds=function(b,c,a,d){if(isNaN(b)||isNaN(c)||isNaN(a)||isNaN(d)||typeof b!=="number"||typeof c!=="number"||typeof a!=="number"||typeof d!=="number"){return false;}else{this.height=b;this.width=c;this.x=a;this.y=d;return true;}};BB.Geom.Rectangle.prototype.translate=function(a,b){if(!isNaN(a)&&typeof a==="number"&&!isNaN(b)&&typeof b==="number"){this.x=this.x+a;this.y=this.y+b;return true;}else{return false;}};BB.Geom.Rectangle.prototype.contains=function(a,b){if(a instanceof BB.Geom.Rectangle){if(a.getX()<=this.x||a.getY()<=this.y||a.getY()>=this.y+this.height||a.getX()>=this.x+this.width(a.getX()+a.getWidth())<=this.x||(a.getY()+a.getHeight())<=this.y||(a.getY()+a.getHeight())>=this.y+this.height||(a.getX()+a.getWidth())>=this.x+this.width){return false;}else{return true;}}else{if(a.x&&a.y){b=a.y;a=a.x;}}if(a<=this.x||b<=this.y||b>=this.y+this.height||a>=this.x+this.width){return false;}else{return true;}};BB.Geom.Rectangle.prototype.containsX=function(a){if(a<this.x||a>this.x+this.width){return false;}else{return true;}};BB.Geom.Rectangle.prototype.containsY=function(a){if(a<this.y||a>this.y+this.height){return false;}else{return true;}};BB.Geom.Rectangle.prototype.toString=function(){return"var jrect = {height: "+this.height+", width: "+this.width+", x: "+this.x+", y: "+this.y+"}";};
BB.Helpers.clickLocation=function(c,a){var b={x:0,y:0};c=c||window.event;if(c.pageX&&c.pageY){b.x=c.pageX-=a.offsetLeft;b.y=c.pageY-=a.offsetTop;while(a){b.x-=a.offsetLeft;b.y-=a.offsetTop;a=a.offsetParent;}}else{b.x=c.clientX+(a.scrollLeft||a.scrollLeft)-(a.clientLeft||0);b.y=c.clientY+(a.scrollTop||a.scrollTop)-(a.clientTop||0);}return b;};
BB.Helpers.Geom.coordinateRotation=function(b,c,g){Interface.ensureImplements(b,BB.Interfaces.Geom.Point);var a,d,f,e;a=b.getX();f=b.getY();if(typeof g==="object"){Interface.ensureImplements(g,BB.Interfaces.Geom.Point);a-=g.getX();f-=g.getY();}if(c>=0){d=(a*Math.cos(c))-(f*Math.sin(c));e=(a*Math.sin(c))+(f*Math.cos(c));}else{d=(a*Math.cos(c))+(f*Math.sin(c));e=(a*Math.sin(c))+(f*Math.cos(c));}if(typeof g==="object"){d+=g.getX();e+=g.getY();}return new BB.Geom.Point(d,e);};
if(!this.JSON){this.JSON={};}(function(){function f(n){return n<10?"0"+n:n;}if(typeof Date.prototype.toJSON!=="function"){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+"-"+f(this.getUTCMonth()+1)+"-"+f(this.getUTCDate())+"T"+f(this.getUTCHours())+":"+f(this.getUTCMinutes())+":"+f(this.getUTCSeconds())+"Z":null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={"\b":"\\b","\t":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==="string"?c:"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==="object"&&typeof value.toJSON==="function"){value=value.toJSON(key);}if(typeof rep==="function"){value=rep.call(holder,key,value);}switch(typeof value){case"string":return quote(value);case"number":return isFinite(value)?String(value):"null";case"boolean":case"null":return String(value);case"object":if(!value){return"null";}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==="[object Array]"){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||"null";}v=partial.length===0?"[]":gap?"[\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"]":"["+partial.join(",")+"]";gap=mind;return v;}if(rep&&typeof rep==="object"){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==="string"){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v);}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?": ":":")+v);}}}}v=partial.length===0?"{}":gap?"{\n"+gap+partial.join(",\n"+gap)+"\n"+mind+"}":"{"+partial.join(",")+"}";gap=mind;return v;}}if(typeof JSON.stringify!=="function"){JSON.stringify=function(value,replacer,space){var i;gap="";indent="";if(typeof space==="number"){for(i=0;i<space;i+=1){indent+=" ";}}else{if(typeof space==="string"){indent=space;}}rep=replacer;if(replacer&&typeof replacer!=="function"&&(typeof replacer!=="object"||typeof replacer.length!=="number")){throw new Error("JSON.stringify");}return str("",{"":value});};}if(typeof JSON.parse!=="function"){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==="object"){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}}return reviver.call(holder,key,value);}text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return"\\u"+("0000"+a.charCodeAt(0).toString(16)).slice(-4);});}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@").replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]").replace(/(?:^|:|,)(?:\s*\[)+/g,""))){j=eval("("+text+")");return typeof reviver==="function"?walk({"":j},""):j;}throw new SyntaxError("JSON.parse");};}}());
var localize=function(a){if(BB.Const.localizedStrings[a]){return BB.Const.localizedStrings[a];}else{return a;}};if(typeof BB.Const.Lang==="undefined"){BB.Const.Lang="en";}(function(){if(BB.Const.Lang!=="en"){var a=document.createElement("script");a.type="text/javascript";a.src="http://assets.bodybuilding.com/javascript/localizedStrings/"+BB.Const.Lang+"_localizedStrings.js";document.getElementsByTagName("head")[0].appendChild(a);}else{BB.Const.localizedStrings={};}}());

(function(b){for(var a in b){if(b.hasOwnProperty(a)){Function.prototype[a]=b[a];}}}(function(){var d=Array.prototype.slice;function g(k,h){var j=k.length,i=h.length;while(i){i-=1;k[j+i]=h[i];}return k;}function f(i,h){i=d.call(i,0);return g(i,h);}function c(){var h=this.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1].replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g,"").replace(/\s+/g,"").split(",");return h.length===1&&!h[0]?[]:h;}function e(j){var h=this,i=d.call(arguments,1);return function(){var k=f(i,arguments);return h.apply(j,k);};}function a(){if(!arguments.length){return this;}var h=this,i=d.call(arguments,0);return function(){var j=f(i,arguments);return h.apply(this,j);};}function b(i){var h=this;return function(){var j=g([h.bind(this)],arguments);return i.apply(this,j);};}return{argumentNames:c,bind:e,curry:a,wrap:b};}()));Function.prototype.bindAsEventListener=function(b){var a=this;return function(c){a.bind(b)(this,c);};};
Math.d2r=function(a){return a*0.017453292519943295;};Math.r2d=function(a){return a*57.29577951308232;};
BB.Controller.MessageController=function(a){this.messageQueue={};if(a){this.messageControllerName=a.name||"Unamed message controller";this.parentMessageController=a.parentMessageController||false;}};BB.Controller.MessageController.prototype.registerListener=function(b,a,c){if(this.messageQueue[b]){this.messageQueue[b][a]=c;}else{this.messageQueue[b]={};this.messageQueue[b][a]=c;}BB.Log.debug(this.messageControllerName+": "+a+" has been registered under "+b);};BB.Controller.MessageController.prototype.sendMessage=function(c,d,b){var g,a;try{g=this.messageQueue[c];a="";}catch(f){BB.Log.error(f);return false;}for(a in g){if(g.hasOwnProperty(a)){try{g[a](d);}catch(f){BB.Log.error(this.messageControllerName+": There was an error sending a message to a member of "+c+" with the UID of "+a);BB.Log.error(f);}}}BB.Log.debug(this.messageControllerName+": "+d+" has been sent to all registered listeners attached to "+c);if(this.parentMessageController&&!b){try{BB.Log.debug(this.messageControllerName+": "+d+" has been forwarded to the parent message controller.");this.parentMessageController.sendMessage(c,d);}catch(f){BB.Log.error(this.messageControllerName+": The parent message controller was called but returned an error.");BB.Log.error(this.messageControllerName+": "+f);}}};BB.Controller.MessageController.prototype.unregisterListener=function(b,a){try{delete this.messageQueue[b][a];}catch(c){BB.Log.warn(c);}BB.Log.debug(this.messageControllerName+": "+a+" has been unregistered from "+b);};BB.Controller.Messenger=new BB.Controller.MessageController({name:"Global Message Controller"});
BB.Controller.AppController=function(){this.stageNames=[];this.stageInstances={};this.messenger=new BB.Controller.MessageController({name:"AppController Message Controller",parentMessageController:BB.Controller.Messenger});};BB.Controller.AppController.prototype.launchApplication=function(appId,name,params){this.stageNames.push(name);this.stageInstances[name]={appId:appId,appUID:Math.floor(Math.random()*new Date()),packageName:appId.split(".")[appId.split(".").length-1],packagePath:function(){var paths=appId.replace("BB.App.","").split("."),outp="";for(var i=0,len=paths.length;i<len;i+=1){outp+=paths[i]+"/";}return outp;}.bind(this)(),scenes:{},templates:{}};var scenesToLoad=0,checkScripts={};var paths=appId.replace("BB.App.","").split("."),space=BB.App;for(var i=0,len=paths.length;i<len;i+=1){space[paths[i]]={};space=space[paths[i]];}delete paths;this.stageInstances[name].nameSpace=space;jQuery.ajax({url:BB.Const.appPath+this.stageInstances[name].packagePath+"index.html",success:function(appIndex){var container=document.getElementById(name);container.id=this.stageInstances[name].appUID;container.innerHTML=appIndex.replace("APP_CONTAINER_ID",name);jQuery.ajax({url:BB.Const.appPath+this.stageInstances[name].packagePath+"sources.json",success:function(sources){var sourceFiles,storeTemplate=function(i,result){this.stageInstances[name].templates[sourceFiles[i].template]=result;this.messenger.sendMessage(appId+name,"done");},storeScene=function(i,result){this.stageInstances[name].scenes[sourceFiles[i].scenes]=result;this.messenger.sendMessage(appId+name,"done");};try{eval("sourceFiles = "+sources);sourceFiles.push({source:"assistants/AppAssistant.js"});}catch(e){BB.Log.error("The application sources.json file is syntactically incorrect.");}this.messenger.registerListener(appId+name,"defer-stage-controller",function(){scenesToLoad-=1;if(scenesToLoad===0){this.stageInstances[name].instance=new BB.Controller.StageController(this,appId,name,params);}}.bind(this));for(var i=0,len=sourceFiles.length;i<len;i+=1){if(sourceFiles[i].template){scenesToLoad+=1;jQuery.ajax({url:BB.Const.appPath+this.stageInstances[name].packagePath+"app/views/"+sourceFiles[i].template+"Template.html?ver="+BB.Const.CSS_VER,success:storeTemplate.bind(this).curry(i)});}else{if(sourceFiles[i].script){var script=document.createElement("script");script.src=sourceFiles[i].source+"?ver="+BB.Const.CSS_VER;script.type="text/javascript";document.getElementsByTagName("head")[0].appendChild(script);}else{var script=document.createElement("script");script.src=BB.Const.appPath+this.stageInstances[name].packagePath+"app/"+sourceFiles[i].source+"?ver="+BB.Const.CSS_VER;script.type="text/javascript";document.getElementsByTagName("head")[0].appendChild(script);if(sourceFiles[i].scenes){scenesToLoad+=1;jQuery.ajax({url:BB.Const.appPath+this.stageInstances[name].packagePath+"app/scenes/"+sourceFiles[i].scenes+"Scene.html?ver="+BB.Const.CSS_VER,success:storeScene.bind(this).curry(i)});}}}}}.bind(this)});}.bind(this)});};BB.Controller.AppController.prototype.getApplicationInstance=function(a){return this.stageInstances[a];};BB.Controller.AppController.prototype.closeApplication=function(a){this.stageInstances[a].instance.destroy();this.stageNames.pop();document.getElementById(this.stageInstances[a].appUID).innerHTML="";delete this.stageInstances[a];};BB.Controller.AppController.prototype.closeAllApplications=function(){while(this.stageNames.length){this.closeApplication(this.stageNames[this.stageNames.length-1]);}};BB.AppController=new BB.Controller.AppController();
BB.Controller.StageController=function(a,c,b,d){this.controller=a;this.appId=c;this.name=b;this.stage=document.getElementById(b);this.scenes=[];this.templateEngine=BB.TemplateCore();BB.Controller.MessageController.call(this,{name:c+"-"+b+" Message Controller",parentMessageController:this.controller.messenger});this.pushScene("App",d);};BB.Controller.StageController.extend(BB.Controller.MessageController);BB.Controller.StageController.prototype.activate=function(){try{this.scenes[this.scenes.length-1].constructor.activate();}catch(a){BB.Log.warning("No activate method was found on "+this.scenes[this.scenes.length-1].name);}};BB.Controller.StageController.prototype.setup=function(){try{this.scenes[this.scenes.length-1].constructor.setup();}catch(a){BB.Log.warning("No setup method was found on "+this.scenes[this.scenes.length-1].name);}};BB.Controller.StageController.prototype.deactivate=function(b){if(this.scenes.length===0){return;}try{this.scenes[this.scenes.length-1].constructor.deactivate();}catch(a){BB.Log.warning("No deactivate method was found on "+this.scenes[this.scenes.length-1].name);}try{this.scenes[this.scenes.length-1].html=this.stage.innerHTML;}catch(a){BB.Log.warning("Unable to cache the current scenes html. No scenes on the stack?");}try{if(b){b();}}catch(a){BB.Log.error("The callback method passed into deactivate failed to execute properly.");BB.Log.error(a);}};BB.Controller.StageController.prototype.destroy=function(){for(var a=0;a<this.scenes.length;a+=1){this.deactivate();this.scenes.pop();}delete this.messageQueue;};BB.Controller.StageController.prototype.pushScene=function(d,a){this.deactivate();var c=this.controller.getApplicationInstance(this.name).nameSpace[d.substring(0,1).toUpperCase()+d.substring(1)+"Assistant"];if(!c){this.interval=setInterval(function(g,e){if(this.controller.getApplicationInstance(this.name).nameSpace[g.substring(0,1).toUpperCase()+g.substring(1)+"Assistant"]){clearInterval(this.interval);this.pushScene(g,e);}}.bind(this).curry(d,a),30);return;}var f=(function(g,e){return function(h){this.controller=h;g.call(this,e);}.curry(this);}.bind(this))(c,a);f.extend(c);try{f=new f();}catch(b){BB.Log.error(b);}if(d==="app"){this.setup();this.activate();return;}this.scenes.push({name:d,constructor:f,html:this.controller.getApplicationInstance(this.name).scenes[d.substring(0,1).toUpperCase()+d.substring(1)]});try{this.stage.innerHTML=this.scenes[this.scenes.length-1].html;}catch(b){BB.Log.error("Stage HTML not found.");}this.setup();this.activate();};BB.Controller.StageController.prototype.popScene=function(){this.deactivate();if(this.scenes.length>1){this.scenes.pop();this.stage.innerHTML=this.scenes[this.scenes.length-1].html;this.activate();}else{this.stage.innerHTML=this.scenes[this.scenes.length-1].html;this.activate();}};BB.Controller.StageController.prototype.popSceneTo=function(b,a){this.deactivate();while(this.scenes[this.scenes.length-1].name!==b){this.popScene();if(this.scenes.length===2){this.pushScene(b,a);break;}}this.stage.innerHTML=this.scenes[this.scenes.length-1].html;this.activate();};BB.Controller.StageController.prototype.swapScene=function(b,a){this.popScene();this.pushScene(b,a);};BB.Controller.StageController.prototype.swapTo=function(b,a){BB.Log.debug("Swaping to "+b);this.deactivate();var g=false;for(var f in this.scenes){if(this.scenes[f].name===b){var c=this.scenes.splice(f,1);this.scenes.push(c[0]);try{this.stage.innerHTML=this.scenes[this.scenes.length-1].html;}catch(d){BB.Log.error("No stage html found.");}this.activate();g=true;break;}}if(!g){BB.Log.debug("Unable to swap to "+b+" so pushing a new scene");this.pushScene(b,a);}};BB.Controller.StageController.prototype.renderTemplate=function(a,c,b,f){if(a&&a.container){f=a.callback;b=a.dataModel;c=a.template;a=a.container;}try{document.getElementById(a).innerHTML=this.templateEngine(this.controller.getApplicationInstance(this.name).templates[c],b);}catch(d){BB.Log.error("Failed to render the "+c+" template into "+a+".");BB.Log.error(d);}try{if(f){f();}}catch(d){BB.Log.error("The callback provided to the renderTemplate method failed when rendering "+c+" into "+a+".");}};
BB.Depot=function(b){try{return new BB.Depot.Module(b);}catch(a){BB.Log.error("Depot Module Creation Failed. Is BB.Depot.Module not defined?");BB.Log.error(a);}};BB.Depot.Modules={};BB.Depot.Module=function(a){this.depotModule={};this.interval={};jQuery.ajax({url:BB.Const.DEPOT_PATH+a.module+".js",success:function(c){var b=document.createElement("script");b.type="text/javascript";b.src=BB.Const.DEPOT_PATH+a.module+".js";document.getElementsByTagName("head")[0].appendChild(b);this.interval=setInterval(function(d){if(BB.Depot.Modules[d.module]){this.depotModule=new BB.Depot.Modules[d.module]();d.success();clearInterval(this.interval);}}.bind(this).curry(a),10);}.bind(this),onFailure:function(){BB.Log.error("Depot Module "+a.module+" Failed To Load.");a.failure();}});};BB.Depot.Module.prototype.getValue=function(a){if(this.validateRequestObject(a,"GET")){this.depotModule.getValue(a);}else{BB.Log.warning("Depot GET request failed request object verification.");BB.Log.debug(a);}};BB.Depot.Module.prototype.setValue=function(a){if(this.validateRequestObject(a,"SET")){this.depotModule.setValue(a);}else{BB.Log.warning("Depot SET request failed request object verification.");BB.Log.debug(a);}};BB.Depot.Module.prototype.updateValue=function(a){if(this.validateRequestObject(a,"UPDATE")){this.depotModule.updateValue(a);}else{BB.Log.warning("Depot UPDATE request failed request object verification.");BB.Log.debug(a);}};BB.Depot.Module.prototype.deleteValue=function(a){if(this.validateRequestObject(a,"DELETE")){this.depotModule.deleteValue(a);}else{BB.Log.warning("Depot DELETE request failed request object verification.");BB.Log.debug(a);}};BB.Depot.Module.prototype.deleteAllValues=function(){this.depotModule.deleteAllValues();};BB.Depot.Module.prototype.validateRequestObject=function(b,a){if(b){if(b.name&&(a==="GET"||a==="DELETE")){return true;}else{if(b.value&&(a==="SET"||a==="UPDATE")){return true;}else{return false;}}}else{return false;}};
BB.Log={level:0,message:function(a){if(BB.Log.level>0){console.log("|\n|   Log ---- "+a+"\n|");}},warning:function(a){if(BB.Log.level>49){console.warn("∑\n∑∑  Warning ---- "+a+"\n∑");}},error:function(a){if(BB.Log.level>98){console.error("/ \n{-  Error ---- "+a+"\n\\");}},debug:function(a){if(BB.Log.level>10){console.debug("\\ \n }- Debug ---- "+a+"\n/");}}};
BB.TemplateCore=function(){var b={},c;c=function a(e,f){var d=!/\W/.test(e)?b[e]=b[e]||c(e):new Function("obj","var p=[],print=function(){p.push.apply(p,arguments);};with(obj){p.push('"+e.replace(/[\r\t\n]/g," ").split("<?").join("\t").replace(/((^|\?>)[^\t]*)'/g,"$1\r").replace(/\t=(.*?)\?>/g,"',$1,'").split("\t").join("');").split("?>").join("p.push('").split("\r").join("\\'")+"');}return p.join('');");return f?d(f):d;};return c;};
BB.UI.Anchor=function(a,b){if(isNaN(a)||isNaN(b)||typeof a!=="number"||typeof b!=="number"){return false;}else{this.x=a;this.y=b;}};BB.UI.Anchor.prototype={setLocation:function(a,b){if(isNaN(a)||isNaN(b)||typeof a!=="number"||typeof b!=="number"){return false;}else{this.x=a;this.y=b;return true;}}};
BB.Core.Cursor=function(c){this.element=c;this.output=new Publisher();var a=this,b={x:0,y:0};this.move=function(f){f=f||window.event;if(f.pageX&&f.pageY){b.x=f.pageX-a.element.offsetLeft;b.y=f.pageY-a.element.offsetTop;var d=a.element;while(d){b.x-=d.offsetLeft;b.y-=d.offsetTop;d=d.offsetParent;}}else{b.x=f.clientX+(a.element.scrollLeft||a.element.scrollLeft)-(a.element.clientLeft||0);b.y=f.clientY+(a.element.scrollTop||a.element.scrollTop)-(a.element.clientTop||0);}a.output.deliver(b);};this.move.attach(c,"mousemove");};
BB.Util.Queue=function(){this.queue=[];return true;};BB.Util.Queue.prototype={push:function(a){if(typeof a==="function"){this.queue.push(a);return true;}else{return false;}},flush:function(){if(this.queue.length>0){this.queue.shift()();}return true;},pop:function(){this.queue.pop();return true;},clear:function(){this.queue=[];return true;}};
var $W=(function(d,b,c){function a(){var h=BB.TemplateCore();var y=33;try{if(typeof window.XMLHttpRequest==="undefined"){y=133;}}catch(v){}this.widgets={};var j=[],t={},u=(function(){var z={},e=function(B,A){BB.Log.debug(B+" was proxied");z[B]=z[B]||[];z[B].push(A);if(z[B].length>=50){BB.Log.warning("Widget proxy for "+B+" has exceeded 50 messages.");}if(z[B].length>=75){BB.Log.warning("Widget proxy for "+B+" has exceeded 75 messages and is being cleared.");z[B]=[];}};e.get=function(B){var A=z[B];z[B]=[];return A;};return e;}()),o,q=false,n=[],l=function(C,z){var B={};for(var e in C){if(C.hasOwnProperty(e)){if(typeof C[e]==="object"){if(C[e] instanceof Array){B[e]=[];for(var A in C[e]){if(C[e].hasOwnProperty(A)){B[e][A]=C[e][A];}}}else{B[e]=l(C[e],z);}}else{if(typeof C[e]==="function"&&z){B[e]=C[e].bind(z);}else{B[e]=C[e];}}}}return B;},s=function(B,z){try{return new this.widgets[z](B);}catch(A){if(q){throw A+" | "+z;}else{n.push(A);}}}.bind(this),w=function(A){if(A.model){for(var z in A.model){if(A.model.hasOwnProperty(z)){try{if(typeof A.model[z]==="function"){this.model[z]=A.model[z].bind(this);}else{this.model[z]=A.model[z];}}catch(B){if(q){throw B;}else{n.push(B);}}}}}if(A.controller){for(var z in A.controller){if(A.controller.hasOwnProperty(z)){try{if(typeof A.controller[z]==="function"){this.controller[z]=A.controller[z].bind(this);}else{this.controller[z]=A.controller[z];}}catch(B){if(q){throw B;}else{n.push(B);}}}}}},g=function(){if(!this.template){return;}this.model.element.innerHTML=h(this.template,this.model);},f=function(B,A,z){if(this.model.link==="undefined"){return;}try{BB.Controller.Messenger.sendMessage("widget-link-"+this.model.link,{message:A,channel:z});}catch(C){}},x=function(B,A){var z=B;try{if(typeof B==="string"){B=document.getElementById(B);}if(typeof A==="undefined"){try{return t[d(B).attr("data-widget-id")];}catch(C){if(q){throw C;}else{n.push(C);}}}try{t[d(B).attr("data-widget-id")].updateModel(A);}catch(C){u(z,A);}try{t[d(B).attr("data-widget-id")].redraw();}catch(C){if(q){throw C;}else{n.push(C);}}}catch(C){if(q){throw C;}else{n.push(C);}}try{return t[d(B).attr("data-widget-id")];}catch(C){if(q){throw new Error("Element not found");}else{n.push(C);}}}.bind(this);x.extendModule=function(A,e){A=this.widgets[A];if(e.controller&&e.controller.handleMessage){var B=function(C,D){return function(E){try{C.call(this,E.message,E.channel);}catch(F){BB.Log.debug("Unable to call handleMessage on "+D+" when sending data of type "+(typeof E));}};}(widgetModule.controller.handleMessage,e.name);}var z=function(E){A.call(this,E);if(e.constructor&&e.hasOwnProperty("constructor")){e.constructor.call(this,E);}if(e.controller){var C=l(e.controller);for(var F in C){if(F!="handleMessage"){this.controller[F]=C[F];}if(F=="handleMessage"){this.controller.handleMessage=B;}}}if(e.model){var D=l(e.model);for(var F in D){this.model[F]=D[F];}}};z.prototype=A.prototype;if(e.redraw){z.prototype.redraw=(function(C){return function(){this.buildTemplate();C.bind(this)();};})(e.redraw);}if(e.template){z.prototype.template=e.template;}this.widgets[e.name]=z;}.bind(this);x.addModule=function(B){try{if(!B.name||!B.model||!B.controller||!B.constructor){throw new Error("Failed to add new widget module. Verify that you implement the correct interface. [{NAME|string}, {CONSTRUCTOR|function}, {REDRAW|function}, {TEMPLATE|string}]");}B.redraw=B.redraw||function(){};var A=function(e,C){if(typeof e==="undefined"){return function(){};}else{return function(D){try{e.call(this,D.message,D.channel);}catch(E){BB.Log.debug("Unable to call handleMessage on "+C+" when sending data of type "+(typeof D));}};}}(B.controller.handleMessage,B.name);this.widgets[B.name]=function(E,D,e,F,G,C){return function(H){this.model=l(D,this);this.controller=l(e,this);this.controller.handleMessage=G;this.controller.sendMessage=C.bind(this);this.model.element=H;E.call(this);this.model.link=this.model.element.getAttribute("data-link");if(this.model.link){BB.Controller.Messenger.registerListener("widget-link-"+this.model.link,this.model.element.getAttribute("data-widget-id"),function(I){this.controller.handleMessage.bind(this)(I);}.bind(this));}this.buildTemplate();this.redraw();};}(B.constructor,B.model,B.controller,B.name,A,f.curry(B.name));this.widgets[B.name].prototype.redraw=(function(e){return function(){this.buildTemplate();e.bind(this)();};}(B.redraw));this.widgets[B.name].prototype.updateModel=w;this.widgets[B.name].prototype.buildTemplate=g;this.widgets[B.name].prototype.template=B.template||"";}catch(z){if(q){throw z;}else{n.push(z);n.push("Failed to add new widget module. Verify that you implement the correct interface. [{NAME|string}, {CONSTRUCTOR|function}, {REDRAW|function}, {TEMPLATE|string}]");}}return this;}.bind(this);var r=function(B){if(!this.widgets[d(B).attr("data-widget")]){return false;}o=Math.floor(new Date()*Math.random());d(B).attr("data-widget-id",o);j.push(o);t[o]=s(B,d(B).attr("data-widget"));var C;try{C=u.get(B.id);}catch(D){}try{for(var A=0,z=C.length;A<z;A+=1){t[d(B).attr("data-widget-id")].updateModel(C[A]);t[d(B).attr("data-widget-id")].redraw();}}catch(D){}return this;}.bind(this),p,k=function(){clearInterval(p);},m=function(){k();return setInterval(function(){d("*[data-widget]:not([data-widget-id])",c).each(function(){r(this);});},y);},i=function(){k();p=m();};p=m();x.debug=function(){q=true;while(n.length){BB.Log.error(n.pop());}return{stopMonitor:k,restartMonitor:i};};return x;}a=new a();return a;})(jQuery,window,document.body);

