Function.prototype.bind = function(object) {
  var fn = this;
  return (function $boundMethod() {
    return arguments.length ? fn.apply(object,arguments) : fn.call(object); // call is faster at least in Firefox.
  });
};

(function(theGlobalObject){
  // define alias "js" for the top-level package, so that name-clashes in AS3 can be resolved:
  theGlobalObject.js = theGlobalObject;
  // defined here to avoid global name space pollution and unneccessary closures:
  function clone(object) {
    var empty = function(){ };
    empty.prototype =  object;
    return new empty();
  };
  function createGetQualified(create) {
    return (function(name) {
      var object = theGlobalObject;
      if (name) {
        var parts = name.split(".");
        for (var i=0; i<parts.length; ++i) {
          var subobject = object[parts[i]];
          try {
            if(String(subobject).indexOf("[JavaPackage")==0) {
              subobject =  null;
            }
          } catch(e) {
            subobject = null;
          }
          if (!subobject) {
            if (create) {
              subobject = object[parts[i]] = {};
            } else {
              return null;
            }
          }
          object = subobject;
        }
      }
      return object;
    });
  }

  theGlobalObject.joo = {
    getOrCreatePackage: createGetQualified(true),
    getQualifiedObject: createGetQualified(false),
    classLoader: {
      prepare: function(packageDef, directives, classDef, memberFactory) {
        var classMatch = classDef.match(/^\s*((public|internal|final|dynamic)\s+)*class\s+([A-Za-z][a-zA-Z$_0-9]*)(\s+extends\s+([a-zA-Z$_0-9.]+))?(\s+implements\s+([a-zA-Z$_0-9.,\s]+))?\s*$/);
        var className = classMatch[3];
        var $extends = classMatch[5];
        var constructor;
        var publicConstructor = joo[className] = function() {
          constructor.apply(this, arguments);
        };
        var superConstructor;
        if ($extends) {
          superConstructor = joo[$extends];
          publicConstructor.prototype = clone(superConstructor.prototype);
        } else {
          superConstructor = Object;
          $extends = "Object";
        }
        publicConstructor.prototype[$extends] = superConstructor;
        var members = memberFactory(publicConstructor, {$super: $extends});
        var staticInitializer;
        for (var i = 0; i < members.length; ++i) {
          var memberDeclaration = members[i];
          switch (typeof memberDeclaration) {
            case "function": staticInitializer = memberDeclaration; break;
            case "string":
              var isStatic = memberDeclaration.match(/\bstatic\b/);
              var target = isStatic ? publicConstructor : publicConstructor.prototype;
              var member = members[++i];
              if (typeof member == "function") {
                var methodName = memberDeclaration.match(/function\s+([a-zA-Z$_0-9]+)/)[1];
                if (methodName == className) {
                  constructor = member;
                } else {
                  target[methodName] = member;
                }
              } else {
                for (var m in member) {
                  target[m] = member[m];
                }
              }
          }
        }
        if (staticInitializer) {
          staticInitializer();
        }
      },
      init: function() {
        // ignore
      }
    }
  };
})(this);// function assert(cond : Object, file : String, line : uint, column : uint) : void
joo.assert = function joo$assert(cond, file, line, column) {
  if (!cond)
    throw new Error(file+"("+line+":"+column+"): assertion failed");
};
// simulate ActionScript's Class object for type casts and "is"
joo.Class = function joo$Class(c){return c;};
joo.Class.$class = {
  isInstance: function(f){return typeof f=="function";}
};
// function trace(msg : String) : void
joo.trace = function joo$trace(msg) {
  msg = "AS3: " + msg;
  var console;
  if ((console = joo.getQualifiedObject("console")) && console.log) {
    console.log(msg);
  } else if ((console = joo.getQualifiedObject("runtime")) && console.trace) {
    console.trace(msg);
  } else if (console = joo.getQualifiedObject("trace")) {
    console(msg);
  }
};
joo.classLoader.prepare("package joo",["import joo.*",""],"public class MemberDeclaration",function(MemberDeclaration,$$private){with(joo)with(MemberDeclaration)with($$private)return["public static const",{METHOD_TYPE_GET:"get",METHOD_TYPE_SET:"set",MEMBER_TYPE_VAR:"var",MEMBER_TYPE_CONST:"const",MEMBER_TYPE_FUNCTION:"function",NAMESPACE_PRIVATE:"private",NAMESPACE_INTERNAL:"internal",NAMESPACE_PROTECTED:"protected",NAMESPACE_PUBLIC:"public",STATIC:"static",FINAL:"final",NATIVE:"native",BOUND:"bound",OVERRIDE:"override"},"private static var",{SUPPORTS_GETTERS_SETTERS: undefined},"private static var",{DEFINE_METHOD: undefined},"private static var",{LOOKUP_METHOD: undefined},function(){SUPPORTS_GETTERS_SETTERS="__defineGetter__"in Object.prototype;DEFINE_METHOD={"get":"__defineGetter__","set":"__defineSetter__"};LOOKUP_METHOD={"get":"__lookupGetter__","set":"__lookupSetter__"};},"public static function create",function(memberDeclarationStr){var tokens=memberDeclarationStr.split(/\s+/);return tokens[0]=="import"?null:new MemberDeclaration(tokens);},"internal var",{_namespace:"internal",_static:false,_final:false,_native:false,_bound:false,_override:false,memberType: undefined,getterOrSetter: undefined,memberName: undefined,slot: undefined,value: undefined,_cloneFactory: undefined},"public function MemberDeclaration",function(tokens){this[$super]();for(var j=0;j<tokens.length;++j){var token=tokens[j];if(!this.memberType){switch(token){case STATIC:case FINAL:case NATIVE:case BOUND:case OVERRIDE:this["_"+token]=true;break;case MEMBER_TYPE_VAR:case MEMBER_TYPE_CONST:case MEMBER_TYPE_FUNCTION:this.memberType=token;break;default:this._namespace=token;}}else{if(this.isMethod()&&LOOKUP_METHOD[this.memberName]){this.getterOrSetter=this.memberName;}this.memberName=token;}}if(!this.memberType){throw new Error("Missing member type in declaration '"+tokens.join(" ")+"'.");}},"public function getQualifiedName",function(){return this._namespace+"::"+this.memberName;},"public function isPrivate",function(){return this._namespace==NAMESPACE_PRIVATE;},"public function isStatic",function(){return this._static;},"public function isFinal",function(){return this._final;},"public function isNative",function(){return this._native;},"public function isOverride",function(){return this._override;},"public function isBound",function(){return this._bound;},"public function isMethod",function(){return this.memberType==MEMBER_TYPE_FUNCTION;},"internal function getNativeMember",function(publicConstructor){var target=this.isStatic()?publicConstructor:publicConstructor.prototype;if(this.memberType==MEMBER_TYPE_FUNCTION&&this.getterOrSetter){this.memberType=MEMBER_TYPE_VAR;this.getterOrSetter=null;}try{var member=target[this.memberName];}catch(e){if(is(e,Error)){}}if(typeof member!="function"){var memberObject={};memberObject[this.memberName]=member;member=memberObject;}return member;},"internal function hasOwnMember",function(target){if(!this.getterOrSetter&&target.hasOwnProperty){return target.hasOwnProperty(this.slot);}var value=this.retrieveMember(target);if(value!==undefined){var superTarget=target.constructor.prototype;var superValue=this.retrieveMember(superTarget);if(value!==superValue){return true;}}return false;},"internal function retrieveMember",function(target){if(!target){return undefined;}var slot=this.slot;if(this.getterOrSetter){if(SUPPORTS_GETTERS_SETTERS){return target[LOOKUP_METHOD[this.getterOrSetter]](slot);}else{slot=this.getterOrSetter+"$"+slot;}}return target[slot];},"internal function storeMember",function(target){if(!this.isNative()){var slot=this.slot;if(this.getterOrSetter){if(SUPPORTS_GETTERS_SETTERS){var oppositeMethodType=this.getterOrSetter==METHOD_TYPE_GET?METHOD_TYPE_SET:METHOD_TYPE_GET;var counterpart=target[LOOKUP_METHOD[oppositeMethodType]](slot);if(counterpart&&counterpart===target.constructor.prototype[LOOKUP_METHOD[oppositeMethodType]](slot)){target[DEFINE_METHOD[oppositeMethodType]](slot,counterpart);}target[DEFINE_METHOD[this.getterOrSetter]](slot,this.value);return;}else{slot=this.getterOrSetter+"$"+slot;}}target[slot]=this.value;}},"public function hasInitializer",function(){return this.memberType!=MEMBER_TYPE_FUNCTION&&typeof this.value=="function"&&this.value.constructor!==RegExp;},"public function _getCloneFactory",function(){if(!this._cloneFactory){this._cloneFactory=function(){};this._cloneFactory.prototype=this;}return this._cloneFactory;},"public function clone",function(changedProperties){var CloneFactory=this._getCloneFactory();var clone=new CloneFactory();for(var m in changedProperties){clone[m]=changedProperties[m];}return clone;},"public function toString",function(){var sb=[this._namespace];if(this._static){sb.push(STATIC);}if(this._override){sb.push(OVERRIDE);}if(this._bound){sb.push(BOUND);}sb.push(this.memberType);if(this.getterOrSetter){sb.push(this.getterOrSetter);}sb.push(this.memberName);return sb.join(" ");},];},["create"]);joo.classLoader.prepare("package joo",["import joo.*",""],"public class NativeClassDeclaration",function(NativeClassDeclaration,$$private){with(joo)with(NativeClassDeclaration)with($$private)return["internal static function createEmptyConstructor",function(constructor_){var emptyConstructor=function(){this.constructor=constructor_;};emptyConstructor.prototype=constructor_.prototype;return emptyConstructor;},"internal var",{level:-1,fullClassName: undefined,constructor_: undefined,publicConstructor: undefined,completed:false,inited:false,Public: undefined,superClassDeclaration: undefined,interfaces: undefined},"public function NativeClassDeclaration",function(fullClassName,publicConstructor){this[$super]();this.fullClassName=fullClassName;this.publicConstructor=publicConstructor;this.publicConstructor.$class=this;},"internal function complete",function(){if(!this.completed){this.completed=true;this.doComplete();}return this;},"internal function doComplete",function(){this.interfaces=[];this.constructor_=this.publicConstructor;this.Public=createEmptyConstructor(this.publicConstructor);},"internal function init",function(){if(!this.inited){this.inited=true;this.complete();this.doInit();}return this;},"internal function doInit",function(){},"public function isInstance",function(object){return object instanceof this.constructor_||object&&object.constructor===this.constructor_;},"public function getQualifiedName",function(){return this.fullClassName.replace(/\.([^\.]+)^/,"::");},"public function toString",function(){return this.fullClassName;},];},["createEmptyConstructor"]);joo.classLoader.prepare("package joo",["import joo.NativeClassDeclaration","import joo.MemberDeclaration","import joo.*",""],"public class SystemClassDeclaration extends NativeClassDeclaration",function(SystemClassDeclaration,$$private){with(joo)with(SystemClassDeclaration)with($$private)return[function(){joo.classLoader.init(MemberDeclaration);},"internal static function createDefaultConstructor",function(superName){return(function $DefaultConstructor(){this[superName].apply(this,arguments);});},"internal static function createPublicConstructor",function(cd){return function joo$SystemClassDeclaration$constructor(){this.constructor=cd.publicConstructor;cd.constructor_.apply(this,arguments);};},"private static function is_",function(object,type){if(!type||object===undefined||object===null){return false;}if(type["$class"]){return(type["$class"]).isInstance(object);}return object instanceof type||object.constructor===type;},function(){joo["is"]=is_;},"internal var",{package_: undefined,isInterface:false,namespace_:"intern",className: undefined,native_:false,extends_:"Object",privateStatics: undefined,memberDeclarations: undefined,memberDeclarationsByQualifiedName: undefined,initializerNames: undefined,staticInitializers: undefined,boundMethodNames: undefined,publicStaticMethodNames: undefined},"public function SystemClassDeclaration",function(packageDef,directives,classDef,memberDeclarations,publicStaticMethodNames){var packageName=packageDef.split(/\s+/)[1]||"";this.package_=joo.getOrCreatePackage(packageName);this.parseDirectives(packageName,directives);var classMatch=classDef.match(/^\s*((public|internal|final|dynamic)\s+)*class\s+([A-Za-z][a-zA-Z$_0-9]*)(\s+extends\s+([a-zA-Z$_0-9.]+))?(\s+implements\s+([a-zA-Z$_0-9.,\s]+))?\s*$/);var interfaces;if(classMatch){if(classMatch[5]){this.extends_=classMatch[5];}interfaces=classMatch[7];}else{classMatch=classDef.match(/^\s*((public|internal)\s+)?interface\s+([A-Za-z][a-zA-Z$_0-9]*)(\s+extends\s+([a-zA-Z$_0-9.,\s]+))?\s*$/);this.isInterface=true;interfaces=classMatch[5];}if(!classMatch){throw new Error("SyntaxError: \""+classDef+"\" does not match.");}this.namespace_=classMatch[2];this.className=classMatch[3];var fullClassName=this.className;if(packageName){fullClassName=packageName+"."+this.className;}this.interfaces=interfaces?interfaces.split(/\s*,\s*/):[];this.memberDeclarations=memberDeclarations;this.publicStaticMethodNames=publicStaticMethodNames;var publicConstructor=joo.getQualifiedObject(fullClassName);if(publicConstructor){this.native_=true;}else{publicConstructor=createPublicConstructor(this);this.package_[this.className]=publicConstructor;}this[$super](fullClassName,publicConstructor);this.privateStatics={"Class":Class,"assert":joo["assert"],"is":is_,"trace":trace};},"internal function parseDirectives",function(packageName,directives){},"internal override function doComplete",function(){this.superClassDeclaration=joo.classLoader.getRequiredClassDeclaration(this.extends_);this.superClassDeclaration.complete();this.level=this.superClassDeclaration.level+1;this.privateStatics.$super=this.level+"super";var Super=this.superClassDeclaration.Public;if(!this.native_){this.publicConstructor.prototype=new Super();}this.Public=NativeClassDeclaration.createEmptyConstructor(this.publicConstructor);},"internal function initMembers",function(){this.initializerNames=[];this.staticInitializers=[];this.boundMethodNames=[];var memberDeclarations=this.memberDeclarations(this.publicConstructor,this.privateStatics);this.memberDeclarations=[];this.memberDeclarationsByQualifiedName={};this.constructor_=null;for(var i=0;i<memberDeclarations.length;++i){var item=memberDeclarations[i];switch(typeof item){case"undefined":continue;case"function":this.staticInitializers.push(item);break;case"string":var memberDeclaration=MemberDeclaration.create(item);if(memberDeclaration){if(!memberDeclaration.isNative()){if(++i>=memberDeclarations.length){throw new Error(this+": Member expected after modifiers '"+item+"'.");}var member=memberDeclarations[i];}if(memberDeclaration.memberType=="function"){this.initMethod(memberDeclaration,member);}else{for(var memberName in member){this._storeMember(this._createMemberDeclaration(memberDeclaration,{memberName:memberName}),member[memberName]);}}}}}var defaultConstructor=this.native_?this.publicConstructor:this.publicConstructor.prototype[this.level+"super"]=this.initializerNames.length==0?this.superClassDeclaration.constructor_:createSuperCall(this);if(!this.constructor_){this.constructor_=defaultConstructor;}if(this.boundMethodNames.length>0){this.constructor_=createMethodBindingConstructor(this.constructor_,this.boundMethodNames);}},"private static function createSuperCall",function(cd){if(cd.extends_=="Object"){return function $super(){for(var i=0;i<cd.initializerNames.length;++i){var slot=cd.initializerNames[i];this[slot]=this[slot]();}};}return function $super(){cd.superClassDeclaration.constructor_.apply(this,arguments);for(var i=0;i<cd.initializerNames.length;++i){var slot=cd.initializerNames[i];this[slot]=this[slot]();}};},"private static function createMethodBindingConstructor",function(constructor_,boundMethodNames){return function $bindMethods(){for(var i=0;i<boundMethodNames.length;++i){var slot=boundMethodNames[i];this[slot]=this[slot].bind(this);}constructor_.apply(this,arguments);};},"internal function _initSlot",function(memberDeclaration){memberDeclaration.slot=memberDeclaration.isPrivate()&&!memberDeclaration.isStatic()?this.privateStatics["$"+memberDeclaration.memberName]=this.level+memberDeclaration.memberName:memberDeclaration.memberName;},"internal function initMethod",function(memberDeclaration,member){if(memberDeclaration.memberName==this.className&&!memberDeclaration.isStatic()){if(memberDeclaration.getterOrSetter){throw new Error(this+": Class name cannot be used for getter or setter: "+memberDeclaration);}this.constructor_=memberDeclaration.isNative()?this.publicConstructor:member;}else{this._initSlot(memberDeclaration);if(memberDeclaration.isNative()){member=memberDeclaration.getNativeMember(this.publicConstructor);}if(this.extends_!="Object"){var superMethod=memberDeclaration.retrieveMember(this.superClassDeclaration.Public.prototype);}var overrides=! !superMethod&&superMethod!==Object.prototype[memberDeclaration.memberName];if(overrides!==memberDeclaration.isOverride()){var msg=overrides?"Method overrides without 'override' modifier":"Method with 'override' modifier does not override";throw new Error(this+": "+msg+": "+memberDeclaration);}if(overrides){this._storeMember(this._createMemberDeclaration(memberDeclaration,{_namespace:MemberDeclaration.NAMESPACE_PRIVATE}),superMethod);}this._storeMember(memberDeclaration,member);if(memberDeclaration.isBound()){this.boundMethodNames.push(memberDeclaration.slot);}}},"internal function _createMemberDeclaration",function(memberDeclaration,changedProperties){var newMemberDeclaration=memberDeclaration.clone(changedProperties);this._initSlot(newMemberDeclaration);return newMemberDeclaration;},"internal function _storeMember",function(memberDeclaration,value){this.memberDeclarations.push(memberDeclaration);this.memberDeclarationsByQualifiedName[memberDeclaration.getQualifiedName()]=memberDeclaration;memberDeclaration.value=value;var _static=memberDeclaration.isStatic();var _private=memberDeclaration.isPrivate();var target=_static?_private?this.privateStatics:this.publicConstructor:this.publicConstructor.prototype;if(!memberDeclaration.hasOwnMember(target)){memberDeclaration.storeMember(target);if(memberDeclaration.hasInitializer()){if(_static){this.staticInitializers.push(memberDeclaration);}else{this.initializerNames.push(memberDeclaration.slot);}}}},"internal override function doInit",function(){this.superClassDeclaration.init();this.initMembers();for(var i=0;i<this.staticInitializers.length;++i){var staticInitializer=this.staticInitializers[i];if(typeof staticInitializer=="function"){staticInitializer();}else{var target=staticInitializer.isPrivate()?this.privateStatics:this.publicConstructor;target[staticInitializer.slot]=target[staticInitializer.slot]();}}},"public function getMemberDeclaration",function(namespace_,memberName){return this.memberDeclarationsByQualifiedName[namespace_+"::"+memberName];},];},["createDefaultConstructor","createPublicConstructor"]);joo.classLoader.prepare("package joo",["import joo.SystemClassDeclaration","import joo.NativeClassDeclaration","import joo.*",""],"public class SystemClassLoader",function(SystemClassLoader,$$private){with(joo)with(SystemClassLoader)with($$private)return[function(){joo["classLoader"]=new SystemClassLoader();},"public static const",{classDeclarationsByName:function(){return({});}},"public var",{debug:false},"public function SystemClassLoader",function(){this[$super]();},"public function prepare",function(packageDef,directives,classDef,memberFactory,publicStaticMethodNames){var cd=this.createClassDeclaration(packageDef,directives,classDef,memberFactory,publicStaticMethodNames);classDeclarationsByName[cd.fullClassName]=cd;},"internal function createClassDeclaration",function(packageDef,directives,classDef,memberFactory,publicStaticMethodNames){return new SystemClassDeclaration(packageDef,directives,classDef,memberFactory,publicStaticMethodNames).init();},"public function getClassDeclaration",function(fullClassName){var cd=classDeclarationsByName[fullClassName];if(!cd){var constructor_=joo.getQualifiedObject(fullClassName);if(constructor_){if(!constructor_.$class){cd=this.createNativeClassDeclaration(fullClassName,constructor_).init();classDeclarationsByName[fullClassName]=cd;}else{cd=constructor_.$class;}}}return cd;},"public function getRequiredClassDeclaration",function(className){var cd=this.getClassDeclaration(className);if(!cd){throw new Error("Class not found: "+className);}return cd;},"protected function createNativeClassDeclaration",function(fullClassName,nativeClass){return new NativeClassDeclaration(fullClassName,nativeClass);},];},[]);joo.classLoader.prepare("package",[""],"public class Array extends Object",function(Array,$$private){with(Array)with($$private)return["public static const",{CASEINSENSITIVE:1},"public static const",{DESCENDING:2},"public static const",{NUMERIC:16},"public static const",{RETURNINDEXEDARRAY:8},"public static const",{UNIQUESORT:4},"public native function get length","public native function set length","public native function Array","public native function concat","public function every",function(callback,thisObject){if(arguments.length<2){thisObject=null;}var i=0,j=this.length;if(thisObject){for(;i<j;i++){if(i in this){if(!callback.call(thisObject,this[i],i,this)){return false;}}}}else{for(;i<j;i++){if(i in this){if(!callback(this[i],i,this)){return false;}}}}return true;},"public function filter",function(callback,thisObject){var len=this.length;var res=[];var i=0;var val;if(thisObject){for(;i<len;i++){if(i in this){val=this[i];if(callback.call(thisObject,val,i,this)){res.push(val);}}}}else{for(;i<len;i++){if(i in this){val=this[i];if(callback(val,i,this)){res.push(val);}}}}return res;},"public function forEach",function(callback,thisObject){var i=0,j=this.length;if(thisObject){for(;i<j;i++){if(i in this){callback.call(thisObject,this[i],i,this);}}}else{for(;i<j;i++){if(i in this){callback(this[i],i,this);}}}},"public function indexOf",function(searchElement,fromIndex){if(arguments.length<2){fromIndex=0;}var len=this.length;for(var i=(fromIndex<0)?Math.max(0,len+fromIndex):fromIndex||0;i<len;i++){if(searchElement===this[i])return i;}return-1;},"public native function join","public function lastIndexOf",function(searchElement,fromIndex){if(arguments.length<2){fromIndex=0x7fffffff;}var len=this.length;for(var i=((fromIndex<0)?Math.max(len,len-fromIndex):fromIndex||len)-1;i>=0;i--){if(searchElement===this[i])return i;}return-1;},"public function map",function(callback,thisObject){if(arguments.length<2){thisObject=null;}var results=[];var i=0,j=this.length;if(thisObject){for(;i<j;i++){results[i]=callback.call(thisObject,this[i],i,this);}}else{for(;i<j;i++){results[i]=callback(this[i],i,this);}}return results;},"public native function pop","public native function push","public native function reverse","public native function shift","public native function slice","public function some",function(callback,thisObject){if(arguments.length<2){thisObject=null;}var i=0,j=this.length;if(thisObject){for(;i<j;i++){if(i in this){if(callback.call(thisObject,this[i],i,this)){return true;}}}}else{for(;i<j;i++){if(i in this){if(callback(this[i],i,this)){return true;}}}}return false;},"public native function sort","public native function splice","public native function toLocaleString","public native function toString","public native function unshift",];},[]);joo.classLoader.prepare("package joo",["import joo.*",""],"internal class ImportMap",function(ImportMap,$$private){with(joo)with(ImportMap)with($$private)return["private var",{importsByName: undefined},"private var",{importedPackages: undefined},"internal function ImportMap",function(){this[$super]();this[$importsByName]={};this[$importedPackages]=[""];},"internal function addImport",function(fullClassName){var afterLastDotIndex=fullClassName.lastIndexOf(".")+1;var packageName=fullClassName.substring(0,afterLastDotIndex);var className=fullClassName.substring(afterLastDotIndex);if(className=="*"){this[$importedPackages].push(packageName);}else{if(className in this[$importsByName]&&this[$importsByName][className]!=fullClassName){delete this[$importsByName][className];}else{this[$importsByName][className]=fullClassName;}}},"internal function getImports",function(){var imports=[];for(var $1 in this[$importsByName]){var im=this[$importsByName][$1];imports.push(im);}return imports;},"internal function findQualifiedName",function(className){if(className.indexOf(".")<0){var fqn=this[$importsByName][className];if(fqn){return fqn;}var packages=this[$importedPackages];for(var i=packages.length-1;i>=0;--i){fqn=packages[i]+className;if(joo.classLoader.getClassDeclaration(fqn)){return fqn;}}}return className;},"internal function addToMap",function(map){for(var im in this[$importsByName]){map[im]=(joo.classLoader).getRequiredClassDeclaration(this[$importsByName][im]).publicConstructor;}return map;},"internal function init",function(){for(var im in this[$importsByName]){(joo.classLoader).getRequiredClassDeclaration(this[$importsByName][im]).init();}},];},[]);joo.classLoader.prepare("package joo",["import joo.ImportMap","import joo.SystemClassDeclaration","import joo.NativeClassDeclaration","import joo.*",""],"public class ClassDeclaration extends joo.SystemClassDeclaration",function(ClassDeclaration,$$private){with(joo)with(ClassDeclaration)with($$private)return["private var",{importMap: undefined},"public function ClassDeclaration",function(packageDef,directives,classDef,memberDeclarations,publicStaticMethods){this[$super](packageDef,directives,classDef,memberDeclarations,publicStaticMethods);},"internal function getDependencies",function(){var dependencies=this[$importMap].getImports();dependencies.push(this[$importMap].findQualifiedName(this.extends_));return dependencies;},"override internal function parseDirectives",function(packageName,directives){this[$importMap]=new ImportMap();this[$importMap].addImport(packageName+".*");directives.forEach(this[$parseDirective]);},"private bound function parseDirective",function(directive){var importMatch=directive.match(/^\s*import\s+(([a-zA-Z$_0-9]+\.)*(\*|[a-zA-Z$_0-9]+))\s*$/);if(importMatch){this[$importMap].addImport(importMatch[1]);}},"override internal function doComplete",function(){this.extends_=this[$importMap].findQualifiedName(this.extends_);this[$doComplete]();for(var i=0;i<this.interfaces.length;++i){this.interfaces[i]=this[$importMap].findQualifiedName(this.interfaces[i]);}this[$importMap].addToMap(this.privateStatics);createInitializingConstructor(this);this.publicStaticMethodNames.forEach(this[$createInitializingStaticMethod]);},"private static function createInitializingConstructor",function(classDeclaration){classDeclaration.constructor_=function(){classDeclaration.init();classDeclaration.constructor_.apply(this,arguments);};},"private bound function createInitializingStaticMethod",function(methodName){var classDeclaration=this;classDeclaration.publicConstructor[methodName]=function(){classDeclaration.init();return classDeclaration.publicConstructor[methodName].apply(null,arguments);};},"private bound function deleteInitializingStaticMethod",function(methodName){delete this.publicConstructor[methodName];},"internal override function doInit",function(){this.publicStaticMethodNames.forEach(this[$deleteInitializingStaticMethod]);this[$doInit]();this.interfaces.forEach(function(interface_,i,interfaces){interfaces[i]=joo.classLoader.getRequiredClassDeclaration(interface_);}.bind(this));},"public override function isInstance",function(object){return typeof object=="object"&&object.constructor.$class?this.isAssignableFrom(object.constructor.$class):false;},"internal bound function isAssignableFrom",function(cd){do{if(this===cd){return true;}if(this.isInterface){if(cd.interfaces.some(this.isAssignableFrom)){return true;}}cd=cd.superClassDeclaration;}while(cd);return false;},];},[]);joo.classLoader.prepare("package joo",["import joo.ImportMap","import joo.ClassDeclaration","import joo.SystemClassLoader","import joo.SystemClassDeclaration","import joo.*",""],"public class StandardClassLoader extends joo.SystemClassLoader",function(StandardClassLoader,$$private){with(joo)with(StandardClassLoader)with($$private)return["private static var",{classDeclarations:function(){return([]);}},"private var",{importMap: undefined},"public function StandardClassLoader",function(){this[$super]();this[$importMap]=new ImportMap();},"override internal function createClassDeclaration",function(packageDef,directives,classDef,memberFactory,publicStaticMethodNames){var cd=new ClassDeclaration(packageDef,directives,classDef,memberFactory,publicStaticMethodNames);classDeclarations.push(cd);return cd;},"public function loadScript",function(uri){var script=window.document.createElement("script");script.type="text/javascript";window.document.body.appendChild(script);script.src=uri;},"public function import_",function(fullClassName){this[$importMap].addImport(fullClassName);},"public function run",function(mainClassName){var args=Array.prototype.slice.call(arguments,1);this.complete(function(){var mainClass=this.getRequiredClassDeclaration(mainClassName);mainClass.publicConstructor["main"].apply(null,args);}.bind(this));},"public function init",function(){var classes=arguments;var clazz;for(var i=0;i<classes.length;++i){if(classes[i].$class){((clazz=classes[i]).$class).init();}}return clazz;},"public function complete",function(onCompleteCallback){this.completeAll();if(onCompleteCallback){this.doCompleteCallbacks([onCompleteCallback]);}},"protected function completeAll",function(){classDeclarations.forEach(function(classDeclaration){classDeclaration.complete();if(classDeclaration.native_){classDeclaration.init();}});},"protected function doCompleteCallbacks",function(onCompleteCallbacks){if(onCompleteCallbacks.length){this[$importMap].init();var importMap=this[$importMap].addToMap({});for(var i=0;i<onCompleteCallbacks.length;++i){(onCompleteCallbacks[i])(importMap);}}},];},[]);joo.classLoader.prepare("package joo",["import joo.StandardClassLoader","import joo.SystemClassDeclaration","import joo.*",""],"public class DynamicClassLoader extends joo.StandardClassLoader",function(DynamicClassLoader,$$private){with(joo)with(DynamicClassLoader)with($$private)return["private static function isEmpty",function(object){for(var m in object){return false;}return true;},"public var",{classLoadTimeoutMS:0,urlPrefix:"joo/classes/"},"private var",{loadCheckTimer: undefined,onCompleteCallbacks:function(){return([]);}},"private var",{pendingDependencies:function(){return([]);}},"private var",{pendingClassState:function(){return({});}},"override internal function createClassDeclaration",function(packageDef,directives,classDef,memberFactory,publicStaticMethodNames){var cd=this[$createClassDeclaration](packageDef,directives,classDef,memberFactory,publicStaticMethodNames);this[$pendingDependencies].push(cd);if(delete this[$pendingClassState][cd.fullClassName]){if(this.debug){trace("prepared class "+cd.fullClassName+", removed from pending classes.");}if(this[$onCompleteCallbacks].length){this[$loadPendingDependencies]();if(this[$loadCheckTimer]){window.clearTimeout(this[$loadCheckTimer]);this[$loadCheckTimer]=undefined;}if(isEmpty(this[$pendingClassState])){var onCompleteCallbacks=this[$onCompleteCallbacks];this[$onCompleteCallbacks]=[];window.setTimeout(function(){this.completeAll();this.doCompleteCallbacks(onCompleteCallbacks);}.bind(this),0);}else if(this.classLoadTimeoutMS){this[$loadCheckTimer]=window.setTimeout(this[$throwMissingClassesError],this.classLoadTimeoutMS);}}}return cd;},"private bound function throwMissingClassesError",function(){var sb=[];for(var loading in this[$pendingClassState]){if(this[$pendingClassState][loading]){sb.push(loading);}}if(sb.length>0){throw new Error("The following classes were not loaded after "+this.classLoadTimeoutMS+" milliseconds: "+sb.join(", "));}},"public override function import_",function(fullClassName){this[$import_](fullClassName);this[$load](fullClassName);},"override public function run",function(mainClassName){var args=Array.prototype.slice.call(arguments,1);this[$load](mainClassName);args.splice(0,0,mainClassName);this[$run].apply(this,args);},"private function load",function(fullClassName){if(!this.getClassDeclaration(fullClassName)){if(this[$onCompleteCallbacks].length==0){if(this[$pendingClassState][fullClassName]===undefined){this[$pendingClassState][fullClassName]=false;if(this.debug){trace("added to pending classes: "+fullClassName+".");}}}else{if(this[$pendingClassState][fullClassName]!==true){this[$pendingClassState][fullClassName]=true;var url=this.getUri(fullClassName);if(this.debug){trace("triggering to load class "+fullClassName+" from URL "+url+".");}this.loadScript(url);}}}},"protected function getBaseUri",function(){var baseUri=window.document.location.href;return baseUri.substring(0,baseUri.lastIndexOf("/")+1)+this.urlPrefix;},"protected function getUri",function(fullClassName){var baseUri=this.getBaseUri();return baseUri+fullClassName.replace(/\./g,"/")+".js";},"public override function complete",function(onCompleteCallback){if(onCompleteCallback||this[$onCompleteCallbacks].length==0){this[$onCompleteCallbacks].push(onCompleteCallback||defaultOnCompleteCallback);}this[$loadPendingDependencies]();if(isEmpty(this[$pendingClassState])){this[$complete](onCompleteCallback);}else{for(var c in this[$pendingClassState]){this[$load](c);}}},"private static function defaultOnCompleteCallback",function(){trace("All classes loaded!");},"private function loadPendingDependencies",function(){for(var j=0;j<this[$pendingDependencies].length;++j){var dependencies=(this[$pendingDependencies][j]).getDependencies();for(var i=0;i<dependencies.length;++i){this[$load](dependencies[i]);}}this[$pendingDependencies]=[];},];},[]);joo.classLoader = new joo.DynamicClassLoader();