// Generated by Construct 2, the HTML5 game and app creator :: http://www.scirra.com
//////////////////////////////////////
// COCOONJS.JS                      //
//////////////////////////////////////

(function()
{
	// There should not be a CocoonJS object when this code is executed.
	// if (typeof window.CocoonJS !== 'undefined') throw("This is strange, a CocoonJS object already exists when trying to create it.");

    /**
    * The basic object for all the CocoonJS related specific APIs === extensions.
    * @namespace
    */
    CocoonJS = window.CocoonJS ? window.CocoonJS : {};

	CocoonJS.nativeExtensionObjectAvailable = typeof window.ext !== 'undefined';

	/**
	* This type represents a 2D size structure with horizontal and vertical values.
	* @namespace
	*/
	CocoonJS.Size = {
		/**
		* The horizontal size value.
		*/
		width : 0,

		/**
		* The vertical size value.
		*/
		height : 0
	};

	/**
	* This utility function allows to create an object oriented like hierarchy between two functions using their prototypes.
	* This function adds a "superclass" and a "__super" attributes to the subclass and it's functions to reference the super class.
	* @param {function} subc The subclass function.
	* @param {function} superc The superclass function.
	*/
	CocoonJS.extend = function(subc, superc) {
	    var subcp = subc.prototype;

	    // Class pattern.
	    var CocoonJSExtendHierarchyChainClass = function() {};
	    CocoonJSExtendHierarchyChainClass.prototype = superc.prototype;

	    subc.prototype = new CocoonJSExtendHierarchyChainClass();       // chain prototypes.
	    subc.superclass = superc.prototype;
	    subc.prototype.constructor = subc;

	    // Reset constructor. See Object Oriented Javascript for an in-depth explanation of this.
	    if (superc.prototype.constructor === Object.prototype.constructor) {
	        superc.prototype.constructor = superc;
	    }

	    // Check all the elements in the subclass prototype and add them to the chain object's prototype.
	    for (var method in subcp) {
	        if (subcp.hasOwnProperty(method)) {
	            subc.prototype[method] = subcp[method];

	            // // tenemos en super un metodo con igual nombre.
	            // if ( superc.prototype[method]) 
	            // {
	            //     subc.prototype[method]= (function(fn, fnsuper) 
	            //     {
	            //         return function() 
	            //         {
	            //             var prevMethod= this.__super;

	            //             this.__super= fnsuper;

	            //             var retValue= fn.apply(
	            //                     this,
	            //                     Array.prototype.slice.call(arguments) );

	            //             this.__super= prevMethod;

	            //             return retValue;
	            //         };
	            //     })(subc.prototype[method], superc.prototype[method]);
	            // }
	        }
	    }
	}

	/**
	* IMPORTANT: This function should only be used by Ludei.
	* This function allows a call to the native extension object function reusing the same arguments object.
	* Why is interesting to use this function instead of calling the native object's function directly?
	* As the CocoonJS object functions expicitly receive parameters, if they are not present and the native call is direcly mapped,
	* undefined arguments are passed to the native side. Some native functions do not check the parameters validation
	* correctly (just check the number of parameters passed).
	* Another solution instead of using this function call is to correctly check if the parameters are valid (not undefined) to make the
	* call, but it takes more work than using this approach.
	* @static
	* @param {string} nativeExtensionObjectName The name of the native extension object name. The object that is a member of the 'ext' object.
	* @param {string} nativeFunctionName The name of the function to be called inside the native extension object.
	* @param {object} arguments The arguments object of the CocoonJS extension object function. It contains all the arguments passed to the CocoonJS extension object function and these are the ones that will be passed to the native call too.
	* @param {boolean} [async] A flag to indicate if the makeCall (false or undefined) or the makeCallAsync function should be used to perform the native call.
	* @returns Whatever the native function call returns.
	*/
	CocoonJS.makeNativeExtensionObjectFunctionCall = function(nativeExtensionObjectName, nativeFunctionName, args, async) {
		if (CocoonJS.nativeExtensionObjectAvailable) {
			var argumentsArray = Array.prototype.slice.call(args);
			argumentsArray.unshift(nativeFunctionName);
			var nativeExtensionObject = ext[nativeExtensionObjectName];
			var makeCallFunction = async ? nativeExtensionObject.makeCallAsync : nativeExtensionObject.makeCall;
			var ret = makeCallFunction.apply(nativeExtensionObject, argumentsArray);
			var finalRet = ret;
			if (typeof ret === "string") {
				try	{
					finalRet = JSON.parse(ret);
				}
				catch(error) {
				}
			}
			return finalRet;
		}
	};

	/**
	* Returns an object retrieved from a path specified by a dot specified text path starting from a given base object.
	* It could be useful to find the reference of an object from a defined base object. For example the base object could be window and the
	* path could be "CocoonJS.App" or "document.body".
	* @param {Object} baseObject The object to start from to find the object using the given text path.
	* @param {string} objectPath The path in the form of a text using the dot notation. i.e. "document.body"
	* For example:
	* var body = getObjectFromPath(window, "document.body");
	*/
	CocoonJS.getObjectFromPath = function(baseObject, objectPath) {
    	var parts = objectPath.split('.');
    	var obj = baseObject;
        for (var i = 0, len = parts.length; i < len; ++i) 
        {
            obj[parts[i]] = obj[parts[i]] || undefined;
    		obj = obj[parts[i]];
    	}
    	return obj;
 	};

 	/**
 	* Returns the key for a value in a dictionary. It looks for an specific value inside a dictionary and returns the corresponding key.
 	* @param {Object} dictionary The dictionary to look for the value in and get the corresponding key.
 	* @param {Object} value The value to look for inside the dictionary and return it's corresponding key.
 	* @return The key that corresponds to the given value it is has been found or null.
 	*/
 	CocoonJS.getKeyForValueInDictionary = function(dictionary, value) {
        var finalKey = null;
        for (var key in dictionary) {
            if (dictionary[key] === value)            {
                finalKey = key;
                break;
            }
        }
        return finalKey;
 	}

 	/**
 	* Finds a string inside a given array of strings by looking for a given substring. It can also
 	* specify if the search must be performed taking care or not of the case sensitivity.
 	* @param {Array} stringArray The array of strings in which to to look for the string.
 	* @param {string} subString The substring to look for inside all the strings of the array.
 	* @param {boolean} caseSensitive A flag to indicate if the search must be performed taking case of the 
 	* case sensitiveness (true) or not (false).
 	* @return {string} The string that has been found or null if the substring is not inside any of the string of the array.
 	*/
 	CocoonJS.findStringInStringArrayThatIsIndexOf = function(stringArray, subString, caseSensitive) {
 		var foundString = null;
 		subString = caseSensitive ? subString : subString.toUpperCase();
 		for (var i = 0; foundString == null && i < stringArray.length; i++)	{
 			foundString = caseSensitive ? stringArray[i] : stringArray[i].toUpperCase();
 			foundString = foundString.indexOf(subString) >= 0 ? stringArray[i] : null; 
 		}
 		return foundString;
 	};

	/**
	* A class that represents objects to handle events. Event handlers have always the same structure:
	* Mainly they provide the addEventListener and removeEventListener functions.
	* Both functions receive a callback function that will be added or removed. All the added callback
	* functions will be called when the event takes place.
	* Additionally they also allow the addEventListenerOnce and notifyEventListeners functions.
	* @constructor
	* @param {string} nativeExtensionObjectName The name of the native extension object (inside the ext object) to be used.
	* @param {string} cocoonJSExtensionObjectName The name of the sugarized extension object.
	* @param {string} nativeEventName The name of the native event inside the ext object.
	* @param {number} [chainFunction] An optional function used to preprocess the listener callbacks. This function, if provided,
	* will be called before any of the other listeners.
	*/
	CocoonJS.EventHandler = function(nativeExtensionObjectName, cocoonJSExtensionObjectName, nativeEventName, chainFunction) {
		this.listeners = [];
		this.listenersOnce = [];
		this.chainFunction = chainFunction;

		/**
		* Adds a callback function so it can be called when the event takes place.
		* @param {function} listener The callback function to be added to the event handler object. See the referenced Listener function documentation for more detail in each event handler object's documentation.
		*/
		this.addEventListener = function(listener) {
			if (chainFunction) {
				var f = function() {
					chainFunction.call(this, arguments.callee.sourceListener, Array.prototype.slice.call(arguments)); 
				};
				listener.CocoonJSEventHandlerChainFunction = f;
				f.sourceListener = listener;
				listener = f;
			}

			var cocoonJSExtensionObject = CocoonJS.getObjectFromPath(CocoonJS, cocoonJSExtensionObjectName);
            if (cocoonJSExtensionObject && cocoonJSExtensionObject.nativeExtensionObjectAvailable) {
                ext[nativeExtensionObjectName].addEventListener(nativeEventName, listener);
            }
            else {
                var indexOfListener = this.listeners.indexOf(listener);
                if (indexOfListener < 0) {
                	this.listeners.push(listener);
                }
            }
		};

        this.addEventListenerOnce = function(listener)
		{
			if (chainFunction) {
				var f = function() { chainFunction(arguments.callee.sourceListener,Array.prototype.slice.call(arguments)); };
				f.sourceListener = listener;
				listener = f;
			}

			var cocoonJSExtensionObject = CocoonJS.getObjectFromPath(CocoonJS, cocoonJSExtensionObjectName);
            if (cocoonJSExtensionObject.nativeExtensionObjectAvailable) {
                ext[nativeExtensionObjectName].addEventListenerOnce(nativeEventName, listener);
            }
            else
            {
                var indexOfListener = this.listeners.indexOf(listener);
                if (indexOfListener < 0)
                {
                	this.listenersOnce.push(listener);
                }
            }
		};

        /**
         * Removes a callback function that was added to the event handler so it won't be called when the event takes place.
         * @param {function} listener The callback function to be removed from the event handler object. See the referenced Listener function documentation for more detail in each event handler object's documentation.
         */
        this.removeEventListener = function (listener) {

        	if (chainFunction) {
        		listener = listener.CocoonJSEventHandlerChainFunction;
        		delete listener.CocoonJSEventHandlerChainFunction;
        	}

			var cocoonJSExtensionObject = CocoonJS.getObjectFromPath(CocoonJS, cocoonJSExtensionObjectName);
            if (cocoonJSExtensionObject.nativeExtensionObjectAvailable) {
                ext[nativeExtensionObjectName].removeEventListener(nativeEventName, listener);
            }
            else {
                var indexOfListener = this.listeners.indexOf(listener);
                if (indexOfListener >= 0) {
                    this.listeners.splice(indexOfListener, 1);
                }
            }
        };

		this.notifyEventListeners = function() {
			var cocoonJSExtensionObject = CocoonJS.getObjectFromPath(CocoonJS, cocoonJSExtensionObjectName);
            if (cocoonJSExtensionObject && cocoonJSExtensionObject.nativeExtensionObjectAvailable) {
                ext[nativeExtensionObjectName].notifyEventListeners(nativeEventName);
            } else {

                var argumentsArray= Array.prototype.slice.call(arguments);
                var listeners =     Array.prototype.slice.call(this.listeners);
                var listenersOnce = Array.prototype.slice.call(this.listenersOnce);
                var _this = this;
                // Notify listeners after a while ;) === do not block this thread.
                setTimeout(function() {
                    for (var i = 0; i < listeners.length; i++) {
                        listeners[i].apply(_this, argumentsArray);
                    }
                    for (var i = 0; i < listenersOnce.length; i++) {
                        listenersOnce[i].apply(_this, argumentsArray);
                    }
                }, 0);

                _this.listenersOnce= [];
            }
		};
		return this;
	};

	/**
	* A simple timer class. Update it every loop iteration and get values from accumulated time to elapsed time in seconds or milliseconds.
	*/
	CocoonJS.Timer = function() {
		this.reset();
		return this;
	};

	CocoonJS.Timer.prototype = {
		currentTimeInMillis : 0,
		lastTimeInMillis : 0,
		elapsedTimeInMillis : 0,
		elapsedTimeInSeconds : 0,
		accumTimeInMillis : 0,

		/**
		Resets the timer to 0.
		*/
		reset : function() {
			this.currentTimeInMillis = this.lastTimeInMillis = new Date().getTime();
			this.accumTimeInMillis = this.elapsedTimeInMillis = this.elapsedTimeInSeconds = 0;
		},

		/**
		Updates the timer calculating the elapsed time between update calls.
		*/
		update : function() {
			this.currentTimeInMillis = new Date().getTime();
			this.elapsedTimeInMillis = this.currentTimeInMillis - this.lastTimeInMillis;
			this.elapsedTimeInSeconds = this.elapsedTimeInMillis / 1000.0;
			this.lastTimeInMillis = this.currentTimeInMillis;
			this.accumTimeInMillis += this.elapsedTimeInMillis;
		}
	};

	// CocoonJS.FindAllNativeBindingsInCocoonJSExtensionObject = function(cocoonJSExtensionObject, nativeFunctionBindingCallback, nativeEventBindingCallback)
	// {
	// 	for (var cocoonJSExtensionObjectAttributeName in cocoonJSExtensionObject)
	// 	{
	// 		var cocoonJSExtensionObjectAttribute = cocoonJSExtensionObject[cocoonJSExtensionObjectAttributeName];

	// 		// Function
	// 		if (typeof cocoonJSExtensionObjectAttribute === 'function' && typeof cocoonJSExtensionObjectAttribute.nativeFunctionName !== 'undefined')
	// 		{
	// 			var nativeFunctionName = cocoonJSExtensionObjectAttribute.nativeFunctionName;
	// 			nativeFunctionBindingCallback(cocoonJSExtensionObjectAttributeName, nativeFunctionName);
	// 		}
	// 		// Event object
	// 		else if (typeof cocoonJSExtensionObjectAttribute === 'object' && cocoonJSExtensionObjectAttribute !== null && typeof cocoonJSExtensionObjectAttribute.nativeEventName !== 'undefined')
	// 		{
	// 			var nativeEventName = cocoonJSExtensionObjectAttribute.nativeEventName;
	// 			nativeEventBindingCallback(cocoonJSExtensionObjectAttributeName, nativeEventName);
	// 		}
	// 	}
	// }

	/**
	This function looks for a CocoonJS extension object that is bound to the given native ext object name.
	@returns The CocoonJS extension object that corresponds to the give native extension object name or null if it cannot be found.
	*/
	// CocoonJS.GetCocoonJSExtensionObjectForNativeExtensionObjectName = function(nativeExtensionObjectName)
	// {
	// 	var cocoonJSExtensionObject = null;
	// 	// Look in the CocoonJS object and for every object that is a CocoonJS.Extension check if it's nativeExtensionObjectName matches to the one passed as argument. If so, create an object that will represent it's documentation for the native ext object.
	// 	for (var cocoonJSAttributeName in CocoonJS)
	// 	{
	// 		var cocoonJSAttribute = CocoonJS[cocoonJSAttributeName];
	// 		if (typeof cocoonJSAttribute === 'object' && cocoonJSAttribute instanceof CocoonJS.Extension && cocoonJSAttribute.nativeExtensionObjectName === nativeExtensionObjectName)
	// 		{
	// 			// We have found the CocoonJS object that represents the native ext extension object name. 
	// 			cocoonJSExtensionObject = cocoonJSAttribute;
	// 			break;
	// 		}
	// 	}
	// 	return cocoonJSExtensionObject;
	// };

	/**
	This function adds functions to a CocoonJS extension object in order to bind them to the native makeCall function calls of the ext object.

	@param extensionObject The reference to the CocoonJS extension object where to add the new functions bound to the ext object makeCall functions calls.

	@param nativeFunctionsConfiguration An array of objects with the following structure:

		{ nativeFunctionName : "" [, functionName : "", isAsync : true/false] }

		- nativeFunctionName: Specifies the name of the function inside the ext object makeCall function call that will be bound.
		- functionName: An optional attribute that allows to specify the name of the function to be added to the CocoonJS extension object. If is not present, the name of the function will be the same
		as the nativeFunctionName.
		- isAsync: An optional attribute that allows to specify if the call should be performed using makeCall (false or missing) or makeCallAsync (true).
		- alternativeFunction: An optional attribute that allows to specify an alternative function that will be called internally when this function is called. This attribute
		allows for adding new functionalities like for example adding methods 

	@returns The CocoonJS extension object.
	*/
	// CocoonJS.AddNativeFunctionBindingsToExtensionObject = function(extensionObject, nativeFunctionsConfiguration)
	// {
	// 	if (typeof extensionObject === 'undefined' || extensionObject === null) throw("The passed extension object be a valid object.");
	// 	if (typeof nativeFunctionsConfiguration === 'undefined' || nativeFunctionsConfiguration === null) throw("The passed native functions configuration array must be a valid object.");

	// 	for (var i = 0; i < nativeFunctionsConfiguration.length; i++)
	// 	{
	// 		if (typeof nativeFunctionsConfiguration[i].nativeFunctionName === 'undefined') throw("The 'nativeFunctionName' attribute in the native function configuration object at index '" + i + "' in the native function configuration array cannot be undefined.");
	// 		var nativeFunctionName = nativeFunctionsConfiguration[i].nativeFunctionName;
	// 		var functionName = typeof nativeFunctionsConfiguration[i].functionName !== 'undefined' ? nativeFunctionsConfiguration[i].functionName : nativeFunctionName;
	// 		var makeCallFunction = null;
	// 		makeCallFunction = typeof nativeFunctionsConfiguration[i].isAsync !== 'undefined' && nativeFunctionsConfiguration[i].isAsync ? extensionObject.nativeExtensionObject.makeCallAsync : extensionObject.nativeExtensionObject.makeCall;
	// 		// Add the new function to the CocoonJS extension object
	// 		extensionObject[functionName] = function()
	// 		{
	// 			// Convert the arguments object to an array
	// 			var arguments = Array.prototype.slice.call(arguments);
	// 			// Add the native function name as the first parameter
	// 			arguments.unshift(nativeFunctionName);
	// 			// Make the native ext object call
	// 			var result = makeCallFunction.apply(extensionObject.nativeExtensionObject, arguments);
	// 			return result;
	// 		}
	// 		// Add a property to the newly added function to store the name of the original function.
	// 		extensionObject[functionName].nativeFunctionName = nativeFunctionName;
	// 	}
	// 	return extensionObject;
	// };

	/**
	This function adds objects to a CocoonJS extension object to allow event listener handling (add and remove) bound to the native ext object event listener handling.

	@param extensionObject The reference to the CocoonJS extension object where to add the new objects bound to the ext object event listener handling.

	@param nativeEventsConfiguration An array of objects with the following structure:

		{ nativeEventName : "" [, eventObjectName : ""] }

		- nativeEventName: Specifies the event in the native ext object to be bound.
		- eventObjectName: An optional attribute that allows to specify the name of the object to be added to the CocoonJS extension object. If is not present, the name of the function will be the same
		as the nativeEventName.
		- alternativeAddEventListenerFunction:
		- alternativeRemoveEventListenerFunction:

	@returns The CocoonJS extension object.
	*/
	// CocoonJS.AddNativeEventBindingsToExtensionObject = function(extensionObject, nativeEventsConfiguration)
	// {
	// 	if (typeof extensionObject === 'undefined' || extensionObject === null) throw("The passed extension object be a valid object.");
	// 	if (typeof nativeEventsConfiguration === 'undefined' || nativeEventsConfiguration === null) throw("The passed native events configuration array must be a valid object.");

	// 	for (var i = 0; i < nativeEventsConfiguration.length; i++)
	// 	{
	// 		if (typeof nativeEventsConfiguration[i].nativeEventName === 'undefined') throw("The 'nativeEventName' attribute in the native event configuration object at index '" + i + "' in the native event configuration array cannot be undefined.");
	// 		var nativeEventName = nativeEventsConfiguration[i].nativeEventName;
	// 		var eventObjectName = typeof nativeEventsConfiguration[i].eventObjectName !== 'undefined' ? nativeEventsConfiguration[i].eventObjectName : nativeEventName;
	// 		// Anonymous function call so each variable in the loop is used in the event listener handling function bindings.
	// 		(function(nativeEventName, eventObjectName)
	// 		{
	//     		extensionObject[eventObjectName] =
	//     		{
	//     			// Store the native event name
	//     			nativeEventName : nativeEventName,
	//     			// Create the event listener management functions bound to the native counterparts
	//     			addEventListener : function(callback)
	// 	    		{
	// 	    			extensionObject.nativeExtensionObject.addEventListener(nativeEventName, callback);
	//     			},
	//     			removeEventListener : function(callback)
	//     			{
	// 	    			extensionObject.nativeExtensionObject.removeEventListener(nativeEventName, callback);
	//     			}
	//     			// ,
	//     			// removeAllEventListeners : function()
	//     			// {

	//     			// }
	//     		};
	// 		})(nativeEventName, eventObjectName);
	// 	}
	// 	return extensionObject;
	// };

	/**
	The function object constructor function all the CocoonJS extensions can use to instantiate the CocoonJS extension object and add all the functionality needed bound to the native ext object.

	@param nativeExtensionObject The reference to the ext object extension object.

	@param nativeFunctionsConfiguration See CocoonJS.AddNativeFunctionBindingsToExtensionObject function's documentation for more details.

	@param nativeEventsConfiguration See CocoonJS.AddNativeEventBindingsToExtensionObject function's documentation for more details.

	@returns The new CocoonJS extension object.
	*/
	// CocoonJS.Extension = function(nativeExtensionObjectName, nativeFunctionsConfiguration, nativeEventsConfiguration)
	// {
	// 	if (typeof nativeExtensionObjectName === 'undefined' || nativeExtensionObjectName === null) throw("The native extension object name cannot be null");

	// 	if (window.ext[nativeExtensionObjectName] === 'undefined') throw("The given native extension object name '" + nativeExtensionObjectName + "' is incorrect or the native extension object is undefined.");

	// 	var nativeExtensionObject = window.ext[nativeExtensionObjectName];

	// 	// Store a reference to the native extension object and to it's name
	// 	this.nativeExtensionObject = nativeExtensionObject;
	// 	this.nativeExtensionObjectName = nativeExtensionObjectName;

	// 	// If native function configuration is passed, use it to add some functions to the new extension object.
	// 	if (typeof nativeFunctionsConfiguration !== 'undefined')
	// 	{
	// 		CocoonJS.AddNativeFunctionBindingsToExtensionObject(this, nativeFunctionsConfiguration);
	// 	}

	// 	// If native event configuration is passed, use it to add some event objects to the new extension object.
	// 	if (typeof nativeEventsConfiguration !== 'undefined')
	// 	{
	// 		CocoonJS.AddNativeEventBindingsToExtensionObject(this, nativeEventsConfiguration);
	// 	}

	// 	return this;
	// };   

})();

//////////////////////////////////////
// COCOONJS_APP.JS                  //
//////////////////////////////////////

(function () {
    // The CocoonJS must exist before creating the extension.
    if (typeof window.CocoonJS === 'undefined' || window.CocoonJS === null) throw("The CocoonJS object must exist and be valid before creating any extension object.");

    /**
     * This namespace represents all the basic functionalities available in the CocoonJS extension API.
     * @namespace
     */
    CocoonJS.App = CocoonJS.App ? CocoonJS.App : {};

    CocoonJS.App.nativeExtensionObjectAvailable = CocoonJS.nativeExtensionObjectAvailable && typeof window.ext.IDTK_APP !== 'undefined';

    /**
     * The predefined possible layouts for the FPS overlay.
     * @namespace
     */
    CocoonJS.App.FPSLayout = {
        TOP_LEFT:'top-left',
        TOP_RIGHT:'top-right',
        BOTTOM_LEFT:'bottom-left',
        BOTTOM_RIGHT:'bottom-right'
    };

    /**
     * Contains all the possible values to specify the input keyboard type to be used when introducing text.
     * @namespace
     */
    CocoonJS.App.KeyboardType = {
        /**
         * Represents a generic text input keyboard.
         */
        TEXT:"text",

        /**
         * Represents a number like input keyboard.
         */
        NUMBER:"num",

        /**
         * Represents a phone like input keyboard.
         */
        PHONE:"phone",

        /**
         * Represents an email like input keyboard.
         */
        EMAIL:"email",

        /**
         * Represents an URL like input keyboard.
         */
        URL:"url"
    };

    /**
     * The storage types to be used with file system related operations.
     * @namespace
     */
    CocoonJS.App.StorageType = {
        /**
         * Represents the application storage. The application storage is the place where all the resources that come with the application are stored.
         */
        APP_STORAGE:"APP_STORAGE",

        /**
         * Represents the internal storage. The internal storage is a different storage space that the application storage and only the data that the application has stored
         * in it will be in this storage. It is internal to the platform/device.
         */
        INTERNAL_STORAGE:"INTERNAL_STORAGE",

        /**
         * Represents an external storage. The external storage is similar to the internal storage in the sense that it only contains information that the application has written
         * in it but it represents an external storage device like a SD-CARD. If there is no exrernal storage, it will represent the same as the internal storage.
         */
        EXTERNAL_STORAGE:"EXTERNAL_STORAGE",

        /**
         * Represents the temporal storage. Same as the internal and external storage spaces in the sense that it only contains information that the application has written
         * in it but the main difference is that the information in this storage may dissapear without notice.
         */
        TEMPORARY_STORAGE:"TEMPORARY_STORAGE"
    };

    /**
     * The capture types to capture screenshots using CocoonJS native capabilities.
     * @namespace
     */
    CocoonJS.App.CaptureType = {
        /**
         Captures everything, both the CocoonJS GL hardware accelerated surface and the system views (like the WebView).
         */
        EVERYTHING:0,

        /**
         * Captures just the CocoonJS GL hardware accelerated surface.
         */
        JUST_COCOONJS_GL_SURFACE:1,

        /**
         * Captures just the sustem views (like the webview)
         */
        JUST_SYSTEM_VIEWS:2
    };

    /**
     * Makes a forward call of some javascript code to be executed in a different environment (i.e. from CocoonJS to the WebView and viceversa).
     * It waits until the code is executed and the result of it is returned === synchronous.
     * @function
     * @param {string} javaScriptCode Some JavaScript code in a string to be forwarded and executed in a different JavaScript environment (i.e. from CocoonJS to the WebView and viceversa).
     * @return {string} The result of the execution of the passed JavaScript code in the different JavaScript environment.
     */
    CocoonJS.App.forward = function (javaScriptCode) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "forward", arguments);
        }
        else if (!navigator.isCocoonJS) {
            if (window.name == 'CocoonJS_App_ForCocoonJS_WebViewIFrame') {
                return window.parent.eval(javaScriptCode);
            }
            else {
                //return window.parent.frames['CocoonJS_App_ForCocoonJS_WebViewIFrame'].window.eval(javaScriptCode);
                return window.frames['CocoonJS_App_ForCocoonJS_WebViewIFrame'].window.eval(javaScriptCode);
            }
        }
    };

    /**
     * Makes a forward call of some javascript code to be executed in a different environment (i.e. from CocoonJS to the WebView and viceversa).
     * It is asyncrhonous so it does not wait until the code is executed and the result of it is returned. Instead, it calls a callback function when the execution has finished to pass the result.
     * @function
     * @param {string} javaScriptCode Some JavaScript code in a string to be forwarded and executed in a different JavaScript environment (i.e. from CocoonJS to the WebView and viceversa).
     * @param {function} [returnCallback] A function callback that will be called when the passed JavaScript code is executed in a different thread to pass the result of the execution in the different JavaScript environment.
     */
    CocoonJS.App.forwardAsync = function (javaScriptCode, returnCallback) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            if (typeof returnCallback !== 'undefined') {
                return ext.IDTK_APP.makeCallAsync("forward", javaScriptCode, returnCallback);
            }
            else {
                return ext.IDTK_APP.makeCallAsync("forward", javaScriptCode);
            }
        }
        else if (!navigator.isCocoonJS) {
            if (window.name == 'CocoonJS_App_ForCocoonJS_WebViewIFrame') {
                return window.parent.eval(javaScriptCode);
            }
            else {
                return window.parent.frames['CocoonJS_App_ForCocoonJS_WebViewIFrame'].window.eval(javaScriptCode);
                // window.frames['CocoonJS_App_ForCocoonJS_WebViewIFrame'].window.eval(javaScriptCode);
            }
        }
    };

    /**
     * Pops up a text dialog so the user can introduce some text and the application can get it back. It is the first approach CocoonJS has taken to be able to introduce
     * text input in a easy way. The dialog execution events are passed to the application through the {@link CocoonJS.App.onTextDialogFinished} and the {@link CocoonJS.App.onTextDialogCancelled} event objects.
     * @function
     * @param {string} [title] Default value is "". The title to be displayed in the dialog.
     * @param {string} [message] Default value is "". The message to be displayed in the dialog, next to the text input field.
     * @param {string} [text] Default value is "". The initial text to be introduced in the text input field.
     * @param {CocoonJS.App.KeyboardType} [keyboardType] Default value is {@link CocoonJS.App.KeyboardType.TEXT}. The keyboard type to be used when the text has to be introduced.
     * @param {string} [cancelButtonText] Default value is "". The text to be displayed in the cancel button of the dialog.
     * @param {string} [okButtonText] Default value is "". The text to be displayed in the ok button of the dialog.
     * @see CocoonJS.App.onTextDialogFinished
     * @see CocoonJS.App.onTextDialogCancelled
     */
    CocoonJS.App.showTextDialog = function (title, message, text, keyboardType, cancelButtonText, okButtonText) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "showTextDialog", arguments, true);
        }
        else if (!navigator.isCocoonJS) {
            if (!message) {
                message = "";
            }
            if (!text) {
                text = "";
            }
            var result = prompt(message, text);
            var eventObject = result ? CocoonJS.App.onTextDialogFinished : CocoonJS.App.onTextDialogCancelled;
            eventObject.notifyEventListeners(result);
        }
    };

    /**
     * Pops up a message dialog so the user can decide between a yes or no like confirmation. The message box execution events are passed to the application through the {@link CocoonJS.App.onMessageBoxConfirmed} and the {@link CocoonJS.App.onMessageBoxDenied} event objects.
     * @function
     * @param {string} [title] Default value is "". The title to be displayed in the dialog.
     * @param {string} [message] Default value is "". The message to be displayed in the dialog, next to the text input field.
     * @param {string} [confirmButtonText] Default value is "Yes". The text to be displayed for the confirm button.
     * @param {string} [denyButtonText] Default value is "No". The text to be displayed for the deny button.
     * @see CocoonJS.App.onMessageBoxConfirmed
     * @see CocoonJS.App.onMessageBoxDenied
     */
    CocoonJS.App.showMessageBox = function (title, message, confirmButtonText, denyButtonText) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "showMessageBox", arguments, true);
        }
        else if (!navigator.isCocoonJS) {
            if (!message) {
                message = "";
            }
            var result = confirm(message);
            var eventObject = result ? CocoonJS.App.onMessageBoxConfirmed : CocoonJS.App.onMessageBoxDenied;
            eventObject.notifyEventListeners();
        }
    };

    /**
     * It allows to load a new JavaScript/HTML5 resource that can be loaded either locally (inside the platform/device storage) or using a remote URL.
     * @function
     * @param {string} path A path to a resource stored in the platform or in a URL to a remote resource.
     * @param {CocoonJS.App.StorageType} [storageType] If the path argument represents a locally stored resource, the developer can specify the storage where it is stored. If no value is passes, the {@link CocoonJS.App.StorageType.APP_STORAGE} value is used by default.
     */
    CocoonJS.App.load = function (path, storageType) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "loadPath", arguments);
        }
        else if (!navigator.isCocoonJS) {
            var xhr = new XMLHttpRequest();

            xhr.onreadystatechange = function (event) {
                if (xhr.readyState === 4) {
                    if (xhr.status === 200) {
                        // TODO: As window load event is not being called (WHY???), I have decided to call the listeners directly
                        // var callback= function(event){
                        //     window.removeEventListener("load", callback);
                        var jsCode;
                        // If there is no webview, it means we are in the webview, so notify the CocoonJS environment
                        if (!CocoonJS.App.EmulatedWebViewIFrame) {
                            jsCode = "window.CocoonJS && window.CocoonJS.App.onLoadInTheWebViewSucceed.notifyEventListeners('" + path + "');";
                        }
                        // If there is a webview, it means we are in CocoonJS, so notify the webview environment
                        else {
                            jsCode = "window.CocoonJS && window.CocoonJS.App.onLoadInCocoonJSSucceed.notifyEventListeners('" + path + "');";
                        }
                        CocoonJS.App.forwardAsync(jsCode);
                        // };
                        // window.addEventListener("load", callback);
                        window.location.href = path;
                    }
                    else if (xhr.status === 404) {
                        this.onreadystatechange = null;
                        var jsCode;
                        // If there is no webview, it means we are in the webview, so notify the CocoonJS environment
                        if (!CocoonJS.App.EmulatedWebViewIFrame) {
                            jsCode = "CocoonJS && CocoonJS.App.onLoadInTheWebViewFailed.notifyEventListeners('" + path + "');";
                        }
                        // If there is a webview, it means we are in CocoonJS, so notify the webview environment
                        else {
                            jsCode = "CocoonJS && CocoonJS.App.onLoadInCocoonJSFailed.notifyEventListeners('" + path + "');";
                        }
                        CocoonJS.App.forwardAsync(jsCode);
                    }
                }
            };
            xhr.open("GET", path, true);
            xhr.send();
        }
    };

    /**
     * Reloads the last loaded path in the current context.
     * @function
     */
    CocoonJS.App.reload = function () {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "reload", arguments);
        }
        else if (!navigator.isCocoonJS) {
            if (window.name == 'CocoonJS_App_ForCocoonJS_WebViewIFrame') {
                return window.parent.location.reload();
            }
            else {
                return window.parent.frames['CocoonJS_App_ForCocoonJS_WebViewIFrame'].window.location.reload();
            }
        }
    };

    /**
     * Opens a given URL using a system service that is able to open it. For example, open a HTTP URL using the system WebBrowser.+
     * @function
     * @param {string} url The URL to be opened by a system service.
     */
    CocoonJS.App.openURL = function (url) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "openURL", arguments, true);
        }
        else if (!navigator.isCocoonJS) {
            window.open(url, '_blank');
        }
    }

    /**
     * Forces the app to be finished.
     * @function
     */
    CocoonJS.App.forceToFinish = function () {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "forceToFinish", arguments);
        }
        else if (!navigator.isCocoonJS) {
            window.close();
        }
    }

    /**
     * Enables or disables the auto lock to control if the screen keeps on after an inactivity period.
     * When the auto lock is enabled and the application has no user input for a short period, the system puts the device into a "sleepâ€ state where the screen dims or turns off.
     * When the auto lock is disabled the screen keeps on even when there is no user input for long times.
     * @param enabled A boolean value that controls whether to enable or disable the auto lock.
     */
    CocoonJS.App.setAutoLockEnabled = function (enabled) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "setAutoLockEnabled", arguments);
        }
    }

    /**
     * Creates a canvas element that is automatically resized to the screen size. When the app is being executed
     * inside CocoonJS. This canvas is optimized for rendering so it is higly recommended to use it if it fits
     * your app needs. If your app uses one canvas as the main canvas where all other canvases and images are displayed, Ludei recommends to
     * call this function in order to create this main canvas. A usual 2x performance gain is achieved by doing so
     * depending on the device and the graphics card driver.
     * @function
     * @return {object} The canvas object that should be used as the main canvas and that is resized to the screen resolution.
     */
    CocoonJS.App.createScreenCanvas = function () {
        var screenCanvas;
        if (navigator.isCocoonJS) {
            screenCanvas = document.createElement("screencanvas");
        }
        else if (!navigator.isCocoonJS) {
            screenCanvas = document.createElement("canvas");
            screenCanvas.width = window.innerWidth;
            screenCanvas.height = window.innerHeight;
        }
        return screenCanvas;
    };

    /**
     * Disables the touch events in the CocoonJS environment.
     * @function
     */
    CocoonJS.App.disableTouchInCocoonJS = function () {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            window.ext.IDTK_APP.makeCall("disableTouchLayer", "CocoonJSView");
        }
    };

    /**
     * Enables the touch events in the CocoonJS environment.
     * @function
     */
    CocoonJS.App.enableTouchInCocoonJS = function () {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            window.ext.IDTK_APP.makeCall("enableTouchLayer", "CocoonJSView");
        }
    };

    /**
     * Disables the touch events in the WebView environment.
     * @function
     */
    CocoonJS.App.disableTouchInTheWebView = function () {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            window.ext.IDTK_APP.makeCall("disableTouchLayer", "WebView");
        }
    };

    /**
     * Enables the touch events in the WebView environment.
     * @function
     */
    CocoonJS.App.enableTouchInTheWebView = function () {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            window.ext.IDTK_APP.makeCall("enableTouchLayer", "WebView");
        }
    };

    /**
     * Setups the update interval in seconds (1 second / X frames) to receive the accelerometer updates.
     * It defines the rate at which the devicemotion events are updated.
     * @function
     * @param {number} updateIntervalInSeconds The update interval in seconds to be set.
     */
    CocoonJS.App.setAccelerometerUpdateIntervalInSeconds = function (updateIntervalInSeconds) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return window.ext.IDTK_APP.makeCall("setAccelerometerUpdateIntervalInSeconds", updateIntervalInSeconds);
        }
    };

    /**
     * Returns the update interval in seconds that is currently set for accelerometer related events.
     * @function
     * @return {number} The update interval in seconds that is currently set for accelerometer related events.
     */
    CocoonJS.App.getAccelerometerUpdateIntervalInSeconds = function () {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return window.ext.IDTK_APP.makeCall("getAccelerometerUpdateIntervalInSeconds");
        }
    };

    /**
     * Setups the update interval in seconds (1 second / X frames) to receive the gyroscope updates.
     * It defines the rate at which the devicemotion and deviceorientation events are updated.
     * @function
     * @param {number} updateIntervalInSeconds The update interval in seconds to be set.
     */
    CocoonJS.App.setGyroscopeUpdateIntervalInSeconds = function (updateIntervalInSeconds) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return window.ext.IDTK_APP.makeCall("setGyroscopeUpdateIntervalInSeconds", updateIntervalInSeconds);
        }
    };

    /**
     * Returns the update interval in seconds that is currently set for gyroscope related events.
     * @function
     * @return {number} The update interval in seconds that is currently set for gyroscope related events.
     */
    CocoonJS.App.getGyroscopeUpdateIntervalInSeconds = function () {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            window.ext.IDTK_APP.makeCall("getGyroscopeUpdateIntervalInSeconds");
        }
    };


    /**
     * Setups a origin proxy for a given typeName. What this means is that after calling this function the environment that makes this call will suddenly
     * have a way of creating instances of the given typeName and those instances will act as a transparent proxy to counterpart instances in the destination environment.
     * Manipulating attributes, calling funcitions or handling events will all be performed in the destination environment but the developer will think they will be
     * happening in the origin environment.
     * IMPORTANT NOTE: These proxies only work with types that use attributes and function parameters and return types that are primitive like numbers, strings or arrays.
     * @param {string} typeName The name of the type to be proxified.
     * @param {array} [attributeNames] A list of the names of the attributes to be proxified.
     * @param {array} [functionNames] A list of the names of the functions to be proxified.
     * @param {array} [eventHandlerNames] A list of the names of the event handlers to be proxified (onXXXX like attributes that represent callbacks).
     * A valid typeName and at least one valid array for attribute, function or event handler names is mandatory.
     */
    CocoonJS.App.setupOriginProxyType = function (typeName, attributeNames, functionNames, eventHandlerNames) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            // Control the parameters.
            if (!typeName) throw "The given typeName must be valid.";
            if (!attributeNames && !functionNames && !eventHandlerNames) throw "There is no point on setting up a proxy for no attributes, functions nor eventHandlers.";
            attributeNames = attributeNames ? attributeNames : [];
            functionNames = functionNames ? functionNames : [];
            eventHandlerNames = eventHandlerNames ? eventHandlerNames : [];

            // The parent object will be the window. It could be another object but careful, the destination side should know about this.
            // TODO: Specify the parentObject as a parameter, obtain it's path from the window object and pass it to the destination environment so it knows about it.
            var parentObject = window;

            // Setup the destination side too.
            var jsCode = "CocoonJS.App.setupDestinationProxyType(" + JSON.stringify(typeName) + ", " + JSON.stringify(eventHandlerNames) + ");";
            CocoonJS.App.forward(jsCode);

            var originalType = parentObject[typeName];

            // Constructor. This will be the new proxified type in the origin environment. Instances of this type will be created by the developer without knowing that they are
            // internally calling to their counterparts in the destination environment.
            parentObject[typeName] = function () {
                var _this = this;

                // Each proxy object will have a origin object inside with all the necessary information to be a proxy to the destination.
                this._cocoonjs_proxy_object_data = {};
                // The id is obtained calling to the destination side to create an instance of the type.
                var jsCode = "CocoonJS.App.newDestinationProxyObject(" + JSON.stringify(typeName) + ");";
                this._cocoonjs_proxy_object_data.id = CocoonJS.App.forward(jsCode);
                // The eventHandlers dictionary contains objects of the type { eventHandlerName : string, eventHandler : function } to be able to make the callbacks when the 
                // webview makes the corresponding calls.
                this._cocoonjs_proxy_object_data.eventHandlers = {};
                // Also store the typename inside each instance.
                this._cocoonjs_proxy_object_data.typeName = typeName;
                // A dictionary to store the event handlers
                this._cocoonjs_proxy_object_data.eventListeners = {};

                // TODO: eventHandlers and eventListeners should be in the same list ;)

                // Store all the proxy instances in a list that belongs to the type itself.
                parentObject[typeName]._cocoonjs_proxy_type_data.proxyObjects[this._cocoonjs_proxy_object_data.id] = this;

                // Create a setter and a getter for all the attribute names that have been specified. When the attributes are accessed (set or get) a call to the destination counterpart will be performed.
                for (var i = 0; i < attributeNames.length; i++) {
                    (function (attributeName) {
                        _this.__defineSetter__(attributeName, function (value) {
                            var jsCode = "CocoonJS.App.setDestinationProxyObjectAttribute(" + JSON.stringify(typeName) + ", " + _this._cocoonjs_proxy_object_data.id + ", " + JSON.stringify(attributeName) + ", " + JSON.stringify(value) + ");";
                            return CocoonJS.App.forwardAsync(jsCode);
                        });
                        _this.__defineGetter__(attributeName, function () {
                            var jsCode = "CocoonJS.App.getDestinationProxyObjectAttribute(" + JSON.stringify(typeName) + ", " + _this._cocoonjs_proxy_object_data.id + ", " + JSON.stringify(attributeName) + ");";
                            return CocoonJS.App.forwardAsync(jsCode);
                        });
                    })(attributeNames[i]);
                }

                // Create a function that performs a call to the destination environment counterpart for all the function names that have been specified.
                for (var i = 0; i < functionNames.length; i++) {
                    (function (functionName) {
                        _this[functionName] = function () {
                            // Get the arguments as an array and add the typeName, the proxy id and the functionName before all the other arguments before making the call to the destination counterpart.
                            var argumentsArray = Array.prototype.slice.call(arguments);
                            argumentsArray.unshift(functionName);
                            argumentsArray.unshift(this._cocoonjs_proxy_object_data.id);
                            argumentsArray.unshift(typeName);
                            // Use the array to create the correct function call.
                            var jsCode = "CocoonJS.App.callDestinationProxyObjectFunction(";
                            for (var i = 0; i < argumentsArray.length; i++) {
                                // The second argument (the id) should not be stringified
                                jsCode += (i !== 1 ? JSON.stringify(argumentsArray[i]) : argumentsArray[i]) + (i < argumentsArray.length - 1 ? ", " : "");
                            }
                            jsCode += ");";
                            // TODO: This next call should be synchronous but it seems that some customers are experiencing some crash issues. Making it async solves these crashes.
                            // Another possible solution could be to be able to specify which calls could be async and which sync in the proxification array.
                            var ret = CocoonJS.App.forwardAsync(jsCode);
                            return ret;
                        };
                    })(functionNames[i]);
                }

                // Create a setter and getter for all the event handler names that have been specified. When the event handlers are accessed, store them inside the corresponding position on the eventHandlers
                // array so they can be called when the destination environment makes the corresponding callback call.
                for (var i = 0; i < eventHandlerNames.length; i++) {
                    (function (eventHandlerName) {
                        _this.__defineSetter__(eventHandlerName, function (value) {
                            _this._cocoonjs_proxy_object_data.eventHandlers[eventHandlerName] = value;
                        });
                        _this.__defineGetter__(eventHandlerName, function () {
                            return _this._cocoonjs_proxy_object_data.eventHandlers[eventHandlerName];
                        });
                    })(eventHandlerNames[i]);
                }

                // Setup the add and remove event listeners in the proxy object
                _this.addEventListener = function (eventTypeName, eventCallback) {
                    var addEventCallback = true;
                    // Check for the eventListeners
                    var eventListeners = _this._cocoonjs_proxy_object_data.eventListeners[eventTypeName];
                    if (eventListeners) {
                        // As the eventListeners were already added, check that the same callback has not been added.
                        addEventCallback = eventListeners.indexOf(eventCallback) < 0;
                    }
                    else {
                        // There are no event listeners, so add the one and add the listeners array for the specific event type name
                        eventListeners = [];
                        _this._cocoonjs_proxy_object_data.eventListeners[eventTypeName] = eventListeners;

                        // Forward the call so the other end registers a event listener (only one is needed).
                        var jsCode = "CocoonJS.App.addDestinationProxyObjectEventListener(" + JSON.stringify(_this._cocoonjs_proxy_object_data.typeName) + ", " + _this._cocoonjs_proxy_object_data.id + ", " + JSON.stringify(eventTypeName) + ");";
                        CocoonJS.App.forwardAsync(jsCode);
                    }
                    // Only if the alforithm above specify so, add the eventcallback and notify the destination environment to do the same
                    if (addEventCallback) {
                        eventListeners.push(eventCallback);
                    }
                };

                _this.removeEventListener = function (eventTypeName, eventCallback) {
                    // Check for the eventListeners
                    var eventListeners = _this._cocoonjs_proxy_object_data.eventListeners[eventTypeName];
                    if (eventListeners) {
                        var eventCallbackIndex = eventListeners.indexOf(eventCallback);
                        if (eventCallbackIndex >= 0) {
                            eventListeners.splice(eventCallbackIndex, 1);
                        }
                    }
                };

                // Return the proxy instance.
                return this;
            };

            // The type will contain a proxy data structure to store all the instances that are created so they are available when the destination environment calls back. 
            parentObject[typeName]._cocoonjs_proxy_type_data =
            {
                originalType:originalType,
                proxyObjects:[]
            };

            /**
             * Deletes a proxy instance from both the CocoonJS environment structures and also deleting it's webview environment counterpart.
             * This function should be manually called whenever a proxy instance won't be accessed anymore.
             * @param {object} object The proxy object to be deleted.
             */
            parentObject[typeName]._cocoonjs_proxy_type_data.deleteProxyObject = function (object) {
                var proxyObjectKey = CocoonJS.getKeyForValueInDictionary(this.proxyObjects, object);
                if (proxyObjectKey) {
                    var jsCode = "CocoonJS.App.deleteDestinationProxyObject(" + JSON.stringify(typeName) + ", " + object._cocoonjs_proxy_object_data.id + ");";
                    CocoonJS.App.forwardAsync(jsCode);
                    object._cocoonjs_proxy_object_data = null;
                    delete this.proxyObjects[proxyObjectKey];
                }
            };

            /**
             * Calls a event handler for the given proxy object id and eventHandlerName.
             * @param {number} id The id to be used to look for the proxy object for which to make the call to it's event handler.
             * @param {string} eventHandlerName The name of the handler to be called.
             * NOTE: Events are a complex thing in the HTML specification. This function just performs a call but at least provides a
             * structure to the event passing the target (the proxy object).
             * TODO: The destination should serialize the event object as far as it can so many parameters can be passed to the origin
             * side. Using JSON.stringify in the destination side and parse in origin side maybe? Still must add the target to the event structure though.
             */
            parentObject[typeName]._cocoonjs_proxy_type_data.callProxyObjectEventHandler = function (id, eventHandlerName) {
                var object = this.proxyObjects[id];
                var eventHandler = object._cocoonjs_proxy_object_data.eventHandlers[eventHandlerName];
                if (eventHandler) {
                    eventHandler({ target:object });
                }
            };

            parentObject[typeName]._cocoonjs_proxy_type_data.callProxyObjectEventListeners = function (id, eventTypeName) {
                var object = this.proxyObjects[id];
                var eventListeners = object._cocoonjs_proxy_object_data.eventListeners[eventTypeName].slice();
                for (var i = 0; i < eventListeners.length; i++) {
                    eventListeners[i]({ target:object });
                }
            };
        }
    };

    /**
     * Takes down the proxification of a type and restores it to it's original type. Do not worry if you pass a type name that is not proxified yet. The
     * function will handle it correctly for compativility reasons.
     * @param {string} typeName The name of the type to be deproxified (take down the proxification and restore the type to it's original state)
     */
    CocoonJS.App.takedownOriginProxyType = function (typeName) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            var parentObject = window;
            if (parentObject[typeName] && parentObject[typeName]._cocoonjs_proxy_type_data) {
                parentObject[typeName] = parentObject[typeName]._cocoonjs_proxy_type_data.originalType;
            }
        }
    };

    /**
     * Deletes everything related to a proxy object in both environments. Do not worry of you do not pass a proxified object to the
     * function. For compatibility reasons, you can still have calls to this function even when no poxification of a type has been done.
     * @param {object} object The proxified object to be deleted.
     */
    CocoonJS.App.deleteOriginProxyObject = function (object) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            var parentObject = window;
            if (object && object._cocoonjs_proxy_object_data) {
                parentObject[object._cocoonjs_proxy_object_data.typeName]._cocoonjs_proxy_type_data.deleteProxyObject(object);
            }
        }
    };

    /**
     * NOTE: This function should never be directly called. It will be called from the destination environment whenever it is needed to work with proxy objects.
     * It calls the origin proxy object when an event handler need to be updated/called from the destination environment.
     * @param {string} typeName The type name of the proxified type.
     * @param {number} id The id of the proxy object.
     * @param {string} eventHandlerName The name of the event handler to be called.
     */
    CocoonJS.App.callOriginProxyObjectEventHandler = function (typeName, id, eventHandlerName) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            var parentObject = window;
            parentObject[typeName]._cocoonjs_proxy_type_data.callProxyObjectEventHandler(id, eventHandlerName);
        }
    };

    /**
     * NOTE: This function should never be directly called. It will be called from the destination environment whenever it is needed to work with proxy objects.
     * It calls the origin proxy object when all the event listeners related to a specific event need to be updated/called from the destination environment.
     * @param {string} typeName The type name of the proxified type.
     * @param {number} id The id of the proxy object.
     * @param {string} eventTypeName The name of the event type to call the listeners related to it.
     */
    CocoonJS.App.callOriginProxyObjectEventListeners = function (typeName, id, eventTypeName) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            var parentObject = window;
            parentObject[typeName]._cocoonjs_proxy_type_data.callProxyObjectEventListeners(id, eventTypeName);
        }
    };

    /**
     * NOTE: This function should never be directly called. It will be called from the origin environment whenever it is needed to work with proxy objects.
     * Setups all the structures that are needed to proxify a destination type to an origin type.
     * @param {string} typeName The name of the type to be proxified.
     * @param {array} eventHandlerNames An array with al the event handlers to be proxified. Needed in order to be able to create callbacks for all the event handlers
     * and call to the CocoonJS counterparts accordingly.
     */
    CocoonJS.App.setupDestinationProxyType = function (typeName, eventHandlerNames) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            var parentObject = window;

            // Add a cocoonjs structure to the destination proxified type to store some useful information like all the proxy instances that are created, plus the id counter 
            // and the names of all the event handlers and some utility functions.
            parentObject[typeName]._cocoonjs_proxy_type_data =
            {
                nextId:0,
                proxyObjects:{},
                eventHandlerNames:eventHandlerNames
            }
        }
    };

    /**
     * NOTE: This function should never be directly called. It will be called from the origin environment whenever it is needed to work with proxy objects.
     * Takes down the proxy type at the destination environment. Just removes the data structure related to proxies that was added to the type when proxification tool place.
     * @param {string} typeName The name of the type to take the proxification down.
     */
    CocoonJS.App.takedownDestinationProxyType = function (typeName) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            var parentObject = window;
            if (parent[typeName] && parentObject[typeName]._cocoonjs_proxy_type_data) {
                delete parentObject[typeName]._cocoonjs_proxy_type_data;
            }
        }
    };

    /**
     * NOTE: This function should never be directly called. It will be called from the original environment whenever it is needed to work with proxy objects.
     * Creates a new destination object instance and generates a id to reference it from the original environment.
     * @param {string} typeName The name of the type to be proxified and to generate an instance.
     * @return The id to be used from the original environment to identify the corresponding destination object instance.
     */
    CocoonJS.App.newDestinationProxyObject = function (typeName) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            var parentObject = window;

            var proxyObject = new parentObject[typeName]();
            // Also store some additional information in the proxy object
            proxyObject._cocoonjs_proxy_object_data = {};
            // Like the type name, that could be useful late ;)
            proxyObject._cocoonjs_proxy_object_data.typeName = typeName;
            // Caculate the id for the object. It will be returned to the origin environment so this object can be referenced later
            var proxyObjectId = parentObject[typeName]._cocoonjs_proxy_type_data.nextId;
            // Store the created object in the structure defined in the setup of proxification with an id associated to it
            parentObject[typeName]._cocoonjs_proxy_type_data.proxyObjects[proxyObjectId] = proxyObject;
            // Also store the id inside the proxy object itself
            proxyObject._cocoonjs_proxy_object_data.id = proxyObjectId;
            // Calculate a new id for the next object.
            parentObject[typeName]._cocoonjs_proxy_type_data.nextId++;

            // Setup all the event handlers.
            for (var i = 0; i < parentObject[typeName]._cocoonjs_proxy_type_data.eventHandlerNames.length; i++) {
                (function (eventHandlerName) {
                    proxyObject[eventHandlerName] = function (event) {
                        var proxyObject = this; // event.target;
                        // var eventHandlerName = CocoonJS.getKeyForValueInDictionary(proxyObject, this); // Avoid closures ;)
                        var jsCode = "CocoonJS.App.callOriginProxyObjectEventHandler(" + JSON.stringify(proxyObject._cocoonjs_proxy_object_data.typeName) + ", " + proxyObject._cocoonjs_proxy_object_data.id + ", " + JSON.stringify(eventHandlerName) + ");";
                        CocoonJS.App.forwardAsync(jsCode);
                    };
                })(parentObject[typeName]._cocoonjs_proxy_type_data.eventHandlerNames[i]);
            }

            // Add the dictionary where the event listeners (callbacks) will be added.
            proxyObject._cocoonjs_proxy_object_data.eventListeners = {};

            return proxyObjectId;
        }
    };

    /**
     * NOTE: This function should never be directly called. It will be called from the origin environement whenever it is needed to work with proxy objects.
     * Calls a function of a destination object idetified by it's typeName and id.
     * @param {string} typeName The name of the type of the proxy.
     * @param {number} id The id of the proxy object.
     * @param {string} functionName The name of the function to be called.
     * @return Whatever the function call returns.
     */
    CocoonJS.App.callDestinationProxyObjectFunction = function (typeName, id, functionName) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            var parentObject = window;
            var argumentsArray = Array.prototype.slice.call(arguments);
            argumentsArray.splice(0, 3);
            var proxyObject = parentObject[typeName]._cocoonjs_proxy_type_data.proxyObjects[id];
            var result = proxyObject[functionName].apply(proxyObject, argumentsArray);
            return result;
        }
    };

    /**
     * NOTE: This function should never be directly called. It will be called from the original environment whenever it is needed to work with proxy objects.
     * Sets a value to the corresponding attributeName of a proxy object represented by it's typeName and id.
     * @param {string} typeName The name of the type of the proxy.
     * @param {number} id The id of the proxy object.
     * @param {string} attributeName The name of the attribute to be set.
     * @param {unknown} attributeValue The value to be set to the attribute.
     */
    CocoonJS.App.setDestinationProxyObjectAttribute = function (typeName, id, attributeName, attributeValue) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            var parentObject = window;
            var proxyObject = parentObject[typeName]._cocoonjs_proxy_type_data.proxyObjects[id];
            proxyObject[attributeName] = attributeValue;
        }
    };

    /**
     * NOTE: This function should never be directly called. It will be called from the original environment whenever it is needed to work with proxy objects.
     * Retrieves the value of the corresponding attributeName of a proxy object represented by it's typeName and id.
     * @param {string} typeName The name of the type of the proxy.
     * @param {number} id The id of the proxy object.
     * @param {string} attributeName The name of the attribute to be retrieved.
     */
    CocoonJS.App.getDestinationProxyObjectAttribute = function (typeName, id, attributeName) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            var parentObject = window;
            var proxyObject = parentObject[typeName]._cocoonjs_proxy_type_data.proxyObjects[id];
            return proxyObject[attributeName];
        }
    };

    /**
     * NOTE: This function should never be directly called. It will be called from the original environment whenever it is needed to work with proxy objects.
     * Deletes a proxy object identifying it using it's typeName and id. Deleting a proxy object mainly means to remove the instance from the global structure
     * that hold all the instances.
     * @param {string} typeName The name of the type of the proxy.
     * @param {number} id The id of the proxy object.
     */
    CocoonJS.App.deleteDestinationProxyObject = function (typeName, id) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            var parentObject = window;
            delete parentObject[typeName]._cocoonjs_proxy_type_data.proxyObjects[id];
        }
    };

    /**
     * NOTE: This function should never be directly called. It will be called from the original environment whenever it is needed to work with proxy objects.
     */
    CocoonJS.App.addDestinationProxyObjectEventListener = function (typeName, id, eventTypeName) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            var parentObject = window;
            // Look for the proxy object
            var proxyObject = parentObject[typeName]._cocoonjs_proxy_type_data.proxyObjects[id];

            var callback = function (event) {
                var proxyObject = this; // event.target;
                // var eventTypeName = CocoonJS.getKeyForValueInDictionary(proxyObject._cocoonjs_proxy_object_data.eventListeners, this); // Avoid closures ;)
                // TODO: Is there a way to retrieve the callbackId without a closure?
                var jsCode = "CocoonJS.App.callOriginProxyObjectEventListeners(" + JSON.stringify(proxyObject._cocoonjs_proxy_object_data.typeName) + ", " + proxyObject._cocoonjs_proxy_object_data.id + ", " + JSON.stringify(eventTypeName) + ");";
                CocoonJS.App.forwardAsync(jsCode);
            };

            proxyObject._cocoonjs_proxy_object_data.eventListeners[eventTypeName] = callback;

            // Finally add the event listener callback to the proxy object
            proxyObject.addEventListener(eventTypeName, callback);
        }
    };

    // TODO: We could add a removeDestinationProxyObjectEventListener although it seems that is not completely necessary.

    /**
     * Proxifies the XMLHttpRequest type for the environment where this call is made. After calling this function, all the new objects
     * of XMLHttpRequest that are instantiated, will be proxified objects that will make calls to the counterparts in the other environment (CocoonJS <-> WebView viceversa).
     * IMPORTANT NOTE: Remember to take down the proxification once you are done or to delete proxy objects whenever they are not needed anymore or memory leaks may occur.
     */
    CocoonJS.App.proxifyXHR = function () {
        var ATTRIBUTE_NAMES =
            [
                "timeout",
                "withCredentials",
                "upload",
                "status",
                "statusText",
                "responseType",
                "response",
                "responseText",
                "responseXML",
                "readyState"
            ];
        var FUNCTION_NAMES =
            [
                "open",
                "setRequestHeader",
                "send",
                "abort",
                "getResponseHeader",
                "getAllResponseHeaders",
                "overrideMimeType"
            ];
        var EVENT_HANDLER_NAMES =
            [
                "onloadstart",
                "onprogress",
                "onabort",
                "onerror",
                "onload",
                "ontimeout",
                "onloadend",
                "onreadystatechange"
            ];
        CocoonJS.App.setupOriginProxyType("XMLHttpRequest", ATTRIBUTE_NAMES, FUNCTION_NAMES, EVENT_HANDLER_NAMES);
    };

    /**
     * Proxifies the Audio type for the environment where this call is made. After calling this function, all the new objects
     * of Audio that are instantiated, will be proxified objects that will make calls to the counterparts in the other environment (CocoonJS <-> WebView viceversa).
     * IMPORTANT NOTE: Remember to take down the proxification once you are done or to delete proxy objects whenever they are not needed anymore or memory leaks may occur.
     */
    CocoonJS.App.proxifyAudio = function () {
        var ATTRIBUTE_NAMES =
            [
                "src",
                "loop",
                "volume",
                "preload"
            ];
        var FUNCTION_NAMES =
            [
                "play",
                "pause",
                "load",
                "canPlayType"
            ];
        var EVENT_HANDLER_NAMES =
            [
                "onended",
                "oncanplay",
                "oncanplaythrough",
                "onerror"
            ];
        CocoonJS.App.setupOriginProxyType("Audio", ATTRIBUTE_NAMES, FUNCTION_NAMES, EVENT_HANDLER_NAMES);
    };

    /**
     * Captures a image of the screen synchronously and saves it to a file. Sync mode allows to capture the screen in the middle of a frame rendering.
     * @param {string} fileName Desired file name and format (png or jpg). If no value is passed, "capture.png" value is used by default
     * @param {CocoonJS.App.StorageType} storageType The developer can specify the storage where it is stored. If no value is passed, the {@link CocoonJS.App.StorageType.TMP_STORAGE} value is used by default.
     * @param {CocoonJS.App.CaptureType} captureType. Optional value to choose capture type. [0: captures everything, 1: only captures cocoonjs surface 2: only captures system views]. @see CocoonJS.App.CaptureType
     * @return The URL of the saved file.
     * @throws exception if the image fails to be stored or there is another error.
     * @see CocoonJS.App.onCaptureScreenSucceeded
     * @see CocoonJS.App.onCaptureScreenFailed
     */
    CocoonJS.App.captureScreen = function (fileName, storageType, captureType) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return window.ext.IDTK_APP.makeCall("captureScreen", fileName, storageType, captureType);
        }
    };

    /**
     * Captures a image of the screen asynchronously and saves it to a file.
     * Async mode captures a final frame as soon as possible.
     * @param {string} Desired file name and format (png or jpg). If no value is passed, "capture.png" value is used by default
     * @param {CocoonJS.App.StorageType} [storageType] The developer can specify the storage where it is stored. If no value is passed, the {@link CocoonJS.App.StorageType.TMP_STORAGE} value is used by default.
     * @param {CocoonJS.App.CaptureType} captureType. Optional value to choose capture type. [0: captures everything, 1: only captures cocoonjs surface, 2: only captures system views]. @see CocoonJS.App.CaptureType
     * @param {function} callback. Response callback, check the error property to monitor errors. Check the 'url' property to get the URL of the saved Image
     */
    CocoonJS.App.captureScreenAsync = function (fileName, storageType, captureType, callback) {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            window.ext.IDTK_APP.makeCallAsync("captureScreen", fileName, storageType, captureType, callback);
        }
    };

    /**
     * Returns the device UUID
     * @return {string} The device UUID
     */
    CocoonJS.App.getDeviceId = function() {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return window.ext.IDTK_APP.makeCall("getDeviceId");
        }
    };

    /**
     * Structure that defines the getDeviceInfo returned information
     */
    CocoonJS.App.DeviceInfo = {

        /**
        * The operating system name (ios, android,...)
        * @type string
        */
        os: null,

        /**
        * The operating system version (4.2.2, 5.0,...)
        * @type string
        */
        version: null,

        /**
        * The operating system screen density in dpi
        * @type string
        */
        dpi: null,

        /**
        * The device manufacturer (apple, samsung, lg,...)
        * @type string
        */
        brand: null,

        /**
        * The device model (iPhone 4S, SAMSUNG-SGH-I997, SAMSUNG-SGH-I997R, etc)
        * @type string
        */
        model: null,

        /**
        * The phone IMEI
        * Android: The phone IMEI is returned or null if the device has not telepohny
        * iOS: null is returned as we cannot get the IMEI in iOS, no public API available for that yet.
        * @type string
        */
        imei: null,

        /**
        * The platform Id
        * Android: The ANDROID_ID is used.
        * iOS: The OpenUDID is used as there is no Android ANDROID_ID equivalent in iOS
        * @type string
        */
        platformId: null,

        /**
        * The Odin generated id https://code.google.com/p/odinmobile/
        * @type string
        */
        odin: null,

        /**
        * The OpenUDID generated Id https://github.com/ylechelle/OpenUDID
        * @type string
        */
        openudid: null
    };

    /**
     * Returns the device Info
     * @return {CocoonJS.App.DeviceInfo} The device Info
     */
    CocoonJS.App.getDeviceInfo = function() {
        if (CocoonJS.App.nativeExtensionObjectAvailable) {
            return window.ext.IDTK_APP.makeCall("getDeviceInfo");
        }
    };    

    /**
     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.App.onTextDialogFinished} event calls.
     * @name OnTextDialogFinishedListener
     * @function
     * @static
     * @memberOf CocoonJS.App
     * @param {string} text The text that was introduced in the text dialog when it was finished.
     */
    /**
     * This {@link CocoonJS.EventHandler} object allows listening to events called when the text dialog is finished by accepting it's content.
     * The callback function's documentation is represented by {@link CocoonJS.App.OnTextDialogFinishedListener}
     * @event
     * @static
     * @memberOf CocoonJS.App
     */
    CocoonJS.App.onTextDialogFinished = new CocoonJS.EventHandler("IDTK_APP", "App", "ontextdialogfinish");

    /**
     * This {@link CocoonJS.EventHandler} object allows listening to events called when the text dialog is finished by dismissing it's content.
     * The callback function does not receive any parameter.
     * @event
     * @static
     * @memberOf CocoonJS.App
     */
    CocoonJS.App.onTextDialogCancelled = new CocoonJS.EventHandler("IDTK_APP", "App", "ontextdialogcancel");

    /**
     * This {@link CocoonJS.EventHandler} object allows listening to events called when the text dialog is finished by accepting it's content.
     * The callback function does not receive any parameter.
     * @event
     * @static
     * @memberOf CocoonJS.App
     */
    CocoonJS.App.onMessageBoxConfirmed = new CocoonJS.EventHandler("IDTK_APP", "App", "onmessageboxconfirmed");

    /**
     * This {@link CocoonJS.EventHandler} object allows listening to events called when the text dialog is finished by dismissing it's content.
     * The callback function does not receive any parameter.
     * @event
     * @static
     * @memberOf CocoonJS.App
     */
    CocoonJS.App.onMessageBoxDenied = new CocoonJS.EventHandler("IDTK_APP", "App", "onmessageboxdenied");

    /**
     * This {@link CocoonJS.EventHandler} object allows listening to events called when the application is suspended.
     * The callback function does not receive any parameter.
     * @event
     * @static
     * @memberOf CocoonJS.App
     */
    CocoonJS.App.onSuspended = new CocoonJS.EventHandler("IDTK_APP", "App", "onsuspended");

    /**
     * This {@link CocoonJS.EventHandler} object allows listening to events called when the application is activated.
     * The callback function does not receive any parameter.
     * @event
     * @static
     * @memberOf CocoonJS.App
     */
    CocoonJS.App.onActivated = new CocoonJS.EventHandler("IDTK_APP", "App", "onactivated");

})();

//////////////////////////////////////
// COCOONJS_APP_FORCOCOONJS.JS		//
//////////////////////////////////////

(function()
{
    if (typeof window.CocoonJS === 'undefined' || window.CocoonJS === null) throw("The CocoonJS object must exist and be valid before adding more functionalities to an extension.");
    if (typeof window.CocoonJS.App === 'undefined' || window.CocoonJS.App === null) throw("The CocoonJS.App object must exist and be valid before adding more functionalities to it.");

    /**
    * This namespace represents all the basic functionalities available in the CocoonJS extension API.
    * @namespace
    */
    CocoonJS.App = CocoonJS.App ? CocoonJS.App : {};

    if (!CocoonJS.App.nativeExtensionObjectAvailable)
    {
        (function createWebView() { 
            CocoonJS.App.EmulatedWebView = document.createElement('div'); 
            CocoonJS.App.EmulatedWebView.setAttribute('id', 'CocoonJS_App_ForCocoonJS_WebViewDiv'); 
            CocoonJS.App.EmulatedWebView.style.width = 0; 
            CocoonJS.App.EmulatedWebView.style.height = 0; 
            CocoonJS.App.EmulatedWebView.style.position = "absolute"; 
            CocoonJS.App.EmulatedWebView.style.left = 0; 
            CocoonJS.App.EmulatedWebView.style.top = 0;
            CocoonJS.App.EmulatedWebView.style.backgroundColor = 'transparent';
            CocoonJS.App.EmulatedWebView.style.border = "0px solid #000"; 
            CocoonJS.App.EmulatedWebViewIFrame = document.createElement("IFRAME"); 
            CocoonJS.App.EmulatedWebViewIFrame.setAttribute('id', 'CocoonJS_App_ForCocoonJS_WebViewIFrame');
            CocoonJS.App.EmulatedWebViewIFrame.setAttribute('name', 'CocoonJS_App_ForCocoonJS_WebViewIFrame');
            CocoonJS.App.EmulatedWebViewIFrame.style.width = 0; 
            CocoonJS.App.EmulatedWebViewIFrame.style.height = 0; 
            CocoonJS.App.EmulatedWebViewIFrame.frameBorder = 0;
            CocoonJS.App.EmulatedWebViewIFrame.allowtransparency = true;
            CocoonJS.App.EmulatedWebView.appendChild(CocoonJS.App.EmulatedWebViewIFrame);
            if(!document.body)
            document.body = document.createElement("body");
            document.body.appendChild(CocoonJS.App.EmulatedWebView);
        })(); 
    }

    /**
    * Pauses the CocoonJS JavaScript execution loop.
    * @function
    * @augments CocoonJS.App
    */
    CocoonJS.App.pause = function()
    {
        if (CocoonJS.App.nativeExtensionObjectAvailable)
        {
            return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "pause", arguments);
        }
    };

    /**
    * Resumes the CocoonJS JavaScript execution loop.
    * @static
    * @function
    */
    CocoonJS.App.resume = function()
    {
        if (CocoonJS.App.nativeExtensionObjectAvailable)
        {
            return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "resume", arguments);
        }
    };

    /**
    * Loads a resource in the WebView environment from the CocoonJS environment.
    * @function
    * @param {string} path The path to the resource. It can be a remote URL or a path to a local file.
    * @param {CocoonJS.App.StorageType} [storageType] An optional parameter to specify at which storage in the device the file path is stored. By default, APP_STORAGE is used.
    * @see CocoonJS.App.load
    * @see CocoonJS.App.onLoadInTheWebViewSucceed
    * @see CocoonJS.App.onLoadInTheWebViewFailed
    */
    CocoonJS.App.loadInTheWebView = function(path, storageType)
    {
        if (CocoonJS.App.nativeExtensionObjectAvailable)
        {
            // TODO: All this code should be changed to a simple call makeNativeExtensionObjectFunctionCall when the native argument control is improved.
            var javaScriptCodeToForward = "ext.IDTK_APP.makeCall('loadPath'";
            if (typeof path !== 'undefined')
            {
                javaScriptCodeToForward += ", '" + path + "'";
                if (typeof storageType !== 'undefined')
                {
                    javaScriptCodeToForward += ", '" + storageType + "'";
                }
            }
            javaScriptCodeToForward += ");";

            return CocoonJS.App.forwardAsync(javaScriptCodeToForward);
        }
        else if (!navigator.isCocoonJS)
        {
            var xhr = new XMLHttpRequest();

            xhr.onreadystatechange = function(event) {
                if (xhr.readyState === 4)
                {
                    if (xhr.status === 200)
                    {
                        var callback= function(event){
                            CocoonJS.App.onLoadInTheWebViewSucceed.notifyEventListeners(path);
                            CocoonJS.App.EmulatedWebViewIFrame.removeEventListener("load", callback);
                        };

                        CocoonJS.App.EmulatedWebViewIFrame.addEventListener(
                            "load", 
                            callback
                        );
                        CocoonJS.App.EmulatedWebViewIFrame.contentWindow.location.href= path;
                    }
                    else if (xhr.status === 404)
                    {
                        this.onreadystatechange = null;
                        CocoonJS.App.onLoadInTheWebViewFailed.notifyEventListeners(path);
                    }
                }
            };
            xhr.open("GET", path, true);
            xhr.send();
        }
    };

    /**
     * Reloads the last loaded path in the WebView context.
     * @function
     */
    CocoonJS.App.reloadWebView = function()
    {
        if (CocoonJS.App.nativeExtensionObjectAvailable)
        {
            return CocoonJS.App.forwardAsync("ext.IDTK_APP.makeCall('reload');");
        }
        else if (!navigator.isCocoonJS)
        {
            CocoonJS.App.EmulatedWebViewIFrame.contentWindow.location.reload();
        }
    };

    /**
    * Shows the webview.
    * @function
    * @param {int} x The top lef x coordinate of the rectangle where the webview will be shown.
    * @param {int} y The top lef y coordinate of the rectangle where the webview will be shown.
    * @param {width} y The width of the rectangle where the webview will be shown.
    * @param {height} y The height of the rectangle where the webview will be shown.
    */
    CocoonJS.App.showTheWebView = function(x, y, width, height)
    {
        if (CocoonJS.App.nativeExtensionObjectAvailable)
        {
            var javaScriptCodeToForward = "ext.IDTK_APP.makeCall('show'";
            if (typeof x !== 'undefined' && typeof y !== 'undefined' && typeof width !== 'undefined' && typeof height !== 'undefined')
            {
                javaScriptCodeToForward += ", " + x + ", " + y + ", " + width + ", " + height;
            }
            javaScriptCodeToForward += ");";

            return CocoonJS.App.forwardAsync(javaScriptCodeToForward);
        }
        else if (!navigator.isCocoonJS)
        {
            CocoonJS.App.EmulatedWebViewIFrame.style.width = (width ? width : window.innerWidth)+'px';
            CocoonJS.App.EmulatedWebViewIFrame.style.height = (height ? height : window.innerHeight)+'px';
            CocoonJS.App.EmulatedWebView.style.left = (x ? x : 0)+'px';
            CocoonJS.App.EmulatedWebView.style.top = (y ? y : 0)+'px';
            CocoonJS.App.EmulatedWebView.style.width = (width ? width : window.innerWidth)+'px';
            CocoonJS.App.EmulatedWebView.style.height = (height ? height : window.innerHeight)+'px';
            CocoonJS.App.EmulatedWebView.style.display = "block";
        }
    };

    /**
    * Hides the webview.
    * @function
    */
    CocoonJS.App.hideTheWebView = function()
    {
        if (CocoonJS.App.nativeExtensionObjectAvailable)
        {
            var javaScriptCodeToForward = "ext.IDTK_APP.makeCall('hide');";
            return CocoonJS.App.forwardAsync(javaScriptCodeToForward);
        }
        else if (!navigator.isCocoonJS)
        {
            CocoonJS.App.EmulatedWebView.style.display = "none";
        }
    };

    /**
    * Marks a audio file to be used as music by the system. CocoonJS, internally, differentiates among music files and sound files.
    * Music files are usually bigger in size and longer in duration that sound files. There can only be just one music file 
    * playing at a specific given time. The developer can mark as many files as he/she wants to be treated as music. When the corresponding
    * HTML5 audio object is used, the system will automatically know how to treat the audio resource as music or as sound.
    * Note that it is not mandatory to use this function. The system automatically tries to identify if a file is suitable to be treated as music
    * or as sound by checking file size and duration thresholds. It is recommended, though, that the developer specifies him/herself what he/she considers
    * to be music.
    * @function
    * @param {string} audioFilePath The same audio file path that will be used to create HTML5 audio objects.
    */
    CocoonJS.App.markAsMusic = function(audioFilePath)
    {
        if (CocoonJS.App.nativeExtensionObjectAvailable)
        {
           return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "addForceMusic", arguments);
        }
    };

    /**
    * Activates or deactivates the antialas functionality from the CocoonJS rendering.
    * @function
    * @param {boolean} enable A flag that indicates if the antialas should be activated (true) or deactivated (false).
    */
    CocoonJS.App.setAntialias = function(enable)
    {
        if (CocoonJS.App.nativeExtensionObjectAvailable)
        {
           return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "setDefaultAntialias", arguments);
        }
    };

    /**
    * Sets a callback function that will be called whenever the system tries to finish the app.
    * The developer can specify how the system will react to the finish of the app by returning a
    * boolean value in the callback function: true means, close the app, false means that the developer
    * will handle the app close.
    * A common example of this is the back button in Android devices. When the back button is pressed, this
    * callback will be called and the system will react depending on the developers choice finishing, or not,
    * the application.
    * @function
    * @param {function} appShouldFinishCallback A function object that will be called when the system
    * determines that the app should be finished. This function must return a true or a false value
    * depending on what the developer wants: true === finish the app, false === do not close the app.
    */
    CocoonJS.App.setAppShouldFinishCallback = function(appShouldFinishCallback)
    {
        if (navigator.isCocoonJS)
        {
            window.onidtkappfinish = appShouldFinishCallback;
        }
    }

    /**
    * Sets the texture reduction options. The texture reduction is a process that allows big images to be reduced/scaled down when they are loaded.
    * Although the quality of the images may decrease, it can be very useful in low end devices or those with limited amount of memory.
    * The function sets the threshold on image size (width or height) that will be used in order to know if an image should be reduced or not.
    * It also allows to specify a list of strings to identify in which images file paths should be applied (when they meet the size threshold requirement) 
    * The developer will still think that the image is of the original size. CocoonJS handles all of the internals to be able to show the image correctly.
    * IMPORTANT NOTE: This function should be called when the application is initialized before any image is set to be loaded for obvious reasons ;).
    * and in which sould be forbid (even if they meet the threshold requirement).
    * @function
    * @param {number} sizeThreshold This parameter specifies the minimun size (either width or height) that an image should have in order to be reduced.
    * @param {string or array} [applyTo] This parameter can either be a string or an array of strings. It's purpose is to specify one (the string) or more (the array) substring(s) 
    * that will be compared against the file path of an image to be loaded in order to know if the reduction should be applied or not. If the image meets the
    * threshold size requirement and it's file path contains this string (or strings), it will be reduced. This parameter can also be null.
    * @param {string or array} [forbidFor] This parameter can either be a string or an array of strings. It's purpose is to specify one (the string) or more (the array) substring(s) 
    * that will be compared against the file path of an image to be loaded in order to know if the reduction should be applied or not. If the image meets the
    * threshold size requirement and it's file path contains this string (or strings), it won't be reduced. This parameter should be used in order to mantain the 
    * quality of some images even they meet the size threshold requirement.
    */
    CocoonJS.App.setTextureReduction = function(sizeThreshold, applyTo, forbidFor)
    {
        if (CocoonJS.App.nativeExtensionObjectAvailable)
        {
            CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "setDefaultTextureReducerThreshold", arguments);
        }
    };


    /**
    * Prints to the console the memory usage of the currently alive textures
    * @function
    */
    CocoonJS.App.logMemoryInfo = function()
    {
        if (CocoonJS.App.nativeExtensionObjectAvailable)
        {
            return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_APP", "logMemoryInfo", arguments);
        }
    };

    /**
    * Enable CocoonJS Webview FPS overlay.
    * @function
    */
    CocoonJS.App.enableFPSInTheWebView = function(fpsLayout, textColor)
    {
        if (!CocoonJS.App.fpsInTheWebViewEnabled)
        {
            fpsLayout = fpsLayout ? fpsLayout : CocoonJS.App.FPSLayout.TOP_RIGHT;
            textColor = textColor ? textColor : "white";
            var jsCode = "" +
                "(function()" +
                "{" +
                    "var COCOONJS_WEBVIEW_EXTENSION_SCRIPT_FILES = ['js/CocoonJSExtensions/CocoonJS.js', 'js/CocoonJSExtensions/CocoonJS_App.js', 'js/CocoonJSExtensions/CocoonJS_App_ForWebView.js'];" +
                    "var loadedScriptCounter = 0;" + 
                    "var loadedScriptFunction = function() " +
                    "{ " +
                        "loadedScriptCounter++;"+
                        "if (loadedScriptCounter >= COCOONJS_WEBVIEW_EXTENSION_SCRIPT_FILES.length)"+
                        "{"+
                            "CocoonJS.App.enableFPS(" + JSON.stringify(fpsLayout) + ", " + JSON.stringify(textColor) + ");"+
                        "}"+
                    "};"+
                    "for (var i = 0; i < COCOONJS_WEBVIEW_EXTENSION_SCRIPT_FILES.length; i++)"+
                    "{"+
                        "var s = document.createElement('script');"+
                        "s.onload = loadedScriptFunction;"+
                        "s.src = COCOONJS_WEBVIEW_EXTENSION_SCRIPT_FILES[i];"+
                        "document.body.appendChild(s);"+
                    "}" +
                "})();";
            setTimeout(function()
            {
                CocoonJS.App.forward(jsCode);
            }, 3000);
            CocoonJS.App.fpsInTheWebViewEnabled = true;
        }
    };

    /**
    * Disable CocoonJS Webview FPS overlay.
    * @function
    */
    CocoonJS.App.disableFPSInTheWebView = function()
    {
        // TODO: Implement this function.
    };

    /**
     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.App.onLoadInTheWebViewSucceed} event calls.
     * @name OnLoadInTheWebViewSucceedListener
     * @function
     * @static
     * @memberOf CocoonJS.App
     * @param {string} pageURL The URL of the page that had been loaded in the webview.
     */
    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the WebView load has completed successfully.
    * The callback function's documentation is represented by {@link CocoonJS.App.OnLoadInTheWebViewSucceedListener}
    * @event
    * @static
    * @memberOf CocoonJS.App
    * @param {string} pageURL A string that represents the page URL loaded.
    */
    CocoonJS.App.onLoadInTheWebViewSucceed = new CocoonJS.EventHandler("IDTK_APP", "App", "forwardpageload");

    /**
     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.App.onLoadInTheWebViewFailed} event calls.
     * @name OnLoadInTheWebViewFailedListener
     * @function
     * @static
     * @memberOf CocoonJS.App
     * @param {string} pageURL The URL of the page that had been loaded in the webview.
     */
    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the WebView load fails.
    * The callback function's documentation is represented by {@link CocoonJS.App.OnLoadInTheWebViewFailedListener}
    * @event
    * @static
    * @memberOf CocoonJS.App
    */
    CocoonJS.App.onLoadInTheWebViewFailed = new CocoonJS.EventHandler("IDTK_APP", "App", "forwardpagefail");
    
})();

//////////////////////////////////////
// COCOONJS_AD.JS                   //
//////////////////////////////////////

(function()
{
    // The CocoonJS must exist before creating the extension.
    if (typeof window.CocoonJS === 'undefined' || window.CocoonJS === null) throw("The CocoonJS object must exist and be valid before creating any extension object.");

    /**
    * This namespace represents the CocoonJS Advertisement extension API.
    * @namespace
    */
    CocoonJS.Ad = {};

    CocoonJS.Ad.nativeExtensionObjectAvailable = CocoonJS.nativeExtensionObjectAvailable && typeof window.ext.IDTK_SRV_AD !== 'undefined';

    /**
    * The predefined possible layouts for a banner ad.
    * @namespace 
    */
	CocoonJS.Ad.BannerLayout = 
	{
		/**
		* Specifies that the banner must be shown in the top of the screen and vertically centered.
		*/
	    TOP_CENTER      : "TOP_CENTER",

		/**
		* Specifies that the banner must be shown in the bottom of the screen and vertically centered.
		*/
	    BOTTOM_CENTER   : "BOTTOM_CENTER"
	};

	/**
    * A rectangle object that contains the banner dimensions
    * @namespace 
    * @constructor
    * @param {int} x The top lef x coordinate of the rectangle.
    * @param {int} y The top lef y coordinate of the rectangle.
    * @param {width} y The rectangle width.
    * @param {height} y The rectangle height.
    */
	CocoonJS.Ad.Rectangle = function(x, y, width, height) 
	{
		/**
		* The top lef x coordinate of the rectangle 
		* @field 
		* @type {int}
		*/
	    this.x = x;

		/**
		* The top lef y coordinate of the rectangle 
		* @field 
		* @type {int}
		*/
	    this.y = y;

	    /**
		* The rectangle width
		* @field 
		* @type {int}
		*/
	    this.width = width;

	    /**
		* The rectangle height
		* @field 
		* @type {int}
		*/
	    this.height = height;
	};

	CocoonJS.Ad.Banner = function(id)
	{
		if (typeof id !== 'number') throw "The given ad ID is not a number.";

		this.id = id;
		var me = this;

		/**
    	* This {@link CocoonJS.EventHandler} object allows listening to events called when a banner is shown.
    	* The callback function does not receive any parameter.
    	* @static
    	* @event
    	*/
		this.onBannerShown = new CocoonJS.EventHandler("IDTK_SRV_AD", "Ad", "onbannershow", function(sourceListener, args)
    	{
    		if (me.id === args[0]) 
    		{
    			sourceListener();
    		}
    	});

    	/**
    	* This {@link CocoonJS.EventHandler} object allows listening to events called when a banner is hidden.
    	* The callback function does not receive any parameter.
    	* @static
    	* @event
    	*/
		this.onBannerHidden = new CocoonJS.EventHandler("IDTK_SRV_AD", "Ad", "onbannerhide", function(sourceListener, args)
    	{
    		if (me.id === args[0]) 
    		{
    			sourceListener();
    		}
    	});

    	/**
    	* This {@link CocoonJS.EventHandler} object allows listening to events called when a banner is ready (cached).
    	* The callback function does not receive any parameter.
    	* @param {number} width The banner width
    	* @param {number} height The banner height
    	* @static
    	* @event
    	*/
		this.onBannerReady = new CocoonJS.EventHandler("IDTK_SRV_AD", "Ad", "onbannerready", function(sourceListener, args)
    	{
    		if (me.id === args[0]) 
    		{
    			sourceListener(args[1], args[2]);
    		}
    	});
	};

	CocoonJS.Ad.Banner.prototype = {

		/**
		* Shows a banner ad if available.
		* @function
		*/
		showBanner : function()
		{
			if (CocoonJS.Ad.nativeExtensionObjectAvailable)
			{
				CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "showBanner", [this.id], true);
			}
		},

		/**
		* Hides the banner ad if it was being shown.
		* @function
		*/
		hideBanner : function()
		{
			if (CocoonJS.Ad.nativeExtensionObjectAvailable)
			{
				CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "hideBanner", [this.id], true);
			}
		},

		/**
		* Refreshes the banner.
		* @function
		*/
		refreshBanner : function()
		{
			if (CocoonJS.Ad.nativeExtensionObjectAvailable)
			{
				CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "refreshBanner", [this.id], true);
			}
		},

		/**
		* Gets the rectangle representing the banner screen position.
		* @function
		* @return {CocoonJS.Ad.Rectangle} rectangle The rectangle representing the banner position and domensions.
		*/
		getRectangle : function()
		{
			if (CocoonJS.Ad.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "getRectangle", [this.id]);
			}
		},

		/**
		* Sets the rectangle where the banner ad is going to be shown.
		* @function
		* @param {CocoonJS.Ad.Rectangle} rect The rectangle representing the banner position and domensions.
		*/
		setRectangle : function(rect)
		{
			if (CocoonJS.Ad.nativeExtensionObjectAvailable)
			{
				CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "setRectangle", [this.id, rect],true);
			}
		},

		/**
		* Sets the rectangle where the banner ad is going to be shown.
		* You can use this method if you want to have better control of the banner screen positioning.
		* @function
		* @param {CocoonJS.Ad.BannerLayout} bannerLayout The layout where the bannerwill be placed.
		*/
		setBannerLayout : function(bannerLayout)
		{
			if (CocoonJS.Ad.nativeExtensionObjectAvailable)
			{
				CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "setBannerLayout", [this.id, bannerLayout],true);
			}
		}
	};

	CocoonJS.Ad.Fullscreen = function(id)
	{
		if (typeof id !== 'number') throw "The given ad ID is not a number.";

		this.id = id;
		var me = this;

		/**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when a full screen ad is shown.
	    * The callback function does not receive any parameter.
	    * @static
	    * @event
	    */
		this.onFullScreenShown = new CocoonJS.EventHandler("IDTK_SRV_AD", "Ad", "onfullscreenshow", function(sourceListener, args)
    	{
    		if (me.id === args[0]) {
    			sourceListener();
    		}
    	});

		/**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when a full screen ad is hidden.
	    * The callback function does not receive any parameter.
	    * @static
	    * @event
	    */
    	this.onFullScreenHidden = new CocoonJS.EventHandler("IDTK_SRV_AD", "Ad", "onfullscreenhide", function(sourceListener, args)
    	{
    		if (me.id === args[0]) {
    			sourceListener();
    		}
    	});

    	/**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when a full screen ad is ready (cached).
	    * The callback function does not receive any parameter.
	    * @static
	    * @event
	    */
    	this.onFullScreenReady = new CocoonJS.EventHandler("IDTK_SRV_AD", "Ad", "onfullscreenready", function(sourceListener, args)
    	{
    		if (me.id === args[0]) {
    			sourceListener();
    		}
    	});
	};

	CocoonJS.Ad.Fullscreen.prototype = {

		/**
		* Shows a full screen ad if available.
		* @function
		* @see CocoonJS.Ad.onFullScreenShown
		* @see CocoonJS.Ad.onFullScreenHidden
		*/
		showFullScreen : function()
		{
			if (CocoonJS.Ad.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "showFullScreen", [this.id], true);
			}
		},

		/**
		* Refreshes the fullscreen.
		* @function
		*/
		refreshFullScreen : function()
		{
			if (CocoonJS.Ad.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "refreshFullScreen", [this.id], true);
			}
		}
	};

	/**
	* Initialize the service with service level initialization parameters.
	* @function
	* @param {object} An object with the required initialization parameters for the service.
	*/
	CocoonJS.Ad.requestInitialization = function(parameters)
	{
        if (typeof parameters === "undefined") {
            parameters = {};
        }

		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "requestInitialization", arguments, true);
		}
	};

	/**
	* Creates a new banner ad.
	* @function
	* @param {object} An object containing the properties the ad will need for its initialization.
	*/
	CocoonJS.Ad.createBanner = function(parameters)
	{
		if (typeof parameters === "undefined") {
            parameters = {};
        }

		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			var adId = CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "createBanner", [parameters]);
			var banner = new CocoonJS.Ad.Banner(adId);

			return banner;
		}
	};

	/**
	* Releases a banner.
	* @function
	* @param {object} The banner ad object to be released.
	*/
	CocoonJS.Ad.releaseBanner = function(banner)
	{
		if (typeof banner === "undefined") {
            throw "The banner ad object to be released is undefined"
        }

		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "releaseBanner", [banner.id]);
		}
	};

	/**
	* Creates a new fullscreen ad.
	* @function
	* @param {object} An object containing the properties the ad will need for its initialization.
	*/
	CocoonJS.Ad.createFullscreen = function(parameters)
	{
		if (typeof parameters === "undefined") {
            parameters = {};
        }

		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			var adId = CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "createFullscreen", [parameters]);
			var fullscreen = new CocoonJS.Ad.Fullscreen(adId);

			return fullscreen;
		}
	};

	/**
	* Releases a fullscreen ad.
	* @function
	* @param {object} The fullscreen ad object to be released.
	*/
	CocoonJS.Ad.releaseFullscreen = function(fullscreen)
	{
		if (typeof fullscreen === "undefined") {
            throw "The fullscreen ad object to be released is undefined"
        }

		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "releaseFullscreen", [fullscreen.id]);
		}
	};

	/**
	* Shows a banner ad if available.
	* @function
	* @see CocoonJS.Ad.setBannerLayout
	* @see CocoonJS.Ad.onBannerShown
	*/
	CocoonJS.Ad.showBanner = function()
	{
		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "showBanner", arguments, true);
		}
	};

	/**
	* Hides the banner ad if it was being shown.
	* @function
	*/
	CocoonJS.Ad.hideBanner = function()
	{
		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "hideBanner", arguments, true);
		}
	};

	/**
	* Refreshes the banner.
	* @function
	*/
	CocoonJS.Ad.refreshBanner = function()
	{
		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "refreshBanner", arguments, true);
		}
	};

	/**
	* Shows a full screen ad if available.
	* @function
	* @see CocoonJS.Ad.onFullScreenShown
	* @see CocoonJS.Ad.onFullScreenHidden
	*/
	CocoonJS.Ad.showFullScreen = function()
	{
		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "showFullScreen", arguments, true);
		}
	};

	/**
	* Refreshes the fullscreen.
	* @function
	*/
	CocoonJS.Ad.refreshFullScreen = function()
	{
		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "refreshFullScreen", arguments, true);
		}
	};

	/**
	* Makes a request to preload a banner ad.
	* @function
	*/
	CocoonJS.Ad.preloadBanner = function()
	{
		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "preloadBanner", arguments, true);
		}
	};

	/**
	* Makes a request to preload a full screen ad.
	* @function
	*/
	CocoonJS.Ad.preloadFullScreen = function()
	{
		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "preloadFullScreen", arguments, true);
		}
	};

	/**
	* Sets the rectangle where the banner ad is going to be shown.
	* @function
	* @param {CocoonJS.Ad.Rectangle} rect The rectangle representing the banner position and domensions.
	*/
	CocoonJS.Ad.setRectangle = function()
	{
		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "setRectangle", arguments, true);
		}
	};

	/**
	* Gets the rectangle representing the banner screen position.
	* @function
	* @return {CocoonJS.Ad.Rectangle} rectangle The rectangle representing the banner position and domensions.
	*/
	CocoonJS.Ad.getRectangle = function()
	{
		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "getRectangle", arguments);
		}
	};

	/**
	* Sets the rectangle where the banner ad is going to be shown.
	* You can use this method if you want to have better control of the banner screen positioning.
	* @function
	* @param {CocoonJS.Ad.BannerLayout} bannerLayout The layout where the bannerwill be placed.
	*/
	CocoonJS.Ad.setBannerLayout = function(bannerLayout)
	{
		if (CocoonJS.Ad.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_AD", "setBannerLayout", arguments, true);
		}
	};

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when a banner is shown.
    * The callback function does not receive any parameter.
    * @static
    * @event
    */
	CocoonJS.Ad.onBannerShown = new CocoonJS.EventHandler("IDTK_SRV_AD", "Ad", "onbannershow");

	/**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when a banner is hidden.
    * The callback function does not receive any parameter.
    * @static
    * @event
    */
	CocoonJS.Ad.onBannerHidden = new CocoonJS.EventHandler("IDTK_SRV_AD", "Ad", "onbannerhide"); 

	/**
	* This {@link CocoonJS.EventHandler} object allows listening to events called when a banner is ready (cached).
	* The callback function does not receive any parameter.
	* @param {number} width The banner width
	* @param {number} height The banner height
	* @static
	* @event
	*/
	CocoonJS.Ad.onBannerReady = new CocoonJS.EventHandler("IDTK_SRV_AD", "Ad", "onbannerready"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when a full screen ad is shown.
    * The callback function does not receive any parameter.
    * @static
    * @event
    */
	CocoonJS.Ad.onFullScreenShown = new CocoonJS.EventHandler("IDTK_SRV_AD", "Ad", "onfullscreenshow"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when a full screen ad is hidden.
    * The callback function does not receive any parameter.
    * @static
    * @event
    */
	CocoonJS.Ad.onFullScreenHidden = new CocoonJS.EventHandler("IDTK_SRV_AD", "Ad", "onfullscreenhide");

	/**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when a full screen ad is ready (cached).
    * The callback function does not receive any parameter.
    * @static
    * @event
    */
	CocoonJS.Ad.onFullScreenReady = new CocoonJS.EventHandler("IDTK_SRV_AD", "Ad", "onfullscreenready"); 

})();

//////////////////////////////////////
// COCOONJS_STORE.JS                //
//////////////////////////////////////

(function()
{
    // The CocoonJS must exist before creating the extension.
    if (typeof window.CocoonJS === 'undefined' || window.CocoonJS === null) throw("The CocoonJS object must exist and be valid before creating any extension object.");

    /**
    * This namespace represents the CocoonJS In-App Purchase extension.
    * @namespace
    */
    CocoonJS.Store = {};

    CocoonJS.Store.nativeExtensionObjectAvailable = CocoonJS.nativeExtensionObjectAvailable && typeof window.ext.IDTK_SRV_STORE !== 'undefined';

	/**
	* The data structure that represents the information of a product in the store.
	* @namespace
	* @constructor
	* @param {string} The id of the product.
	* @param {string} The alias of the product.
	* @param {CocoonJS.Store.ProductType} The product type @see CocoonJS.Store.ProductType.
	* @param {string} The title of the product.
	* @param {string} The description of the product.
	* @param {string} The localized price of the product.
	* @param {string} The URL of the asset to be downloaded for this purchase.
	*/
	CocoonJS.Store.ProductInfo = function(productAlias, productId, productType, title, description, price, localizedPrice, downloadURL)
	{
		/**
		* The id of the product.
		* @field
		* @type string
		*/
		this.productId = productId;

		/**
		* The alias of the product.
		* @field
		* @type string
		*/
		this.productAlias = productAlias;

		/**
		* The product type @see CocoonJS.Store.ProductType
		* @field
		* @type CocoonJS.Store.ProductType
		*/
		this.productType = productType;

		/**
		* The title of the product.
		* @field
		* @type string
		*/
		this.title = title;

		/**
		* The description of the product.
		* @field
		* @type string
		*/
		this.description = description;

		/**
		* The price of the product.
		* @field
		* @type string
		*/
		this.price = price;

		/**
		* The localized price of the product.
		* @field
		* @type string
		*/
		this.localizedPrice = localizedPrice;

		/**
		* The URL of the asset to be downloaded for this purchase.
		* @field
		* @type string
		*/
		this.downloadURL = downloadURL;

		return this;
	};

	/**
    * The predefined possible states of a purchase.
    * @namespace 
    */
	CocoonJS.Store.ProductType = 
	{
		/**
		* A consumable product. See platform documentation for further information.
		*/
	    CONSUMABLE : 0,

		/**
		* A non-cunsumable product. . See platform documentation for further information.
		*/
	    NON_CONSUMABLE : 1,

	    /**
		* An auto-renewable subscription. See platform documentation for further information.
		*/
	    AUTO_RENEWABLE_SUBSCRIPTION : 2,

	    /**
		* A free subscription. See platform documentation for further information.
		*/
	    FREE_SUBSCRIPTION : 3,

	    /**
		* A non-renewable subscription. See platform documentation for further information.
		*/
	    NON_RENEWABLE_SUBSCRIPTION : 4
	};

	/**
    * The predefined possible store types.
    * @namespace 
    */
	CocoonJS.Store.StoreType = 
	{
		/**
		* Apple AppStore
		*/
	    APP_STORE : 0,

	    /**
	    * Android Play Store
	    */
	    PLAY_STORE : 1,

		/**
		* Mock Store
		*/
		MOCK_STORE : 2,

		/**
	    * Amazon AppStore
	    */
	    CHROME_STORE : 3,

	    /**
	    * Amazon AppStore
	    */
	    AMAZON_STORE : 4,

	    /**
	    * Nook Store
	    */
	    NOOK_STORE : 5
	};

	/**
	* The data structure that represents the information of a purchase.
	* @namespace
	* @constructor
	* @param {string} The transaction id of a purchase.
	* @param {string} The time when the purchase was done in seconds since 1970.
	* @param {CocoonJS.Store.PurchaseState} The state of the purchase. @see CocoonJS.Store.PurchaseState
	* @param {string} The product id related to this purchase.
	* @param {number} The number of products of the productId kind purchased in this transaction.
	*/
	CocoonJS.Store.PurchaseInfo = function(transactionId, purchaseTime, purchaseState, productId, quantity)
	{
		/**
		* The transaction id of a purchase.
		* @field
		* @type string
		*/
		this.transactionId = transactionId;

		/**
		* The time when the purchase was done in seconds since 1970.
		* @field
		* @type string
		*/
		this.purchaseTime = purchaseTime;

		/**
		* The state of the purchase. @see CocoonJS.Store.PurchaseState
		* @field
		* @type CocoonJS.Store.PurchaseState
		*/
		this.purchaseState = purchaseState;

		/**
		* The product id related to this purchase.
		* @field
		* @type string
		*/
		this.productId = productId;

		/**
		* The number of products of the productId kind purchased in this transaction.
		* @field
		* @type number
		*/
		this.quantity = quantity;

		return this;
	};

	/**
    * The predefined possible states of a purchase.
    * @namespace 
    */
	CocoonJS.Store.PurchaseState = 
	{
		/**
		* The product has been successfully purchased. The transaction has ended successfully.
		*/
	    PURCHASED : 0,

		/**
		* The purchase has been canceled.
		*/
	    CANCELED : 1,

	    /**
		* The purchase has been refunded.
		*/
	    REFUNDED : 2,

	    /**
		* The purchase (subscriptions only) has expired and is no longer valid.
		*/
	    EXPIRED : 3
	};

	/**
	* Gets the name of the native store implementation. 
	* @return {CocoonJS.Store.StoreType} The store type
	* @function
	*/ 
	CocoonJS.Store.getStoreType = function()
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "getStoreType", arguments);
		}
	};

	/**
	* Initialize the service with service level initialization parameters.
	* @function
	* @param {object} An object with the required initialization parameters for the service.
	*/
	CocoonJS.Store.requestInitialization = function(parameters)
	{
        if (typeof parameters === "undefined") 
        {
            parameters = {};
        }
        else
        {
        	if (parameters['managed'] !== undefined) parameters['remote'] = parameters['managed'];
        	if (parameters['sandbox'] !== undefined) parameters['debug'] = parameters['sandbox'];
        }

		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "requestInitialization", arguments, true);
		}
	};

	/**
	* Starts the Store Service. 
	* This will make the system to initialize the Store Service and probably Store callbacks will start to be received after calling this method so you should have set your event handler before calling this method so don't lose any callback.
	* @function
	*/ 
	CocoonJS.Store.start = function()
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "start", arguments);
		}
	};

	/**
	* This method allows you to check is the  Store service is available in this platform. 
	* Not all iOS and Android devices will have the Store service available so you should check if it is before calling any other method.
	* @function
	* @return {boolean} True if the service is available and false otherwise.
	*/ 
	CocoonJS.Store.canPurchase = function()
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "canPurchase", arguments);
		}
	};

	/**
	* Fetches the products from the CocoonJS Cloud Compiling service store configuration. 
	* The request is monitored using the {@link CocoonJS.Store.onProductsFetchStarted}, {@link CocoonJS.Store.onProductsFetchCompleted} and {@link CocoonJS.Store.onProductsFetchFailed} event handlers.
	* @deprecated You should now use fetchProductsFromStore. We don't support cloud products now.
	* @function
	* @see CocoonJS.Store.onProductsFetchStarted
	* @see CocoonJS.Store.onProductsFetchCompleted
	* @see CocoonJS.Store.onProductsFetchFailed
	*/ 
	CocoonJS.Store.fetchProductsFromServer = function()
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "fetchProductsFromServer", arguments, true);
		}
	};

	/**
	* Fetches the products information from the Store. 
	* The request is monitored using the {@link CocoonJS.Store.onProductsFetchStarted}, {@link CocoonJS.Store.onProductsFetchCompleted} and {@link CocoonJS.Store.onProductsFetchFailed} event handlers.
	* @function
	* @param {array} productIds An array with the ids of the products to retrieve information from.
	* @see CocoonJS.Store.onProductsFetchStarted
	* @see CocoonJS.Store.onProductsFetchCompleted
	* @see CocoonJS.Store.onProductsFetchFailed
	*/ 
	CocoonJS.Store.fetchProductsFromStore = function(productIds)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "fetchProductsFromStore", arguments, true);
		}
	};

	/**
	* Finish a purchase transaction and removes the transaction from the transaction queue. 
	* This method must be called after a purchase finishes successfully and the  {@link CocoonJS.Store.onProductPurchaseCompleted} callback has been received. 
	* If the purchase includes some asset to download from an external server this method must be called after the asset has been successfully downloaded. 
	* If you do not finish the transaction because the asset has not been correctly downloaded the {@link CocoonJS.Store.onProductPurchaseStarted} method will be called again later on.
	* @function
	* @param {string} transactionId The transactionId of the purchase to finish.
	*/ 
	CocoonJS.Store.finishPurchase = function(transactionId)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "finishPurchase", arguments, true);
		}
	};

	/**
	* Consumes a purchase. This makes that product to be purchasable again. 
	* @function
	* @param {string} transactionId The transaction Id of the purchase to consume.
	* @param {string} productId The product Id of the product to be consumed.
	*/ 
	CocoonJS.Store.consumePurchase = function(transactionId, productId)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "consumePurchase", arguments, true);
		}
	};

	/**
	* Request a product purchase given it's product id. 
	* The request is monitored using the {@link CocoonJS.Store.onPurchaseProductStarted}, {@link CocoonJS.Store.onProductPurchaseStarted} and {@link CocoonJS.Store.onProductPurchaseFailed} event handlers.
	* @function
	* @param {string} productId The id or alias of the product to be purchased.
	* @see CocoonJS.Store.onProductPurchaseStarted
	* @see CocoonJS.Store.onProductPurchaseCompleted
	* @see CocoonJS.Store.onProductPurchaseFailed
	*/ 
	CocoonJS.Store.purchaseProduct = function(productId)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "purchaseFeature", arguments, true);
		}
	};

	/**
	* Request a product purchase given it's product id showing a modal progress dialog. 
	* The request is monitored using the {@link CocoonJS.Store.onProductPurchaseStarted}, {@link CocoonJS.Store.onProductPurchaseCompleted} and {@link CocoonJS.Store.onProductPurchaseFailed} event handlers.
	* @function
	* @param {string} productId The id or alias of the product to be purchased.
	* @see CocoonJS.Store.onProductPurchaseStarted
	* @see CocoonJS.Store.onProductPurchaseCompleted
	* @see CocoonJS.Store.onProductPurchaseFailed
	*/ 
	CocoonJS.Store.puchaseProductModal = function(productId)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "purchaseFeatureModal", arguments, true);
		}
	};

	/**
	* Request the purchase of a product given it's product id showing a dialog with a preview of the product (title and description). 
	* The request is monitored using the {@link CocoonJS.Store.onProductPurchaseStarted}, {@link CocoonJS.Store.onProductPurchaseCompleted} and {@link CocoonJS.Store.onProductPurchaseFailed} event handlers.
	* @function
	* @param {string} productId The id or alias of the product to be purchased.
	* @see CocoonJS.Store.onProductPurchaseStarted
	* @see CocoonJS.Store.onProductPurchaseCompleted
	* @see CocoonJS.Store.onProductPurchaseFailed
	*/ 
	CocoonJS.Store.purchaseProductModalWithPreview = function(productId)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "purchaseFeatureModalWithPreview", arguments, true);
		}
	};

	/**
	* Returns if a product has been already purchased or not. 
	* @function
	* @param {string} productId The product id or alias of the product to be checked.
	* @returns {boolean} A flag that indicates whether the product has been already purchased (true) or not (false).
	*/
	CocoonJS.Store.isProductPurchased = function(productId)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "isFeaturePurchased", arguments);
		}
	};

	/**
	* Restores all the purchases from the platform's market. 
	* For each already purchased product {@link CocoonJS.Store.onPurchaseProductStarted}, {@link CocoonJS.Store.onPurchaseProductCompleted} and {@link CocoonJS.Store.onPurchaseProductFailed} event handlers are called again
	* @function
	* @see CocoonJS.Store.onRestorePurchasesStarted
	* @see CocoonJS.Store.onRestorePurchasesCompleted
	* @see CocoonJS.Store.onRestorePurchasesFailed
	*/
	CocoonJS.Store.restorePurchases = function()
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "restorePurchases", arguments, true);
		}
	};

	/**
	* Restores all the purchases from the platform's market showing a modal progress dialog. 
	* For each already purchased product {@link CocoonJS.Store.onPurchaseProductStarted}, {@link CocoonJS.Store.onPurchaseProductCompleted} and {@link CocoonJS.Store.onPurchaseProductFailed} event handlers are called again
	* @function
	* @see CocoonJS.Store.onRestorePurchasesStarted
	* @see CocoonJS.Store.onRestorePurchasesCompleted
	* @see CocoonJS.Store.onRestorePurchasesFailed
	*/
	CocoonJS.Store.restorePurchasesModal = function()
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "restorePurchasesModal", arguments, true);
		}
	};

	/**
	* Returns all the products available to be purchased.
	* @function
	* @returns {array} An array with  all the {@link CocoonJS.Store.ProductInfo} objects available for purchase.
	*/
	CocoonJS.Store.getProducts = function()
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "getProducts", arguments);
		}
	};

	/**
	* Adds a product to the products local DB. 
	* @function
	* @param {CocoonJS.Store.ProductInfo} product The product to be added to the local products DB.
	*/
	CocoonJS.Store.addProduct = function(product)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "addProduct", arguments);
		}
	};

	/**
	* Removes a product from the products local DB given its productId. 
	* @function
	* @param {string} productId The product or alias of the product to be removed from the local products DB.
	*/
	CocoonJS.Store.removeProduct = function(productId)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "removeProduct", arguments);
		}
	};

	/**
	* Returns all the locally stored purchases.
	* @function
	* @returns {array} An array with all the {@link CocoonJS.Store.PurchaseInfo} completed purchases.
	*/
	CocoonJS.Store.getPurchases = function()
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "getPurchases", arguments);
		}
	};

	/**
	* Adds a purchase to the local purchases DB. 
	* @function
	* @param {CocoonJS.Store.StorePurchase} purchase The purchase to be added.
	*/ 
	CocoonJS.Store.addPurchase = function(purchase)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "addPurchase", arguments);
		}
	};

	/**
	* Removes a purchase from the local purchases DB given it's transaction id. 
	* @function
	* @param {string} transactionId The id of the transaction to be removed.
	*/ 
	CocoonJS.Store.removePurchase = function(transactionId)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "removePurchase", arguments);
		}
	};

	/**
	* (TESTING ONLY) Simulate a purchase cancel. 
	* This method is not allowed in production services and will only work in Mocks. 
	* The request is monitored using the {@link CocoonJS.Store.onPurchaseProductStarted}, {@link CocoonJS.Store.onProductPurchaseStarted} and {@link CocoonJS.Store.onProductPurchaseFailed} event handlers.
	* @function
	* @param {string} transactionId The transactionId of the purchase to be canceled.
	*/
	CocoonJS.Store.cancelPurchase = function(transactionId)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "cancelPurchase", arguments);
		}
	};

	/**
	* (TESTING ONLY) Simulate a purchase refundment. 
	* This method is not allowed in production services and will only work in Mocks. 
	* The request is monitored using the {@link CocoonJS.Store.onPurchaseProductStarted}, {@link CocoonJS.Store.onProductPurchaseStarted} and {@link CocoonJS.Store.onProductPurchaseFailed} event handlers.
	* @function
	* @param {string} transactionId The transactionId of the purchase to be refunded.
	*/
	CocoonJS.Store.refundPurchase = function(transactionId)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "refundPurchase", arguments);
		}
	};

	/**
	* (TESTING ONLY) Simulate a purchase expiration. 
	* This method is not allowed in production services and will only work in Mocks. 
	* The request is monitored using the {@link CocoonJS.Store.onPurchaseProductStarted}, {@link CocoonJS.Store.onProductPurchaseStarted} and {@link CocoonJS.Store.onProductPurchaseFailed} event handlers.
	* @function
	* @param {string} transactionId The transactionId of the purchase to be expired.
	*/
	CocoonJS.Store.expirePurchase = function(transactionId)
	{
		if (CocoonJS.Store.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_STORE", "expirePurchase", arguments);
		}
	};

	/**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the products fetch has started.
    * The callback function receives no parameters.
    * @static
    * @event
    */
	CocoonJS.Store.onProductsFetchStarted = new CocoonJS.EventHandler("IDTK_SRV_STORE", "Store", "onProductsFetchStarted");

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the products fetch has completed.
    * The callback function receives a parameter with an the valid products array.
    * @static
    * @event
    * @param {array} validProducts An array of {@link CocoonJS.Store.ProductInfo} objects representing all the valid fetched products.
    */
	CocoonJS.Store.onProductsFetchCompleted = new CocoonJS.EventHandler("IDTK_SRV_STORE", "Store", "onProductsFetchCompleted"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the products fetch has failed.
    * The callback function receives an error message as a parameter.
    * @static
    * @event
    * @param {string} errorMessage The error message.
    */
	CocoonJS.Store.onProductsFetchFailed = new CocoonJS.EventHandler("IDTK_SRV_STORE", "Store", "onProductsFetchFailed"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the purchase of a product starts.
    * The callback function receives a parameters with the information of the purchased product @see CocoonJS.Store.ProductInfo.
    * @static
	* @event
    * @param {string} productId The product id of the product being purchased.
    */
	CocoonJS.Store.onProductPurchaseStarted = new CocoonJS.EventHandler("IDTK_SRV_STORE", "Store", "onProductPurchaseStarted"); 

	/**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when a request for purchase verification has been received from the Store.
    * The callback function receives two parameters, one with the productId of the purchased product and another one with a JSON object containing the data to be verified.
    * In Andorid this JSON object will containt two keys: signedData and signature. You will need that information to verify the purchase against the backend server.
    * @static
    * @event
    * @param {string} productId The product id of the product to be verified.
    * @param {string} data The string with the data to be verified.
    */
	CocoonJS.Store.onProductPurchaseVerificationRequestReceived = new CocoonJS.EventHandler("IDTK_SRV_STORE", "Store", "onProductPurchaseVerificationRequestReceived");

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the purchase of a product succeeds.
    * The callback function receives as parameter the information of the purchase {@see CocoonJS.Store.PurchaseInfo}.
    * @static
    * @event
    * @param {CocoonJS.Store.PurchaseInfo} purchaseInfo The purchase info.
    */
	CocoonJS.Store.onProductPurchaseCompleted = new CocoonJS.EventHandler("IDTK_SRV_STORE", "Store", "onProductPurchaseCompleted"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the purchase of a product fails.
    * The callback function receives a parameters with the product id and an error message.
    * @static
    * @event
    * @param {string} productId The product id.
    * @param {string} msg The error message.
    */
	CocoonJS.Store.onProductPurchaseFailed = new CocoonJS.EventHandler("IDTK_SRV_STORE", "Store", "onProductPurchaseFailed"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the restore purchases operation has started.
    * The callback function receives no parameters.
    * @static
    * @event
    */
	CocoonJS.Store.onRestorePurchasesStarted = new CocoonJS.EventHandler("IDTK_SRV_STORE", "Store", "onRestorePurchasesStarted"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the restore purchases operation has completed.
    * The callback function receives no parameters.
    * @static
    * @event
    */
	CocoonJS.Store.onRestorePurchasesCompleted = new CocoonJS.EventHandler("IDTK_SRV_STORE", "Store", "onRestorePurchasesCompleted"); 

	/**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the restore purchases operation has failed.
    * The callback function receives an error message as a parameter.
    * @static
    * @event
    * @param {string} errorMessage The error message.
    */
	CocoonJS.Store.onRestorePurchasesFailed = new CocoonJS.EventHandler("IDTK_SRV_STORE", "Store", "onRestorePurchasesFailed");

	/**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the consume purchase operation has started.
    * @static
    * @event
    * @param {string} transactionId The transaction id of the purchase being consumed.
    */
	CocoonJS.Store.onConsumePurchaseStarted = new CocoonJS.EventHandler("IDTK_SRV_STORE", "Store", "onConsumePurchaseStarted"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the consume purchase operation has completed.
    * @static
    * @event
    * @param {string} transactionId The transaction id of the consumed purchase.
    */
	CocoonJS.Store.onConsumePurchaseCompleted = new CocoonJS.EventHandler("IDTK_SRV_STORE", "Store", "onConsumePurchaseCompleted"); 

	/**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the consume purchase operation has failed.
    * @static
    * @event
    * @param {string} transactionId The transaction id of the purchase that couldn't be consumed.
    * @param {string} errorMessage The error message.
    */
	CocoonJS.Store.onConsumePurchaseFailed = new CocoonJS.EventHandler("IDTK_SRV_STORE", "Store", "onConsumePurchaseFailed");

})();

//////////////////////////////////////
// COCOONJS_SOCIAL.JS               //
//////////////////////////////////////

(function()
{
    // The CocoonJS must exist before creating the extension.
    if (typeof window.CocoonJS === 'undefined' || window.CocoonJS === null) throw("The CocoonJS object must exist and be valid before creating any extension object.");

	/**
	* This type represents the access to a native Social extension API. As there can be more than
	* one service of this type, more than one instance can be created.
	* @namespace
	* @constructor
	* @param {string} nativeExtensionName The name of the native ext object extension property name.
	* @param {string} extensionName The name of the CocoonJS object extension property name.
	*/
	CocoonJS.Social = function(nativeExtensionName, extensionName)
	{
		if (typeof nativeExtensionName !== 'string') throw "The given native extension name '" + nativeExtensionName + "' is not a string.";
		if (typeof extensionName !== 'string') throw "The given extension name '" + extensionName + "' is not a string.";

		this.nativeExtensionName = nativeExtensionName;
		this.extensionName = extensionName;
	    this.nativeExtensionObjectAvailable = CocoonJS.nativeExtensionObjectAvailable && typeof window.ext[nativeExtensionName] !== 'undefined';

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.Social.onRequestInitializationSucceed} event calls.
	     * @name OnRequestInitializationSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.Social
	     * @param {object} initializationData The data structure passed when requestInitialization was called.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user information request suceeds.
	    * The callback function's documentation is represented by {@link CocoonJS.Social.OnRequestInitializationSucceedListener}
	    * @static
	    * @event
	    * @memberOf CocoonJS.Social
	    */
	    this.onRequestInitializationSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestInitializationSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.Social.onRequestInitializationFailed} event calls.
	     * @name OnRequestInitializationFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.Social
	     * @param {object} initializationData The data structure passed when the requestInitialization function was called.
	     * @param {string} errorMessage The message that describes why the request did fail.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user information request fails.
	    * The callback function's documentation is represented by {@link CocoonJS.Social.OnRequestInitializationFailedListener}
	    * @static
	    * @event
	    * @memberOf CocoonJS.Social
	    */
	    this.onRequestInitializationFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestInitializationFailed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.Social.onRequestLoginSucceed} event calls.
	     * @name OnRequestLoginSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.Social
	     * @param {CocoonJS.Social.UserInfo} userInfo The structure that describes the information of the user that logged in.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user login request succeeds.
	    * The callback function's documentation is represented by {@link CocoonJS.Social.OnRequestLoginSucceedListener}
	    * @static
	    * @event
	    * @memberOf CocoonJS.Social
	    */
		this.onRequestLoginSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestLoginSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.Social.onRequestLoginFailed} event calls.
	     * @name OnRequestLoginFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.Social
	     * @param {string} errorMessage The message that describes why the request did fail.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user login request fails.
	    * The callback function's documentation is represented by {@link CocoonJS.Social.OnRequestLoginFailedListener}
	    * @static
	    * @event
	    * @memberOf CocoonJS.Social
	    */
		this.onRequestLoginFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestLoginFailed");

	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user logs out.
	    * The callback function does not receive any parameter.
	    * @static
	    * @event
	    * @memberOf CocoonJS.Social
	    */
		this.onLogout = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onLogout");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.Social.onRequestUserInfoSucceed} event calls.
	     * @name OnRequestUserInfoSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.Social
	     * @param {CocoonJS.Social.UserInfo} userInfo The structure that describes the information of the request user id.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user information request suceeds.
	    * The callback function's documentation is represented by {@link CocoonJS.Social.OnUserInfoRequestSucceedListener}
	    * @static
	    * @event
	    * @memberOf CocoonJS.Social
	    */
		this.onRequestUserInfoSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestUserInfoSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.Social.onRequestUserInfoFailed} event calls.
	     * @name OnRequestUserInfoFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.Social
	     * @param {string} userID The id used in the request.
	     * @param {string} errorMessage The message that describes why the request did fail.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user information request fails.
	    * The callback function's documentation is represented by {@link CocoonJS.Social.OnUserInfoRequestFailedListener}
	    * @static
	    * @event
	    * @memberOf CocoonJS.Social
	    */
		this.onRequestUserInfoFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestUserInfoFailed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.Social.onRequestUserImageURLSucceed} event calls.
	     * @name OnRequestUserImageURLSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.Social
	     * @param {string} userID The id used in the request.
	     * @param {string} imageURL The URL of the image of the requested user. 
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user image URL request succeeds.
	    * The callback function's documentation is represented by {@link CocoonJS.Social.OnRequestUserImageURLSucceedListener}
	    * @static
	    * @event
	    * @memberOf CocoonJS.Social
	    */
		this.onRequestUserImageURLSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestUserImageURLSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.Social.onRequestUserImageURLFailed} event calls.
	     * @name OnRequestUserImageURLFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.Social
	     * @param {string} userID The id of the user the request was placed for.
	     * @param {string} errorMessage The message that describes why the request did fail.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user image URL request fails.
	    * The callback function's documentation is represented by {@link CocoonJS.Social.OnRequestUserImageURLFailedListener}
	    * @static
	    * @event
	    * @memberOf CocoonJS.Social
	    */
		this.onRequestUserImageURLFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestUserImageURLFailed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.Social.onRequestUserFriendsUserInfosSucceed} event calls.
	     * @name OnRequestUserFriendsUserInfosSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.Social
	     * @param {string} userID The id of the user for whom the friend user infos where requested.
	     * @param {array} friendsInfo An array of {@link CocoonJS.Social.UserInfo} objects representing the information of the friends of the user.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user's friends info is successfully retrieved.
	    * The callback function's documentation is represented by {@link CocoonJS.Social.OnRequestUserFriendsUserInfosSucceedListener}
	    * @static
	    * @event
	    * @memberOf CocoonJS.Social
	    */
		this.onRequestUserFriendsUserInfosSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestUserFriendsUserInfosSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.Social.onRequestUserFriendsUserInfosFailed} event calls.
	     * @name OnRequestUserFriendsUserInfosFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.Social
	     * @param 
	     * @param {string} userID The id of the user fro whom the friends infos were requested.
	     * @param {string} errorMessage The error message.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user's friends info fails to be retrieved.
	    * The callback function's documentation is represented by {@link CocoonJS.Social.OnRequestUserFriendsUserInfosFailedListener}
	    * @static
	    * @event
	    * @memberOf CocoonJS.Social
	    */
		this.onRequestUserFriendsUserInfosFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestUserFriendsUserInfosFailed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.Social.onRequestMessagePublicationSucceed} event calls.
	     * @name OnRequestMessagePublicationSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.Social
 	     * @param {CocoonJS.Social.Message} message The message that has been published.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user message publication request succeeds.
	    * The callback function's documentation is represented by {@link CocoonJS.Social.OnRequestMessagePublicationSucceedListener}
	    * @static
	    * @event
	    * @memberOf CocoonJS.Social
	    * @param {CocoonJS.Social.Message} message The message that has been published.
	    */
		this.onRequestMessagePublicationSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestMessagePublicationSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.Social.onRequestMessagePublicationFailed} event calls.
	     * @name OnRequestMessagePublicationFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.Social
	     * @param {CocoonJS.Social.Message} message The message that was supposed to be published.
	     * @param {string} errorMessage The error message.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user message publication request fails.
	    * The callback function's documentation is represented by {@link CocoonJS.Social.OnRequestMessagePublicationFailedListener}
	    * @static
	    * @event
	    * @memberOf CocoonJS.Social
	    */
		this.onRequestMessagePublicationFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestMessagePublicationFailed");

		/**
        * @ignore
        */
        this.on= function(event, callback) {
            event= "on"+event[0].toUpperCase()+event.substr(1);
            var signal= this[event];
            if (signal) {
                signal.addEventListener(callback);
            } else {
                console.error("SocialGaming service: '"+this.extensionName+"' does not understand '"+event+' signal.');
            }

            return this;
        };

	    return this;
	};

	CocoonJS.Social.prototype = {
        userInfo : null,
        userInfoCocoonJS : null,

        /**
        * @ignore
        */
        getUserInfo : function() {
            return this.userInfo;
        },

        /**
        * Returns the information of the currently logged in user.
        * @return {@link CocoonJS.Social.UserInfo}
        */
        getLoggedInUserInfo : function() {
            if (this.nativeExtensionObjectAvailable) {
                return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "getLoggedInUserInfo", arguments);
            }
            else {
                return this.userInfoCocoonJS;
            }
        },

        /**
        * @ignore
        */
        setUserInfo : function( userInfo) {
            this.userInfo= userInfo;
        },

        /**
        * @ignore
        */
        setUserInfoCocoonJS : function( userInfoCocoonJS ) {
            this.userInfoCocoonJS = userInfoCocoonJS;
        },

		/**
        * Request initialization of the underlying social service.
        * @param {object} paramsObject A data structure to initialize the service. It will be dependable of the underlying service.
        * @see CocoonJS.Social.onRequestInitializationSucceed
        * @see CocoonJS.Social.onRequestInitializationFailed
        */
		requestInitialization : function(paramsObject) 
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "requestInitialization", arguments, true);
			}
		},

		/**
        * Returns a flag to indicate if the underlying service has been initialized or not.
        * @return {boolean} If the underlying service had been initialized using the requestInitialization function call.
        */
		isInitialized : function()
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "isInitialized", arguments);
			}
			else
			{
				return false;
			}
		},

		/**
		* Request to log in the social gaming application.
		* @see CocoonJS.Social.onRequestLoginSucceed
		* @see CocoonJS.Socual.onRequestLoginFailed
		*/
		requestLogin : function()
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "requestLogin", arguments, true);
			}
		},

		/**
		* Request to log out of the social gaming application.
		* @see CocoonJS.Social.onRequestLoginSucceed
		* @see CocoonJS.Social.onRequestLoginFailed
		* @see CocoonJS.Social.onLogout
		*/
		requestLogout : function()
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "requestLogout", arguments, true);
			}
		},

		/**
		* Check if the user is logged in.
		* @return {boolean} true if the user is still logged in, false otherwise.
		*/
		isLoggedIn : function()
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "isLoggedIn", arguments);
			}
			else
			{
				return false;
			}
		},

		/**
		* Request to retrieve the current or a specific user's id. The request can be monitored using the {@link CocoonJS.Social.onUserInfoRequestSucceed} and {@link CocoonJS.Social.onUserInfoRequestFailed} event handlers.
		* @param {string} [userId] The id of the user to retireve the information from. If no userID is specified, the currently logged in user is assumed.
		* @see CocoonJS.Social.onRequestUserInfoSucceed
		* @see CocoonJS.Social.onRequestUserInfoFailed
		*/
		requestUserInfo : function(userID)
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "requestUserInfo", arguments, true);
			}
		},

		/**
		* Request to retrieve the Image of a user
		* @param {string} [userID] The id of the user to get the image for. If no userID is specified, the currently logged user is used.
		* @param {CocoonJS.Social.ImageSizeType} [imageSizeType] The size of the image. One of the possible values among the ones in the {@link CocoonJS.Social.ImageSizeType}. If no value is specified, SMALL is used.
		* @see CocoonJS.Social.onRequestUserImageURLSucceed;
		* @see CocoonJS.Social.onRequestUserImageURLFailed;
		*/
		requestUserImageURL : function( imageSizeType, userID)
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "requestUserImageURL", arguments, true);
			}
		},

		/**
		* Request for the information of all the friends of the currently logged user.
		* @param {string} [userID] The id of the user to get the friends infos for. If no userID is specified, the currently logged user is used.
		* @see CocoonJS.Social.onRequestUserFriendsUserInfosSucceed;
		* @see CocoonJS.Social.onRequestUserFriendsUserInfosFailed;
		*/
		requestUserFriendsUserInfos : function(userID)
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "requestUserFriendsUserInfos", arguments, true);
			}
		},

		/**
		* Request the publication of a message using a dialog.
		* @param {CocoonJS.Social.Message} message A object representing the information to be published.
		* @see CocoonJS.Social.onRequestMessagePublicationSucceed
		* @see CocoonJS.Social.onRequestMessagePublicationFailed
		*/
		requestMessagePublicationWithDialog : function(message)
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "requestMessagePublicationWithDialog", arguments, true);
			}
		}
	};

	/**
	* This structure represents the possible images to be obtained for a user in the social gaming extension.
	* @namespace
	*/
	CocoonJS.Social.ImageSizeType = 
	{
		/**
		* Represent a thumbnail like image size.
		*/
	    THUMB : "thumb",

		/**
		* Represents the small image size.
		*/
	    SMALL : "small",

		/**
		* Represents the medium image size.
		*/
	    MEDIUM : "medium",

		/**
		* Represents the large image size.
		*/
	    LARGE : "large"
	};

	/**
	* The data structure that represents the information of a user inside the social gaming extension.
	* @namespace
	* @constructor
	* @param {string} userID The id of the user.
	* @param {string} userName The user name of the user.
	*/
	CocoonJS.Social.UserInfo = function(userID, userName)
	{
		/**
		* The id of the user.
		* @field
		* @type string
		*/
		this.userID = userID;

		/**
		* The user name of the user.
		* @field
		* @type string
		*/
		this.userName = userName;
	};

	/**
	* This type represents a message to be published.
	* @namespace
	* @constructor
	* @param {string} message The message to be published.
	* @param {string} mediaURL An URL to a media (image, video, ...)
	* @param {string} linkURL An URL to add to the message so the user can click on that link to get more information.
	* @param {string} linkText The text that will appear in the message link.
	* @param {string} linkCaption The text caption that will appear in the message link.
	*/
	CocoonJS.Social.Message = function(message, mediaURL, linkURL, linkText, linkCaption)
	{
		/**
		* The message to be published.
		* @field
		* @type string
		*/
		this.message = message;

		/**
		* An URL to a media (image, video, ...)
		* @field
		* @type string
		*/
		this.mediaURL = mediaURL;

		/**
		* An URL to add to the message so the user can click on that link to get more information.
		* @field
		* @type string
		*/
		this.linkURL = linkURL;

		/**
		* The text that will appear in the message link.
		* @field
		* @type string
		*/
		this.linkText = linkText;

		/**
		* The text caption that will appear in the message link.
		* @field
		* @type string
		*/
		this.linkCaption = linkCaption;

		return this;
	};

})();

//////////////////////////////////////
// COCOONJS_SOCIALGAMING.JS         //
//////////////////////////////////////

(function()
{
    // The CocoonJS must exist before creating the extension.
    if (typeof window.CocoonJS === 'undefined' || window.CocoonJS === null) throw("The CocoonJS object must exist and be valid before creating any extension object.");

    if (!CocoonJS.Social)
		throw("The CocoonJS.Social object must exist and be valid before creating any extension object.");

	/**
	* This type represents the access to a native Social Gamming extension API. As there can be more than
	* one service of this type, more than one instance can be created.
	* @namespace
	* @constructor
	* @param {string} nativeExtensionName The name of the native ext object extension property name.
	* @param {string} extensionName The name of the CocoonJS object extension property name.
	*/
	CocoonJS.SocialGaming = function(nativeExtensionName, extensionName)
	{
		CocoonJS.SocialGaming.superclass.constructor.call(this, nativeExtensionName, extensionName);

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onRequestUserAndFriendsScoresSucceed} event calls.
	     * @name OnRequestUserAndFriendsScoresSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {array} userAndFriendsScoreInfos An array of {@link CocoonJS.SocialGaming.UserScoreInfo} objects representing the information of the user's and friends' scores.
	     */
		/**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user and friends scores request succeeds.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnRequestUserAndFriendsScoresSucceedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onRequestUserAndFriendsScoresSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestUserAndFriendsScoresSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onRequestUserAndFriendsScoresFailed} event calls.
	     * @name OnRequestUserAndFriendsScoresFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} userID The id of the user for whom the score and friends scores were requested.
	     * @param {string} leadeboardID The id of the leaderboard for whom the score and friends scores were requested.
	     * @param {string} errorMessage The error message.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user and his/her friends scores request fails.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnRequestUserAndFriendsScoresFailedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onRequestUserAndFriendsScoresFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestUserAndFriendsScoresFailed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onRequestUserScoreSucceed} event calls.
	     * @name OnRequestUserScoreSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {CocoonJS.SocialGaming.UserScoreInfo} userScoreInfo The info of the user's score.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user's score information request suceeds.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnRequestUserScoreSucceedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onRequestUserScoreSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestUserScoreSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onRequestUserScoreFailed} event calls.
	     * @name OnRequestUserScoreFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} userID The id of the user for whom the score was requested.
	     * @param {string} leaderboardID The id of the leaderboard for whom the score was requested.
	     * @param {string} errorMessage The error message.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user's score information request fails.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnRequestUserScoreFailedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onRequestUserScoreFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestUserScoreFailed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onSubmitUserScoreSucceed} event calls.
	     * @name OnSubmitUserScoreSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} userID The id of the user for whom the score has been submitted.
	     * @param {string} leaderboardID The id of the leaderboard for which the score has been submitted.
	     * @param {number} score The score that has been submitted.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user's score submit suceeds.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnSubmitUserScoreSucceedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onSubmitUserScoreSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onSubmitUserScoreSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onSubmitUserScoreFailed} event calls.
	     * @name OnSubmitUserScoreFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} userID The id of the user for whom the score submition was requested.
	     * @param {string} leaderboadID The id of the leaderboard for which the score submition was requested.
	     * @param {number} score The score that was submitted and failed.
	     * @param {string} errorMessage The error message.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user's score submit fails.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnSubmitUserScoreFailedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onSubmitUserScoreFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onSubmitUserScoreFailed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onRequestUserAchievementsSucceed} event calls.
	     * @name OnRequestUserAchievementsSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} userID The id of the user for whom the achievements where requested.
	     * @param {array} achievementsInfos An array of {@link CocoonJS.SocialGaming.AchievementInfo} objects representing the information of the user's achievements.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user's achievements info are successfully retrieved.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnRequestUserAchievementsSucceedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onRequestUserAchievementsSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestUserAchievementsSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onRequestUserAchievementsFailed} event calls.
	     * @name OnRequestUserAchievementsFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} userID The id of the user for whom the achievements were requested.
	   	 * @param {string} msg The error message.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user's achievmeents info fails to be retrieved.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnRequestUserAchievementsFailedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onRequestUserAchievementsFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestUserAchievementsFailed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onRequestAllAchievementsSucceed} event calls.
	     * @name OnRequestAllAchievementsSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {array} achievementsInfos An array of {@link CocoonJS.SocialGaming.AchievementInfo} objects representing the information of all the achievements.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user's achievements info are successfully retrieved.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnRequestAllAchievementsSucceedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onRequestAllAchievementsSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestAllAchievementsSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onRequestAllAchievementsFailed} event calls.
	     * @name OnRequestAllAchievementsFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	   	 * @param {string} msg The error message.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the user's achievmeents info fails to be retrieved.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnRequestAllAchievementsFailedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onRequestAllAchievementsFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestAllAchievementsFailed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onRequestAchievementInfoSucceed} event calls.
	     * @name OnRequestAchievementInfoSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {CocoonJS.SocialGaming.AchievementInfo} achievementInfo A {@link CocoonJS.SocialGaming.AchievementInfo} object representing the information of the achievement.
	     */
		/**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the request to retrieve the information of an achievement succeeds.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnRequestAchievementInfoSucceedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onRequestAchievementInfoSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestAchievementInfoSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onRequestAchievementInfoFailed} event calls.
	     * @name OnRequestAchievementInfoFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} achievementID The id of the achievement for which the information retrieval was requested.
	     * @param {string} errorMessage The error message.
	     */
		/**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the request to retrieve the information of an achievement fails.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnRequestAchievementInfoFailedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onRequestAchievementInfoFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onRequestAchievementInfoFailed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onSubmitUserAchievementSucceed} event calls.
	     * @name OnSubmitUserAchievementSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} userID The id of the user for whom the achievement has been submitted.
	     * @param {string} achievementID The id of the achievement that has been submitted.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when a user's achievement submition succeeds.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnSubmitUserAchievementSucceedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onSubmitUserAchievementSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onSubmitUserAchievementSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onSubmitUserAchievementFailed} event calls.
	     * @name OnSubmitUserAchievementFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} userID The id of the user for whom the achievment was submitted.
	     * @param {string} achievementID The id of the achievement that was submitted.
	     * @param {string} msg The error message.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when a user's achievement submition fails.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnSubmitUserAchievementFailedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onSubmitUserAchievementFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onSubmitUserAchievementFailed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onResetUserAchievementsSucceed} event calls.
	     * @name OnResetUserAchievementsSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} userID The id of the user for whom the achievements were reset.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when a user's achievement reset succeeds.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnResetUserAchievementsSucceedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onResetUserAchievementsSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onResetUserAchievementsSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onResetUserAchievementsFailed} event calls.
	     * @name OnResetUserAchievementsFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} userID The id of the user for whom the achievements where tried to be reset.
	     * @param {string} msg The error message.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when a user's achievement reset fails.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnResetUserAchievementsFailedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onResetUserAchievementsFailed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onResetUserAchievementsFailed");

	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the users closes the achievements view.
	    * The callback function does not receive any parameter.
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onAchievementsViewClosed  = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onAchievementsViewClosed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onAchievementsViewFailed} event calls.
	     * @name OnAchievementsViewFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} errorMessage The message that describes why the call failed.
	     */
		/**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when the achievements view failed to show.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnAchievementsViewFailedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onAchievementsViewFailed  = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onAchievementsViewFailed");

		/**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when achievements view shows successfully.
	    * The callback function does not receive any parameter.
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
		this.onAchievementsViewSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onAchievementsViewSucceed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onLeaderboardViewClosed} event calls.
	     * @name OnLeaderboardViewClosedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} leaderboardID The id of the leaderboard for which it's vew was requested to be shown.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when a user's achievement reset fails.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnLeaderboardViewClosedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
   		this.onLeaderboardViewClosed  = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onLeaderboardViewClosed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onLeaderboardViewFailed} event calls.
	     * @name OnLeaderboardViewFailedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} leaderboardID The id of the leaderboard for which it's vew was requested to be shown.
	     * @param {string} errorMessage The error message.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when a user's achievement reset fails.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnLeaderboardViewFailedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
   		this.onLeaderboardViewFailed  = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onLeaderboardViewFailed");

	    /**
	     * FOR DOCUMENTATION PURPOSE ONLY! The documentation of the function callback for the {@link CocoonJS.SocialGaming.onLeaderboardViewSucceed} event calls.
	     * @name OnLeaderboardViewSucceedListener
	     * @function
	     * @static
	     * @memberOf CocoonJS.SocialGaming
	     * @param {string} leaderboardID The id of the leaderboard for which it's vew was requested to be shown.
	     */
	    /**
	    * This {@link CocoonJS.EventHandler} object allows listening to events called when a user's achievement reset fails.
	    * The callback function's documentation is represented by {@link CocoonJS.SocialGaming.OnLeaderboardViewSucceedListener}
	    * @event
	    * @static
	    * @memberOf CocoonJS.SocialGaming
	    */
   		this.onLeaderboardViewSucceed = new CocoonJS.EventHandler(this.nativeExtensionName, this.extensionName, "onLeaderboardViewSucceed");

		return this;
	};

	CocoonJS.SocialGaming.prototype = 
	{
        abstractToSocialGamingAchievementMap : null,
        abstractToSocialGamingAchievementMapInverse : null,

        /**
        * @ignore
        */
        setAbstractToSocialGamingAchievementMap : function( map ) {
            this.abstractToSocialGamingAchievementMap= map;

            // build a reciprocal map.
            this.abstractToSocialGamingAchievementMapInverse= {};
            for( var id in map ) {
                if ( map.hasOwnProperty(id) ) {
                    this.abstractToSocialGamingAchievementMapInverse[ map[id] ]= id;
                }
            }
            return this;
        },

        /**
        * @ignore
        */
        getAbstractToSocialGamingAchievementTranslation : function( achievementID ) {
            /**
             * If a translation map for abstract in-game achievements has been set, translate achievementID from
             * abstract to SocialGamingService.
             */
            if (this.abstractToSocialGamingAchievementMap) {
                var socialGamingAchievementID = this.abstractToSocialGamingAchievementMap[achievementID];
                if (socialGamingAchievementID) {
                    console.log("Abstract achieventID='" + achievementID + "' turned to '" + socialGamingAchievementID + "'");
                    achievementID = socialGamingAchievementID;
                } else {
                    console.log("Something may be wrong: abstract achievementID: '" + achievementID + "' w/o translation.")
                }
            }

            return achievementID;
        },

		/**
		* Request to retrieve the scores of all friends of a given user.
		* @param {string} [leaderboardID] The id of the leaderboard to request the scores for.
		* @param {string} [userID] The id of the user. If null or undefined is passed, the currently logged in user id is used.
		* @see CocoonJS.SocialGaming.onRequestUserAndFriendsScoresSucceed
		* @see CocoonJS.SocialGaming.onRequestUserAndFriendsScoresFailed
		*/
		requestUserAndFriendsScores : function(leaderboardID, userID)
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "requestUserAndFriendsScores", arguments, true);
			}
		},

		/**
		* Request to retrieve the score of a user.
		* @param {string} [leaderboardID] The id of the scores leaderboard to retireve the score from. If null or underfined is passed, the "leadeboard" id will be used.
		* @param {string} [userID] The id of the user to retireve the score from. If null or undefined is passed, the currently logged in user id is used.
		* @see CocoonJS.SocialGaming.onRequestUserScoreSucceed
		* @see CocoonJS.SocualGaming.onRequestUserScoreFailed
		*/
		requestUserScore : function(leaderboardID, userID)
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "requestUserScore", arguments, true);
			}
		},

		/**
		* Request to the server the score of a user.
		* @param {number} [score] the score to submit
		* @param {string} [leaderboardID] The id of the scores leaderboard to submit the score to. If null or underfined is passed, the "leadeboard" id will be used.
		* @param {string} [userID] The id of the user to submit the score for. If null or undefined is passed, the currently logged in user id is used.
		* @see CocoonJS.SocialGaming.onSubmitUserScoreSucceed
		* @see CocoonJS.SocualGaming.onSubmitUserScoreFailed
		*/
		submitUserScore : function(score, leaderboardID, userID)
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "submitUserScore", arguments, true);
			}
		},
		/**
		* Shows the leaderboard using a platform dependant view.
		* @param {string} [leaderboardID] The id of the scores leaderboard to show the view for. If null or underfined is passed, the "leadeboard" id will be used.
		* @see CocoonJS.SocialGaming.onLeaderboardViewClosed
		*/
		showLeaderboardView : function(leaderboardID)
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "showLeaderboardView", arguments, true);
			}
		},

		/**
		* Request to retrieve the user achievements. The request can be monitored using the {@link CocoonJS.SocialGaming.onRequestUserAchievementsSucceed} and {@link CocoonJS.Social.onRequestUserAchievementsFailed} event handlers.
		* @param {string} [userID] The id of the user to retireve the achievements from. if null/undefined/"" is specified, the currently logged in user is assumed.
		* @see CocoonJS.SocialGaming.onRequestUserAchievementsSucceed
		* @see CocoonJS.SocialGaming.onRequestUserAchievementsFailed
		*/
		requestUserAchievements : function(userID)
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "requestUserAchievements", arguments, true);
			}
		},

		/**
		* Request to retrieve all the achievements. The request can be monitored using the {@link CocoonJS.SocialGaming.onRequestAllAchievementsSucceed} and {@link CocoonJS.Social.onRequestAllAchievementsFailed} event handlers.
		* @see CocoonJS.SocialGaming.onRequestAllAchievementsSucceed
		* @see CocoonJS.SocialGaming.onRequestAllAchievementsFailed
		*/
		requestAllAchievements : function()
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "requestAllAchievements", arguments, true);
			}
		},

		/**
		* Request to retrieve the information about an achievement. 
		* @param {string} achievementID The id of the achievement to get the information for.
		* @param {CocoonJS.Social.ImageSizeType} [imageSizeType] The size of the image. One of the possible values among the ones in the {@link CocoonJS.Social.ImageSizeType}
		*/
		requestAchievementInfo : function(achievementID)
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "requestAchievementInfo", arguments, true);
			}
		},

		/**
		* Submits an achievement to the server. If the process fails, the achievement is stored to submit it later.
		* @param {string} [achievementID] the achievement identifier
		* @param {number} [percentComplete] an optional number between 0 and 100 that indicates a completion percentage.
		* @see CocoonJS.SocialGaming.onSubmitAchievementSucceed
		* @see CocoonJS.SocualGaming.onSubmitAchievementFailed
		*/
        submitUserAchievement:function (achievementID, userID) {
            achievementID = this.getAbstractToSocialGamingAchievementTranslation(achievementID);

            if (this.nativeExtensionObjectAvailable) {
                return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "submitUserAchievement", arguments, true);
            }
        },

		/**
		* Shows the achievements using a platform dependant view.
		* @see CocoonJS.SocialGaming.onAchievementsViewClosed
		*/
		showUserAchievementsView : function(userID)
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "showUserAchievementsView", arguments, true);
			}
		},

		/**
		* Resets all the achievements of the current user
		* @param {string} [userID] The id of the user to reset the achievements for. If null/undefined/"", the logged in user is assumed.
		* @see CocoonJS.SocialGaming.onResetAchievementsSucceed
		* @see CocoonJS.SocualGaming.onResetAchievementsFailed
		*/
		resetUserAchievements : function(userID)
		{
			if (this.nativeExtensionObjectAvailable)
			{
				return CocoonJS.makeNativeExtensionObjectFunctionCall(this.nativeExtensionName, "resetUserAchievements", arguments, true);
			}
		}
	};

	/**
    * @ignore
    */
	CocoonJS.extend(CocoonJS.SocialGaming, CocoonJS.Social);

	/**
	* The data structure that represents the information of the user score in the application.
	* @namespace
	* @constructor
	* @param {string} userID The user id.
	* @param {number} score The score of the user.
	* @param {string} userName The name of the user.
	* @param {string} imageURL The url of the user image.
	* @param {number} leaderboardID The id of the leaderboard the score belongs to.
	*/
	CocoonJS.SocialGaming.UserScoreInfo = function(userID, score, userName, imageURL, leaderboardID)
	{
		/**
		* The user id. 
		* @type string
		*/
		this.userID = userID;

		/**
		* The score of the user.
		* @type number
		*/
		this.score = score ? score : 0;

		/**
		* The name of the user.
		* @type string
		*/
        this.userName = userName;

		/**
		* The url of the user image.
		* @type string
		*/
        this.imageURL = imageURL;

        /**
		* The id of the leaderboard the score belongs to.
		* @type number
		*/
        this.leaderboardID = leaderboardID;
	};

	/**
	* The data structure that represents the information of an achievement in the application.
	* @namespace
	* @constructor
	* @param {string} achievementID The id of the achievement info.
	* @param {string} title The title of the achievement.
	* @param {string} description The description of the achievement.
	* @param {string} imageURL The url to the image representing the achievement.
	* @param {number} points The points value of the achievement
	*/
	CocoonJS.SocialGaming.AchievementInfo = function(achievementID, title, description, imageURL, points)
	{
		/**
		* The id of the achievement info.
		* @type string
		*/
		this.achievementID = achievementID;

		/**
		* The title of the achievement.
		* @type string
		*/
		this.title = title;

		/**
		* The description of the achievement.
		* @type string
		*/
		this.description = description;

		/**
		* The url to the image representing the achievement.
		* @type string
		*/
		this.imageURL = imageURL;

		/**
		* The points value of the achievement
		* @type number
		*/
		this.points = points ? points : 0;
	};

})();

/////////////////////////////////////////
// COCOONJS_SOCIALGAMING_GAMECENTER.JS //
/////////////////////////////////////////

(function()
{
    // The CocoonJS must exist before creating the extension.
    if (typeof window.CocoonJS === 'undefined' || window.CocoonJS === null) throw("The CocoonJS object must exist and be valid before creating any extension object.");
    if (typeof window.CocoonJS.SocialGaming === 'undefined' || window.CocoonJS === null) throw("The CocoonJS.SocialGaming object must exist and be valid before creating a Game Center extension object.");

	/**
	* This instance represents the extension object to access GameCenter related native functionalities.
	* The data structure for initialization: None.
	* @see CocoonJS.Social
	*/
	CocoonJS.SocialGaming.GameCenter = new CocoonJS.SocialGaming("IDTK_SRV_SOCIAL_GAMECENTER", "SocialGaming.GameCenter");
})();

//////////////////////////////
// COCOONJS_GAMEPAD.JS 		//
//////////////////////////////

(function () {
    // The CocoonJS must exist before creating the extension.
    if (typeof window.CocoonJS === 'undefined' || window.CocoonJS === null) throw("The CocoonJS object must exist and be valid before creating any extension object.");

    /**
     * This namespace represents the functionalities related to OUYA android gaming control.
     * @namespace
     */
    CocoonJS.Gamepad = {};

    CocoonJS.Gamepad.nativeExtensionObjectAvailable = CocoonJS.nativeExtensionObjectAvailable && typeof window.ext.Gamepad !== 'undefined';

    CocoonJS.Gamepad.Indices = {
        BUTTON_0                : 0, 
        BUTTON_1                : 1,
        BUTTON_2                : 2,
        BUTTON_3                : 3,
        BUTTON_LEFT_BUMPER      : 4,
        BUTTON_RIGHT_BUMPER     : 5,
        
        BUTTON_LEFT_TRIGGER     : 6,
        BUTTON_RIGHT_TRIGGER    : 7,
        
        BUTTON_LEFT_JOYSTICK    : 10,
        BUTTON_RIGHT_JOYSTICK   : 11,
        BUTTON_DPAD_UP          : 12,
        BUTTON_DPAD_DOWN        : 13,
        BUTTON_DPAD_LEFT        : 14,
        BUTTON_DPAD_RIGHT       : 15,
        
        AXE_LEFT_JOYSTICK_X     : 0,
        AXE_LEFT_JOYSTICK_Y     : 1,
        AXE_RIGHT_JOYSTICK_X    : 2,
        AXE_RIGHT_JOYSTICK_Y    : 3
    };

    // If the extension is present and the navigator does not provide the gamepad API:
    // 1.- Add the getGamepads function to the navigator object.
    // 2.- Replace the window add and remove event listener functions to call to the extension for the gamepad related events.
    var systemSupportsGamepads = navigator["getGamepads"] || navigator["webkitGetGamepads"];
    if (CocoonJS.Gamepad.nativeExtensionObjectAvailable && !systemSupportsGamepads)
    {
        navigator.getGamepads = function()
        {
            return window.ext.Gamepad.makeCall("getGamepads");
        };

        CocoonJS.Gamepad.originalWindowAddEventListener = window.addEventListener;
        CocoonJS.Gamepad.originalWindowRemoveEventListener = window.removeEventListener;

        window.addEventListener = function(eventName, callback)
        {
            console.log("The new window.addEventListener has been called.");
            if (eventName === "gamepadconnected" || eventName === "gamepaddisconnected")
            {
                window.ext.Gamepad.addEventListener(eventName, callback);
            }
            else
            {
                var argumentsArray = Array.prototype.slice.call(arguments);
                CocoonJS.Gamepad.originalWindowAddEventListener.apply(window, argumentsArray);
            }
        };
        window.removeEventListener = function(eventName, callback)
        {
            console.log("The new window.removeEventListener has been called.");
            if (eventName === "gamepadconnected" || eventName === "gamepaddisconnected")
            {
                window.ext.Gamepad.removeEventListener(eventName, callback);
            }
            else
            {
                var argumentsArray = Array.prototype.slice.call(arguments);
                CocoonJS.Gamepad.originalWindowRemoveEventListener.apply(window, argumentsArray);
            }
        };
    }
})();

//////////////////////////////
// COCOONJS_NOTIFICATION.JS //
//////////////////////////////

(function()
{
    // The CocoonJS must exist before creating the extension.
    if (typeof window.CocoonJS === 'undefined' || window.CocoonJS === null) throw("The CocoonJS object must exist and be valid before creating any extension object.");

    /**
    * This namespace represents the CocoonJS Notification extension.
    * @namespace
    */
    CocoonJS.Notification = {};

    CocoonJS.Notification.nativeExtensionObjectAvailable = CocoonJS.nativeExtensionObjectAvailable && typeof window.ext.IDTK_SRV_NOTIFICATION !== 'undefined';

	/**
	* The data structure that represents the information of a local notification.
	* @namespace
	* @constructor
	* @param {string} message The notification message.
	* @param {boolean} soundEnabled A flag that indicates if the sound should be enabled for the notification.
	* @param {number} badgeNumber The number that will appear in the badge of the application icon in the home screen.
	* @param {object} userData The JSON data to attached to the notification.
	* @param {string} contentBody The body content to be showed in the expanded notification information.
	* @param {string} contentTitle The title to be showed in the expanded notification information.
	* @param {number} date Time in millisecs from 1970 when the notification will be fired.
	*/
	CocoonJS.Notification.LocalNotification = function(message, soundEnabled, badgeNumber, userData, contentBody, contentTitle, scheduleTime)
	{
		/**
		* The notification message.
		* @field
		* @type string
		*/
		this.message = message;

		/**
		* A flag that indicates if the sound should be enabled for the notification.
		* @field
		* @type boolean
		*/
		this.soundEnabled = soundEnabled;

		/**
		* (iOS only) The number that will appear in the badge of the application icon in the home screen.
		* @field
		* @type number
		*/
		this.badgeNumber = badgeNumber;

		/**
		* The JSON data to attached to the notification.
		* @field
		* @type object
		*/
		this.userData = userData;

		/**
		* (Android only) The body content to be showed in the expanded notification information.
		* @field
		* @type string
		*/
		if (contentBody !== undefined)
			this.contentBody = contentBody;
		else
			this.contentBody = "";

		/**
		* (Android only) The title to be showed in the expanded notification information.
		* @field
		* @type string
		*/
		if (contentTitle !== undefined)
			this.contentTitle = contentTitle;
		else
			this.contentTitle = "";

		/**
		* Time in millisecs from 1970 when the local notification will be fired
		* @field
		* @type number
		*/
		var currentTime = new Date().getTime();
		if (scheduleTime !== undefined){
			this.scheduleTime = scheduleTime;
		}else{
			this.scheduleTime = currentTime;
		}
	};

	/**
	* The data structure that represents the information of a push notification.
	* @namespace
	* @constructor
	* @param {string} message The notification message.
	* @param {boolean} soundEnabled A flag that indicates if the sound should be enabled for the notification.
	* @param {number} badgeNumber The number that will appear in the badge of the application icon in the home screen.
	* @param {object} userData The JSON data to attached to the notification.
	* @param {array} channels An array containing the channels names this notification will be delivered to.
	* @param {number} expirationTime A time in seconds from 1970 when the notification is no longer valid and will not be delivered in case it has not already been delivered.
	* @param {number} expirationTimeInterval An incremental ammount of time in from now when the notification is no longer valid and will not be delivered in case it has not already been delivered.
	*/
	CocoonJS.Notification.PushNotification = function(message, soundEnabled, badgeNumber, userData, channels, expirationTime, expirationTimeInterval)
	{
		/**
		* The notification message.
		* @field
		* @type string
		*/
		this.message = message;

		/**
		* A flag that indicates if the sound should be enabled for the notification.
		* @field
		* @type boolean
		*/
		this.soundEnabled = soundEnabled;

		/**
		* The number that will appear in the badge of the application icon in the home screen.
		* @field
		* @type number
		*/
		this.badgeNumber = badgeNumber;

		/**
		* The JSON data to attached to the notification.
		* @field
		* @type object
		*/
		this.userData = userData

		/**
		* An array containing the channels names this notification will be delivered to.
		* @field
		* @type array
		*/
		this.channels = channels;

		/**
		* A time in seconds from 1970 when the notification is no longer valid and will not be delivered in case it has not already been delivered.
		* @field
		* @type number
		*/
		if (expirationTime !== undefined)
			this.expirationTime = expirationTime;
		else
			this.expirationTime = 0;

		/**
		* An incremental ammount of time in from now when the notification is no longer valid and will not be delivered in case it has not already been delivered.
		* @field
		* @type number
		*/
		if (expirationTimeInterval !== undefined)
			this.expirationTimeInterval = expirationTimeInterval;
		else
			this.expirationTimeInterval = 0;
	};

	/**
	* Register to be able to receive push notifications. 
	* The registration process is controlled using the {@link CocoonJS.Notification.onRegisterForPushNotificationsSucceed} and {@link CocoonJS.Notification.onRegisterForPushNotificationsFailed} event handlers.
	* @function
	* @see {CocoonJS.Notification.onRegisterForPushNotificationsSucceed}
	* @see {CocoonJS.Notification.onRegisterForPushNotificationsFailed}
	*/ 
	CocoonJS.Notification.registerForPushNotifications = function()
	{
		if (CocoonJS.Notification.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_NOTIFICATION", "registerForPushNotifications", arguments, true);
		}
	};

	/**
	* Unregister from receiving push notifications.
	* The unregistration process is controlled using the {@link CocoonJS.Notification.onUnregisterForPushNotificationsSucceed} event handler.
	* @function
	* @see CocoonJS.Notification.onUnregisterForPushNotificationsSucceed
	*/ 
	CocoonJS.Notification.unregisterForPushNotifications = function()
	{
		if (CocoonJS.Notification.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_NOTIFICATION", "unregisterForPushNotifications", arguments, true);
		}
	};

	/**
	* Cancel the last sent local notification. 
	* The last sent local notification will be remove from the notifications bar.
	* @function
	*/ 
	CocoonJS.Notification.cancelLastSentLocalNotificiation = function()
	{
		if (CocoonJS.Notification.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_NOTIFICATION", "cancelLocalNotification", arguments, true);
		}
	};

	/**
	* Cancel all sent local notifications. 
	* All the notifications will ve removed from the notifications bar.
	* @function
	*/ 
	CocoonJS.Notification.cancelAllLocalNotifications = function()
	{
		if (CocoonJS.Notification.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_NOTIFICATION", "cancelAllLocalNotifications", arguments, true);
		}
	};

	/**
	* Send a local notification.
	* @function
	* @param {CocoonJS.Notification.LocalNotification} localNotification The local notification to be sent.
	*/ 
	CocoonJS.Notification.sendLocalNotification = function(localNotification)
	{
		if (CocoonJS.Notification.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_NOTIFICATION", "sendLocalNotification", arguments, true);
		}
	};

	/**
	* Subscribe to a channel in order to receive notifications targeted to that channel.
	* @function
	* @param {string} channel The channel id to subscribe to.
	*/ 
	CocoonJS.Notification.subscribeToChannel = function(channel)
	{
		if (CocoonJS.Notification.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_NOTIFICATION", "subscribe", arguments, true);
		}
	};

	/**
	* Unsubscribe from a channel in order to stop receiving notifications targeted to it.
	* @function
	* @param {string} channel The channel id to unsubscribe from.
	*/ 
	CocoonJS.Notification.unsubscribeFromChannel = function(channel)
	{
		if (CocoonJS.Notification.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_NOTIFICATION", "unsubscribe", arguments, true);
		}
	};

	/**
	* Send a push notification.
	* @function
	* @param {CocoonJS.Notification.PushNotification} pushNotification The push notification object to be sent.
	* @see CocoonJS.Notification.onPushNotificationDeliverySucceed
	* @see CocoonJS.Notification.onPushNotificationDeliveryFailed
	*/ 
	CocoonJS.Notification.sendPushNotification = function(pushNotification)
	{
		if (CocoonJS.Notification.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_NOTIFICATION", "sendPushNotification", arguments, true);
		}
	};

	/**
	* (iOS only) Set the badge number for this application. 
	* This is useful if you want to modify the badge number set by a notification.
	* @function
	* @param {number} badgeNumber The number of the badge.
	*/ 
	CocoonJS.Notification.setBadgeNumber = function(badgeNumber)
	{
		if (CocoonJS.Notification.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_NOTIFICATION", "setBadgeNumber", arguments);
		}
	};

	/**
	* (iOS only) Returns the current badge number.
	* @function
	* @returns {number} The badge number.
	*/ 
	CocoonJS.Notification.getBadgeNumber = function()
	{
		if (CocoonJS.Notification.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_NOTIFICATION", "getBadgeNumber", arguments);
		}
	};

	/**
	* Returns the last received user data from a Local notification.
	* @function
	* @returns {object} The last received user data from a Local notification.
	*/ 
	CocoonJS.Notification.getLastReceivedLocalNotificationData = function()
	{
		if (CocoonJS.Notification.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_NOTIFICATION", "getLastReceivedLocalNotificationData", arguments);
		}
	};

	/**
	* Returns the last received user data from a Push notification.
	* @function
	* @returns {object} The last received user data from a Push notification.
	*/ 
	CocoonJS.Notification.getLastReceivedPushNotificationData = function()
	{
		if (CocoonJS.Notification.nativeExtensionObjectAvailable)
		{
			return CocoonJS.makeNativeExtensionObjectFunctionCall("IDTK_SRV_NOTIFICATION", "getLastReceivedPushNotificationData", arguments);
		}
	};

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the registration for push notification succeeds.
    * The callback function does not receive any parameter.
    * @static
    * @event
    * @param {string} token The token (apid or device token) received at registration time.
    * @memberOf CocoonJS.Notification
    */
	CocoonJS.Notification.onRegisterForPushNotificationsSucceed = new CocoonJS.EventHandler("IDTK_SRV_NOTIFICATION", "Notification", "pushNotificationServiceRegistered"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the unregistration for push notifications succeeds.
    * The callback function does not receive any parameter.
    * @static
    * @event
    * @memberOf CocoonJS.Notification
    */
	CocoonJS.Notification.onUnregisterForPushNotificationsSucceed = new CocoonJS.EventHandler("IDTK_SRV_NOTIFICATION", "Notification", "pushNotificationServiceUnregistered"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the registration for push notifications fails.
    * The callback function receives a parameter with error information.
    * @static
    * @event
    * @param {string} msg The error message.
    */
	CocoonJS.Notification.onRegisterForPushNotificationsFailed = new CocoonJS.EventHandler("IDTK_SRV_NOTIFICATION", "Notification", "pushNotificationServiceFailedToRegister"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when a push notification is received.
    * The callback function receives a parameter with the userData of the received notification.
    * @static
    * @event
    * @param {object} userData An object with the notification userData information.
    */
	CocoonJS.Notification.onPushNotificationReceived = new CocoonJS.EventHandler("IDTK_SRV_NOTIFICATION", "Notification", "pushNotificationReceived"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when a local notification is received.
    * The callback function receives a parameter with the userData of the received notification.
    * @static
    * @event
    * @param {object} userData An object with the notification userData information.
    */
	CocoonJS.Notification.onLocalNotificationReceived = new CocoonJS.EventHandler("IDTK_SRV_NOTIFICATION", "Notification", "localNotificationReceived"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when a notification is successfully delivered.
    * The callback function receives a parameter with the notificationId of the delivered notification.
    * @static
    * @event
    * @param {string} userData A string with the notification userData information.
    */
	CocoonJS.Notification.onPushNotificationDeliverySucceed = new CocoonJS.EventHandler("IDTK_SRV_NOTIFICATION", "Notification", "pushNotificationSuccessfullyDelivered"); 

    /**
    * This {@link CocoonJS.EventHandler} object allows listening to events called when the delivery of push a notification fails.
    * The callback function receives a parameter with error information.
    * @static
    * @event
    * @param {string} msg The error message.
    */
	CocoonJS.Notification.onPushNotificationDeliveryFailed = new CocoonJS.EventHandler("IDTK_SRV_NOTIFICATION", "Notification", "pushNotificationDeliveryError"); 

})();

/////////////////
// PATHFIND.JS //
/////////////////

// Pathfind.js
// Written by Ashley Gullen
// Copyright (c) 2013 Scirra Ltd.

// A* pathfinding javascript implementation

(function() {
	
	var PF_CLEAR = 0;
	var PF_OBSTACLE = 32767;
	
	function node()
	{
		this.parent = null;
		
		this.x = 0;
		this.y = 0;

		this.f = 0;
		this.g = 0;
		this.h = 0;
	};
	
	var nodeCache = [];			// for recycling nodes
	
	function allocNode()
	{
		var ret;
		
		if (nodeCache.length)
			ret = nodeCache.pop();
		else
			ret = new node();
			
		ret.parent = null;
		ret.x = 0;
		ret.y = 0;
		ret.f = 0;
		ret.g = 0;
		ret.h = 0;
		return ret;
	};
	
	function freeNode(n)
	{
		if (nodeCache.length < 64000)
			nodeCache.push(n);
	};
	
	function resultNode(x_, y_)
	{
		this.x = x_ || 0;
		this.y = y_ || 0;
	};
	
	var resultNodeCache = [];			// for recycling resultNodes
	
	function allocResultNode()
	{
		if (resultNodeCache.length)
			return resultNodeCache.pop();
		else
			return new resultNode(0, 0);
	};
	
	function freeResultNode(n)
	{
		if (resultNodeCache.length < 10000)
			resultNodeCache.push(n);
	};
	
	var workersSupported = (typeof Worker !== "undefined");
	var isInWebWorker = (typeof document === "undefined");		// no DOM in a worker
	var myInstance = null;										// single pathfinder instance for worker
	
	if (isInWebWorker)
	{
		self.addEventListener("message", function (e)
		{
			var d = e.data;
			
			if (!d)
				return;		// could be empty postMessage() to start worker
			
			if (d.cmd === "init")
			{
				if (!myInstance)
					myInstance = new pathfinder();
					
				myInstance.init(d.hcells, d.vcells, d.data, d.diagonals);
			}
			else if (d.cmd === "find")
			{
				// receive a pathfind job, process it them dispatch result
				myInstance.pathEnd.parent = null;
				myInstance.targetX = d.endX;
				myInstance.targetY = d.endY;
				
				if (myInstance.doLongFindPath(d.startX, d.startY))
				{
					self.postMessage({ cmd: "result", pathList: myInstance.pathList });
				}
				else
				{
					self.postMessage({ cmd: "result", pathList: null });
				}
			}
			else if (d.cmd === "setdiag")
			{
				// update diagonalsEnabled flag
				myInstance.diagonalsEnabled = d.diagonals;
			}
			
		}, false);
	}
	
	function pathfinder()
	{
		this.hcells = 0;
		this.vcells = 0;
		
		this.pathEnd = allocNode();
		
		this.cells = null;
		this.openList = [];
		this.closedList = [];
		this.closedCache = {};
		this.pathList = [];
		
		this.currentNode = null;
		this.targetX = 0;
		this.targetY = 0;
		this.diagonalsEnabled = true;
		
		this.worker = null;
		this.workerQueue = [];		// jobs awaiting completion from worker in order of requests made
		this.workerRecycle = [];
		
		var self = this;
		var i, len;
		
		if (workersSupported && !isInWebWorker)
		{
			// Create worker and receive results of pathfind jobs from it
			this.worker = new Worker("pathfind.js");
			
			this.worker.addEventListener("message", function (e) {
			
				if (!e || !e.data)
					return;
				
				if (e.data.cmd === "result")
				{
					if (e.data.pathList)
					{
						for (i = 0, len = self.pathList.length; i < len; i++)
							freeResultNode(self.pathList[i]);
						
						self.pathList = e.data.pathList;
						self.workerQueue[0].success();
					}
					else
						self.workerQueue[0].fail();
						
					self.workerRecycle.push(self.workerQueue.shift());
				}
			}, false);
			
			this.worker.addEventListener("error", function (e) {
				console.error(e);
			}, false);
			
			this.worker.postMessage(null);
		}
	};
	
	pathfinder.prototype.init = function (hcells_, vcells_, data_, diagonals_)
	{
		this.hcells = hcells_;
		this.vcells = vcells_;
		this.cells = data_;
		this.diagonalsEnabled = diagonals_;
		
		if (workersSupported && !isInWebWorker)
		{
			this.worker.postMessage({
				cmd: "init",
				hcells: hcells_,
				vcells: vcells_,
				diagonals: diagonals_,
				data: data_
			});
		}
	};
	
	pathfinder.prototype.isReady = function ()
	{
		return !!this.cells;
	};
	
	pathfinder.prototype.setDiagonals = function (d)
	{
		if (this.diagonalsEnabled === d)
			return;
		
		this.diagonalsEnabled = d;
		
		if (workersSupported && !isInWebWorker)
		{
			this.worker.postMessage({
				cmd: "setdiag",
				diagonals: d,
			});
		}
	};
	
	pathfinder.prototype.at = function (x_, y_)
	{
		if (x_ < 0 || y_ < 0 || x_ >= this.hcells || y_ >= this.vcells)
			return PF_OBSTACLE;
			
		return this.cells[x_][y_];
	};
	
	pathfinder.prototype.findPath = function (startX, startY, endX, endY, successCallback, failCallback)
	{
		if (!this.cells)
		{
			// not yet initialised
			failCallback();
			return;
		}
		
		startX = Math.floor(startX);
		startY = Math.floor(startY);
		endX = Math.floor(endX);
		endY = Math.floor(endY);
		
		this.targetX = endX;
		this.targetY = endY;
		this.pathEnd.parent = null;
		
		// Check the box made by the start and dest cells.
		// If the complete box is empty, allow a direct move to target.
		var minX = Math.min(startX, endX);
		var maxX = Math.max(startX, endX);
		var minY = Math.min(startY, endY);
		var maxY = Math.max(startY, endY);
		
		// Path goes out of bounds: no calculable path
		if (minX < 0 || minY < 0 || maxX >= this.hcells || maxY >= this.vcells)
		{
			failCallback();
			return;
		}
		
		var x, y, i, len, c, h, n;

		if (this.diagonalsEnabled)
		{
			var canMoveDirect = true;
			
			for (x = minX; x <= maxX; x++)
			{
				for (y = minY; y <= maxY; y++)
				{
					if (this.cells[x][y] !== 0)
					{
						canMoveDirect = false;
						
						// Break both loops
						x = maxX + 1;
						break;
					}
				}
			}

			// A "direct" path is available (box is empty)
			if (canMoveDirect)
			{
				for (i = 0, len = this.pathList.length; i < len; i++)
					freeResultNode(this.pathList[i]);
				this.pathList.length = 0;
			
				this.pathEnd.x = endX;
				this.pathEnd.y = endY;
				this.pathEnd.parent = null;
				n = allocResultNode();
				n.x = endX;
				n.y = endY;
				this.pathList.push(n);
				successCallback();
				return;
			}
		}
		
		if (workersSupported)
		{
			// recycle objects in the worker queue
			if (this.workerRecycle.length)
				h = this.workerRecycle.pop();
			else
				h = {};
			
			h.success = successCallback;
			h.fail = failCallback;
			
			// dispatch the heavy lifting to the worker thread
			this.workerQueue.push(h);

			this.worker.postMessage({
				cmd: "find",
				startX: startX,
				startY: startY,
				endX: endX,
				endY: endY
			});
		}
		else
		{
			// no web worker support, just run on main thread
			if (this.doLongFindPath(startX, startY))
				successCallback();
			else
				failCallback();
		}
	};
		
	pathfinder.prototype.doLongFindPath = function (startX, startY)
	{
		var i, len, c, n, p, lastDir = 8, curDir = -1, addNode;
		for (i = 0, len = this.openList.length; i < len; i++)
			freeNode(this.openList[i]);
		for (i = 0, len = this.closedList.length; i < len; i++)
			freeNode(this.closedList[i]);
		for (i = 0, len = this.pathList.length; i < len; i++)
			freeResultNode(this.pathList[i]);
		this.openList.length = 0;
		this.closedList.length = 0;
		this.closedCache = {};
		this.pathList.length = 0;

		// Add the start node to the open list
		var startNode = allocNode();
		startNode.x = startX;
		startNode.y = startY;

		this.openList.push(startNode);
		var obsLeft = false, obsTop = false, obsRight = false, obsBottom = false;
		var diagonals = this.diagonalsEnabled;
		
		// While there are nodes on the open list
		while (this.openList.length)
		{
			// Move the best F value to closed list
			c = this.openList.shift();
			this.closedList.unshift(c);
			this.closedCache[((c.x << 16) + c.y).toString()] = true;

			// Are we there yet?
			if (c.x === this.targetX && c.y === this.targetY)
			{
				this.pathEnd.parent = c.parent;
				this.pathEnd.x = c.x;
				this.pathEnd.y = c.y;
				
				// Link up the whole path to an indexable array
				p = this.pathEnd;
				
				while (p)
				{
					// filter redundant nodes in straight lines
					if (this.pathList.length === 0)
					{
						addNode = true;
						
						if (p.parent)
						{
							lastDir = this.nodeDirection(p, p.parent);
							curDir = lastDir;
						}
					}
					else if (!p.parent)
						addNode = false;
					else 
					{
						curDir = this.nodeDirection(p, p.parent);
						addNode = (curDir !== lastDir);
					}
					
					if (addNode)
					{
						n = allocResultNode();
						n.x = p.x;
						n.y = p.y;
						this.pathList.unshift(n);
						lastDir = curDir;
					}
					
					p = p.parent;
				}
				
				return true;
			}

			// Get current node
			this.currentNode = c;
			var x = c.x;
			var y = c.y;
			
			var obsLeft = (this.at(x - 1, y) === PF_OBSTACLE);
			var obsTop = (this.at(x, y - 1) === PF_OBSTACLE);
			var obsRight = (this.at(x + 1, y) === PF_OBSTACLE);
			var obsBottom = (this.at(x, y + 1) === PF_OBSTACLE);

			// Check adjacent 8 nodes.  No diagonals allowed if either cell being crossed is obstacle.
			if (!obsLeft)
				this.addCellToOpenList(x - 1, y, 10);

			if (diagonals && !obsLeft && !obsTop)
				this.addCellToOpenList(x - 1, y - 1, 14);

			if (!obsTop)
				this.addCellToOpenList(x, y - 1, 10);

			if (diagonals && !obsTop && !obsRight)
				this.addCellToOpenList(x + 1, y - 1, 14);

			if (!obsRight)
				this.addCellToOpenList(x + 1, y, 10);

			if (diagonals && !obsRight && !obsBottom)
				this.addCellToOpenList(x + 1, y + 1, 14);

			if (!obsBottom)
				this.addCellToOpenList(x, y + 1, 10);

			if (diagonals && !obsBottom && !obsLeft)
				this.addCellToOpenList(x - 1, y + 1, 14);
		}
		
		return false;
	};
	
	pathfinder.prototype.insertToOpenList = function (c)
	{
		var i, len;
		
		// Needs to go at end
		if (c.f >= this.openList[this.openList.length - 1].f)
		{
			this.openList.push(c);
		}
		else
		{
			for (i = 0, len = this.openList.length; i < len; i++)
			{
				if (c.f < this.openList[i].f)
				{
					this.openList.splice(i, 0, c);
					break;
				}
			}
		}
	};
	
	pathfinder.prototype.addCellToOpenList = function (x_, y_, g_)
	{
		// Ignore if cell on closed list
		if (this.closedCache.hasOwnProperty(((x_ << 16) + y_).toString()))
			return;
		
		var i, len, c;
		
		// Cell costs can be increased by changing the number in the map
		var curCellCost = this.at(x_, y_);

		// Is this cell already on the open list?
		for (i = 0, len = this.openList.length; i < len; i++)
		{
			c = this.openList[i];
			
			if (x_ === c.x && y_ === c.y)
			{
				// Is this a better path?
				if (this.currentNode.g + g_ + curCellCost < c.g)
				{
					// Update F, G and H and update parent
					c.parent = this.currentNode;
					c.g = this.currentNode.g + g_ + curCellCost;
					c.h = this.estimateH(c.x, c.y);
					c.f = c.g + c.h;

					// This node's F has changed:  Delete it then re-insert it in the right place

					if (this.openList.length === 1)
					{
						// no need to remove then re-insert same node, just leave it there
						return;
					}
					
					this.openList.splice(i, 1);
					this.insertToOpenList(c);
				}

				return;
			}
		}

		// Not on the open list; add it in the right place
		c = allocNode();
		c.x = x_;
		c.y = y_;
		c.h = this.estimateH(x_, y_);
		c.g = this.currentNode.g + g_ + curCellCost;
		c.f = c.h + c.g;
		c.parent = this.currentNode;

		// Insert this node sorted in the open list
		// The loop below won't add new largest F values
		if (!this.openList.length)
		{
			this.openList.push(c);
			return;
		}
		
		this.insertToOpenList(c);
	};
	
	function quickAbs(x)
	{
		return x < 0 ? -x : x;
	};
	
	pathfinder.prototype.estimateH = function (x_, y_)
	{
		var dx = quickAbs(x_ - this.targetX);
		var dy = quickAbs(y_ - this.targetY);

		return dx * 10 + dy * 10;
	};
	
	pathfinder.prototype.nodeDirection = function (a, b)
	{
		var ax = a.x;
		var ay = a.y;
		var bx = b.x;
		var by = b.y;

		if (ax === bx)
		{
			if (by > ay) return 6;
			if (by < ay) return 2;
			if (ay == by) return 8;
		}
		else if (ay === by)
		{
			if (bx > ax) return 4;
			if (by < ax) return 0;
		}
		else
		{
			if (bx < ax && by < ay) return 1;
			if (bx > ax && by < ay) return 3;
			if (bx < ax && by > ay) return 7;
			if (bx > ax && by > ay) return 5;
		}
		return 8;
	};
	
	if (!isInWebWorker)
	{
		window.PF_CLEAR = PF_CLEAR;
		window.PF_OBSTACLE = PF_OBSTACLE;
		window.Pathfinder = pathfinder;
		
		window.ResultNode = resultNode;
		window.allocResultNode = allocResultNode;
		window.freeResultNode = freeResultNode;
	}

})();
(function() {
'use strict';var cr={plugins_:{},behaviors:{}};"function"!==typeof Object.getPrototypeOf&&(Object.getPrototypeOf="object"===typeof"test".__proto__?function(a){return a.__proto__}:function(a){return a.constructor.prototype});
(function(){function a(a,b){this.x=a;this.y=b;cr.seal(this)}function b(a,b,c,d){this.set(a,b,c,d);cr.seal(this)}function c(){this.bly=this.blx=this.bry=this.brx=this.try_=this.trx=this.tly=this.tlx=0;cr.seal(this)}function d(){this.items={};this.item_count=0;this.values_cache=[];this.cache_valid=!0;cr.seal(this)}function e(){this.sum=this.t=this.y=this.c=0;cr.seal(this)}function g(a){this.pts_cache=[];this.set_pts(a);cr.seal(this)}cr.logexport=function(a){window.console&&window.console.log&&window.console.log(a)};
cr.seal=function(a){return a};cr.freeze=function(a){return a};cr.is_undefined=function(a){return"undefined"===typeof a};cr.is_number=function(a){return"number"===typeof a};cr.is_string=function(a){return"string"===typeof a};cr.isPOT=function(a){return 0<a&&0===(a-1&a)};cr.abs=function(a){return 0>a?-a:a};cr.max=function(a,b){return a>b?a:b};cr.min=function(a,b){return a<b?a:b};cr.PI=Math.PI;cr.round=function(a){return a+0.5|0};cr.floor=function(a){return a|0};a.prototype.offset=function(a,b){this.x+=
a;this.y+=b;return this};a.prototype.mul=function(a,b){this.x*=a;this.y*=b;return this};cr.vector2=a;cr.segments_intersect=function(a,b,c,d,e,f,r,g){if(cr.max(a,c)<cr.min(e,r)||cr.min(a,c)>cr.max(e,r)||cr.max(b,d)<cr.min(f,g)||cr.min(b,d)>cr.max(f,g))return!1;var t=e-a+r-c,l=f-b+g-d;a=c-a;b=d-b;e=r-e;f=g-f;g=cr.abs(b*e-f*a);a=a*l-b*t;return cr.abs(e*l-f*t)<=g&&cr.abs(a)<=g};b.prototype.set=function(a,b,c,d){this.left=a;this.top=b;this.right=c;this.bottom=d};b.prototype.width=function(){return this.right-
this.left};b.prototype.height=function(){return this.bottom-this.top};b.prototype.offset=function(a,b){this.left+=a;this.top+=b;this.right+=a;this.bottom+=b;return this};b.prototype.intersects_rect=function(a){return!(a.right<this.left||a.bottom<this.top||a.left>this.right||a.top>this.bottom)};b.prototype.contains_pt=function(a,b){return a>=this.left&&a<=this.right&&b>=this.top&&b<=this.bottom};cr.rect=b;c.prototype.set_from_rect=function(a){this.tlx=a.left;this.tly=a.top;this.trx=a.right;this.try_=
a.top;this.brx=a.right;this.bry=a.bottom;this.blx=a.left;this.bly=a.bottom};c.prototype.set_from_rotated_rect=function(a,b){if(0===b)this.set_from_rect(a);else{var c=Math.sin(b),d=Math.cos(b),e=a.left*c,f=a.top*c,r=a.right*c,c=a.bottom*c,g=a.left*d,t=a.top*d,l=a.right*d,d=a.bottom*d;this.tlx=g-f;this.tly=t+e;this.trx=l-f;this.try_=t+r;this.brx=l-c;this.bry=d+r;this.blx=g-c;this.bly=d+e}};c.prototype.offset=function(a,b){this.tlx+=a;this.tly+=b;this.trx+=a;this.try_+=b;this.brx+=a;this.bry+=b;this.blx+=
a;this.bly+=b;return this};c.prototype.bounding_box=function(a){a.left=cr.min(cr.min(this.tlx,this.trx),cr.min(this.brx,this.blx));a.top=cr.min(cr.min(this.tly,this.try_),cr.min(this.bry,this.bly));a.right=cr.max(cr.max(this.tlx,this.trx),cr.max(this.brx,this.blx));a.bottom=cr.max(cr.max(this.tly,this.try_),cr.max(this.bry,this.bly))};c.prototype.contains_pt=function(a,b){var c=this.trx-this.tlx,d=this.try_-this.tly,e=this.brx-this.tlx,f=this.bry-this.tly,r=a-this.tlx,g=b-this.tly,t=c*c+d*d,l=c*e+
d*f,d=c*r+d*g,w=e*e+f*f,y=e*r+f*g,C=1/(t*w-l*l),c=(w*d-l*y)*C,t=(t*y-l*d)*C;if(0<=c&&0<t&&1>c+t)return!0;c=this.blx-this.tlx;d=this.bly-this.tly;t=c*c+d*d;l=c*e+d*f;d=c*r+d*g;C=1/(t*w-l*l);c=(w*d-l*y)*C;t=(t*y-l*d)*C;return 0<=c&&0<t&&1>c+t};c.prototype.at=function(a,b){switch(a){case 0:return b?this.tlx:this.tly;case 1:return b?this.trx:this.try_;case 2:return b?this.brx:this.bry;case 3:return b?this.blx:this.bly;case 4:return b?this.tlx:this.tly;default:return b?this.tlx:this.tly}};c.prototype.midX=
function(){return(this.tlx+this.trx+this.brx+this.blx)/4};c.prototype.midY=function(){return(this.tly+this.try_+this.bry+this.bly)/4};c.prototype.intersects_segment=function(a,b,c,d){if(this.contains_pt(a,b)||this.contains_pt(c,d))return!0;var e,f,r,g,t;for(t=0;4>t;t++)if(e=this.at(t,!0),f=this.at(t,!1),r=this.at(t+1,!0),g=this.at(t+1,!1),cr.segments_intersect(a,b,c,d,e,f,r,g))return!0;return!1};c.prototype.intersects_quad=function(a){var b=a.midX(),c=a.midY();if(this.contains_pt(b,c))return!0;b=
this.midX();c=this.midY();if(a.contains_pt(b,c))return!0;var d,e,f,r,g,t,l,w;for(l=0;4>l;l++)for(w=0;4>w;w++)if(b=this.at(l,!0),c=this.at(l,!1),d=this.at(l+1,!0),e=this.at(l+1,!1),f=a.at(w,!0),r=a.at(w,!1),g=a.at(w+1,!0),t=a.at(w+1,!1),cr.segments_intersect(b,c,d,e,f,r,g,t))return!0;return!1};cr.quad=c;cr.RGB=function(a,b,c){return Math.max(Math.min(a,255),0)|Math.max(Math.min(b,255),0)<<8|Math.max(Math.min(c,255),0)<<16};cr.GetRValue=function(a){return a&255};cr.GetGValue=function(a){return(a&65280)>>
8};cr.GetBValue=function(a){return(a&16711680)>>16};cr.shallowCopy=function(a,b,c){for(var d in b)b.hasOwnProperty(d)&&(a[d]=b[d]);return a};cr.arrayRemove=function(a,b){var c,d;b=cr.floor(b);if(!(0>b||b>=a.length))if(0===b)a.shift();else if(b===a.length-1)a.pop();else{c=b;for(d=a.length-1;c<d;c++)a[c]=a[c+1];a.length=d}};cr.shallowAssignArray=function(a,b){a.length=b.length;var c,d;c=0;for(d=b.length;c<d;c++)a[c]=b[c]};cr.arrayFindRemove=function(a,b){var c=a.indexOf(b);-1!==c&&cr.arrayRemove(a,
c)};cr.clamp=function(a,b,c){return a<b?b:a>c?c:a};cr.to_radians=function(a){return a/(180/cr.PI)};cr.to_degrees=function(a){return a*(180/cr.PI)};cr.clamp_angle_degrees=function(a){a%=360;0>a&&(a+=360);return a};cr.clamp_angle=function(a){a%=2*cr.PI;0>a&&(a+=2*cr.PI);return a};cr.to_clamped_degrees=function(a){return cr.clamp_angle_degrees(cr.to_degrees(a))};cr.to_clamped_radians=function(a){return cr.clamp_angle(cr.to_radians(a))};cr.angleTo=function(a,b,c,d){return Math.atan2(d-b,c-a)};cr.angleDiff=
function(a,b){if(a===b)return 0;var c=Math.sin(a),d=Math.cos(a),e=Math.sin(b),f=Math.cos(b),c=c*e+d*f;return 1<=c?0:-1>=c?cr.PI:Math.acos(c)};cr.angleRotate=function(a,b,c){var d=Math.sin(a),e=Math.cos(a),f=Math.sin(b),r=Math.cos(b);return Math.acos(d*f+e*r)>c?0<e*f-d*r?cr.clamp_angle(a+c):cr.clamp_angle(a-c):cr.clamp_angle(b)};cr.angleClockwise=function(a,b){var c=Math.sin(a),d=Math.cos(a),e=Math.sin(b),f=Math.cos(b);return 0>=d*e-c*f};cr.rotatePtAround=function(a,b,c,d,e,f){if(0===c)return f?a:
b;var r=Math.sin(c);c=Math.cos(c);a-=d;b-=e;var g=a*r;a=a*c-b*r;b=b*c+g;return f?a+d:b+e};cr.distanceTo=function(a,b,c,d){a=c-a;b=d-b;return Math.sqrt(a*a+b*b)};cr.xor=function(a,b){return!a!==!b};cr.lerp=function(a,b,c){return a+(b-a)*c};cr.hasAnyOwnProperty=function(a){for(var b in a)if(a.hasOwnProperty(b))return!0;return!1};cr.wipe=function(a){for(var b in a)a.hasOwnProperty(b)&&delete a[b]};var f=+new Date;cr.performance_now=function(){if("undefined"!==typeof window.performance){var a=window.performance;
if("undefined"!==typeof a.now)return a.now();if("undefined"!==typeof a.webkitNow)return a.webkitNow();if("undefined"!==typeof a.msNow)return a.msNow()}return Date.now()-f};d.prototype.contains=function(a){return this.items.hasOwnProperty(a.toString())};d.prototype.add=function(a){var b=a.toString();this.items.hasOwnProperty(b)||(this.items[b]=a,this.item_count++,this.cache_valid=!1);return this};d.prototype.remove=function(a){a=a.toString();this.items.hasOwnProperty(a)&&(delete this.items[a],this.item_count--,
this.cache_valid=!1);return this};d.prototype.clear=function(){cr.wipe(this.items);this.item_count=0;this.values_cache.length=0;this.cache_valid=!0;return this};d.prototype.isEmpty=function(){return 0===this.item_count};d.prototype.count=function(){return this.item_count};d.prototype.update_cache=function(){if(!this.cache_valid){this.values_cache.length=this.item_count;var a,b=0;for(a in this.items)this.items.hasOwnProperty(a)&&(this.values_cache[b++]=this.items[a]);this.cache_valid=!0}};d.prototype.values=
function(){this.update_cache();return this.values_cache.slice(0)};d.prototype.valuesRef=function(){this.update_cache();return this.values_cache};cr.ObjectSet=d;e.prototype.add=function(a){this.y=a-this.c;this.t=this.sum+this.y;this.c=this.t-this.sum-this.y;this.sum=this.t};e.prototype.reset=function(){this.sum=this.t=this.y=this.c=0};cr.KahanAdder=e;cr.regexp_escape=function(a){return a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")};g.prototype.set_pts=function(a){this.pts_array=a;this.pts_count=a.length/
2;this.pts_cache.length=a.length;this.cache_height=this.cache_width=-1;this.cache_angle=0};g.prototype.is_empty=function(){return!this.pts_array.length};g.prototype.set_from_quad=function(a,b,c,d,e){this.pts_cache.length=8;this.pts_count=4;var f=this.pts_cache;f[0]=a.tlx-b;f[1]=a.tly-c;f[2]=a.trx-b;f[3]=a.try_-c;f[4]=a.brx-b;f[5]=a.bry-c;f[6]=a.blx-b;f[7]=a.bly-c;this.cache_width=d;this.cache_height=e};g.prototype.set_from_poly=function(a){this.pts_count=a.pts_count;cr.shallowAssignArray(this.pts_cache,
a.pts_cache)};g.prototype.cache_poly=function(a,b,c){if(!(this.cache_width===a&&this.cache_height===b&&this.cache_angle===c)){this.cache_width=a;this.cache_height=b;this.cache_angle=c;var d,e,f,r=0,g=1,t=this.pts_array,l=this.pts_cache;0!==c&&(r=Math.sin(c),g=Math.cos(c));c=0;for(d=this.pts_count;c<d;c++)e=t[2*c]*a,f=t[2*c+1]*b,l[2*c]=e*g-f*r,l[2*c+1]=f*g+e*r}};g.prototype.contains_pt=function(a,b){var c=this.pts_cache;if(a===c[0]&&b===c[1])return!0;var d,e,f,r=this.pts_count,g=c[0],t=g,l=c[1],w=
l;for(d=1;d<r;d++)e=c[2*d],f=c[2*d+1],e<g&&(g=e),e>t&&(t=e),f<l&&(l=f),f>w&&(w=f);e=g-110;var l=l-101,t=t+131,w=w+120,y,C,z=0,x=0;for(d=0;d<r;d++)f=c[2*d],g=c[2*d+1],y=c[2*((d+1)%r)],C=c[2*((d+1)%r)+1],cr.segments_intersect(e,l,a,b,f,g,y,C)&&z++,cr.segments_intersect(t,w,a,b,f,g,y,C)&&x++;return 1===z%2||1===x%2};g.prototype.intersects_poly=function(a,b,c){var d=a.pts_cache,e=this.pts_cache;if(this.contains_pt(d[0]+b,d[1]+c)||a.contains_pt(e[0]-b,e[1]-c))return!0;var f,r,g,t,l,w,y,C,z,x,A,D;f=0;for(r=
this.pts_count;f<r;f++){l=e[2*f];w=e[2*f+1];y=e[2*((f+1)%r)];C=e[2*((f+1)%r)+1];g=0;for(t=a.pts_count;g<t;g++)if(z=d[2*g]+b,x=d[2*g+1]+c,A=d[2*((g+1)%t)]+b,D=d[2*((g+1)%t)+1]+c,cr.segments_intersect(l,w,y,C,z,x,A,D))return!0}return!1};g.prototype.intersects_segment=function(a,b,c,d,e,f){var r=this.pts_cache;if(this.contains_pt(c-a,d-b))return!0;var g,t,l,w,y,C;g=0;for(t=this.pts_count;g<t;g++)if(l=r[2*g]+a,w=r[2*g+1]+b,y=r[2*((g+1)%t)]+a,C=r[2*((g+1)%t)+1]+b,cr.segments_intersect(c,d,e,f,l,w,y,C))return!0;
return!1};cr.CollisionPoly=g;var l="lighter xor copy destination-over source-in destination-in source-out destination-out source-atop destination-atop".split(" ");cr.effectToCompositeOp=function(a){return 0>=a||11<=a?"source-over":l[a-1]};cr.setGLBlend=function(a,b,c){if(c)switch(a.srcBlend=c.ONE,a.destBlend=c.ONE_MINUS_SRC_ALPHA,b){case 1:a.srcBlend=c.ONE;a.destBlend=c.ONE;break;case 3:a.srcBlend=c.ONE;a.destBlend=c.ZERO;break;case 4:a.srcBlend=c.ONE_MINUS_DST_ALPHA;a.destBlend=c.ONE;break;case 5:a.srcBlend=
c.DST_ALPHA;a.destBlend=c.ZERO;break;case 6:a.srcBlend=c.ZERO;a.destBlend=c.SRC_ALPHA;break;case 7:a.srcBlend=c.ONE_MINUS_DST_ALPHA;a.destBlend=c.ZERO;break;case 8:a.srcBlend=c.ZERO;a.destBlend=c.ONE_MINUS_SRC_ALPHA;break;case 9:a.srcBlend=c.DST_ALPHA;a.destBlend=c.ONE_MINUS_SRC_ALPHA;break;case 10:a.srcBlend=c.ONE_MINUS_DST_ALPHA,a.destBlend=c.SRC_ALPHA}};cr.round6dp=function(a){return Math.round(1E6*a)/1E6};cr.equals_nocase=function(a,b){return"string"!==typeof a||"string"!==typeof b||a.length!==
b.length?!1:a===b?!0:a.toLowerCase()===b.toLowerCase()}})();var MatrixArray="undefined"!==typeof Float32Array?Float32Array:Array,glMatrixArrayType=MatrixArray,vec3={},mat3={},mat4={},quat4={};vec3.create=function(a){var b=new MatrixArray(3);a&&(b[0]=a[0],b[1]=a[1],b[2]=a[2]);return b};vec3.set=function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];return b};vec3.add=function(a,b,c){if(!c||a===c)return a[0]+=b[0],a[1]+=b[1],a[2]+=b[2],a;c[0]=a[0]+b[0];c[1]=a[1]+b[1];c[2]=a[2]+b[2];return c};
vec3.subtract=function(a,b,c){if(!c||a===c)return a[0]-=b[0],a[1]-=b[1],a[2]-=b[2],a;c[0]=a[0]-b[0];c[1]=a[1]-b[1];c[2]=a[2]-b[2];return c};vec3.negate=function(a,b){b||(b=a);b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];return b};vec3.scale=function(a,b,c){if(!c||a===c)return a[0]*=b,a[1]*=b,a[2]*=b,a;c[0]=a[0]*b;c[1]=a[1]*b;c[2]=a[2]*b;return c};
vec3.normalize=function(a,b){b||(b=a);var c=a[0],d=a[1],e=a[2],g=Math.sqrt(c*c+d*d+e*e);if(g){if(1===g)return b[0]=c,b[1]=d,b[2]=e,b}else return b[0]=0,b[1]=0,b[2]=0,b;g=1/g;b[0]=c*g;b[1]=d*g;b[2]=e*g;return b};vec3.cross=function(a,b,c){c||(c=a);var d=a[0],e=a[1];a=a[2];var g=b[0],f=b[1];b=b[2];c[0]=e*b-a*f;c[1]=a*g-d*b;c[2]=d*f-e*g;return c};vec3.length=function(a){var b=a[0],c=a[1];a=a[2];return Math.sqrt(b*b+c*c+a*a)};vec3.dot=function(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]};
vec3.direction=function(a,b,c){c||(c=a);var d=a[0]-b[0],e=a[1]-b[1];a=a[2]-b[2];b=Math.sqrt(d*d+e*e+a*a);if(!b)return c[0]=0,c[1]=0,c[2]=0,c;b=1/b;c[0]=d*b;c[1]=e*b;c[2]=a*b;return c};vec3.lerp=function(a,b,c,d){d||(d=a);d[0]=a[0]+c*(b[0]-a[0]);d[1]=a[1]+c*(b[1]-a[1]);d[2]=a[2]+c*(b[2]-a[2]);return d};vec3.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+"]"};
mat3.create=function(a){var b=new MatrixArray(9);a&&(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8]);return b};mat3.set=function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];return b};mat3.identity=function(a){a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=1;a[5]=0;a[6]=0;a[7]=0;a[8]=1;return a};
mat3.transpose=function(a,b){if(!b||a===b){var c=a[1],d=a[2],e=a[5];a[1]=a[3];a[2]=a[6];a[3]=c;a[5]=a[7];a[6]=d;a[7]=e;return a}b[0]=a[0];b[1]=a[3];b[2]=a[6];b[3]=a[1];b[4]=a[4];b[5]=a[7];b[6]=a[2];b[7]=a[5];b[8]=a[8];return b};mat3.toMat4=function(a,b){b||(b=mat4.create());b[15]=1;b[14]=0;b[13]=0;b[12]=0;b[11]=0;b[10]=a[8];b[9]=a[7];b[8]=a[6];b[7]=0;b[6]=a[5];b[5]=a[4];b[4]=a[3];b[3]=0;b[2]=a[2];b[1]=a[1];b[0]=a[0];return b};
mat3.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+"]"};mat4.create=function(a){var b=new MatrixArray(16);a&&(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3],b[4]=a[4],b[5]=a[5],b[6]=a[6],b[7]=a[7],b[8]=a[8],b[9]=a[9],b[10]=a[10],b[11]=a[11],b[12]=a[12],b[13]=a[13],b[14]=a[14],b[15]=a[15]);return b};
mat4.set=function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=a[12];b[13]=a[13];b[14]=a[14];b[15]=a[15];return b};mat4.identity=function(a){a[0]=1;a[1]=0;a[2]=0;a[3]=0;a[4]=0;a[5]=1;a[6]=0;a[7]=0;a[8]=0;a[9]=0;a[10]=1;a[11]=0;a[12]=0;a[13]=0;a[14]=0;a[15]=1;return a};
mat4.transpose=function(a,b){if(!b||a===b){var c=a[1],d=a[2],e=a[3],g=a[6],f=a[7],l=a[11];a[1]=a[4];a[2]=a[8];a[3]=a[12];a[4]=c;a[6]=a[9];a[7]=a[13];a[8]=d;a[9]=g;a[11]=a[14];a[12]=e;a[13]=f;a[14]=l;return a}b[0]=a[0];b[1]=a[4];b[2]=a[8];b[3]=a[12];b[4]=a[1];b[5]=a[5];b[6]=a[9];b[7]=a[13];b[8]=a[2];b[9]=a[6];b[10]=a[10];b[11]=a[14];b[12]=a[3];b[13]=a[7];b[14]=a[11];b[15]=a[15];return b};
mat4.determinant=function(a){var b=a[0],c=a[1],d=a[2],e=a[3],g=a[4],f=a[5],l=a[6],k=a[7],h=a[8],m=a[9],n=a[10],q=a[11],p=a[12],r=a[13],s=a[14];a=a[15];return p*m*l*e-h*r*l*e-p*f*n*e+g*r*n*e+h*f*s*e-g*m*s*e-p*m*d*k+h*r*d*k+p*c*n*k-b*r*n*k-h*c*s*k+b*m*s*k+p*f*d*q-g*r*d*q-p*c*l*q+b*r*l*q+g*c*s*q-b*f*s*q-h*f*d*a+g*m*d*a+h*c*l*a-b*m*l*a-g*c*n*a+b*f*n*a};
mat4.inverse=function(a,b){b||(b=a);var c=a[0],d=a[1],e=a[2],g=a[3],f=a[4],l=a[5],k=a[6],h=a[7],m=a[8],n=a[9],q=a[10],p=a[11],r=a[12],s=a[13],t=a[14],v=a[15],w=c*l-d*f,y=c*k-e*f,C=c*h-g*f,z=d*k-e*l,x=d*h-g*l,A=e*h-g*k,D=m*s-n*r,G=m*t-q*r,F=m*v-p*r,u=n*t-q*s,B=n*v-p*s,H=q*v-p*t,E=1/(w*H-y*B+C*u+z*F-x*G+A*D);b[0]=(l*H-k*B+h*u)*E;b[1]=(-d*H+e*B-g*u)*E;b[2]=(s*A-t*x+v*z)*E;b[3]=(-n*A+q*x-p*z)*E;b[4]=(-f*H+k*F-h*G)*E;b[5]=(c*H-e*F+g*G)*E;b[6]=(-r*A+t*C-v*y)*E;b[7]=(m*A-q*C+p*y)*E;b[8]=(f*B-l*F+h*D)*E;
b[9]=(-c*B+d*F-g*D)*E;b[10]=(r*x-s*C+v*w)*E;b[11]=(-m*x+n*C-p*w)*E;b[12]=(-f*u+l*G-k*D)*E;b[13]=(c*u-d*G+e*D)*E;b[14]=(-r*z+s*y-t*w)*E;b[15]=(m*z-n*y+q*w)*E;return b};mat4.toRotationMat=function(a,b){b||(b=mat4.create());b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];b[4]=a[4];b[5]=a[5];b[6]=a[6];b[7]=a[7];b[8]=a[8];b[9]=a[9];b[10]=a[10];b[11]=a[11];b[12]=0;b[13]=0;b[14]=0;b[15]=1;return b};
mat4.toMat3=function(a,b){b||(b=mat3.create());b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[4];b[4]=a[5];b[5]=a[6];b[6]=a[8];b[7]=a[9];b[8]=a[10];return b};mat4.toInverseMat3=function(a,b){var c=a[0],d=a[1],e=a[2],g=a[4],f=a[5],l=a[6],k=a[8],h=a[9],m=a[10],n=m*f-l*h,q=-m*g+l*k,p=h*g-f*k,r=c*n+d*q+e*p;if(!r)return null;r=1/r;b||(b=mat3.create());b[0]=n*r;b[1]=(-m*d+e*h)*r;b[2]=(l*d-e*f)*r;b[3]=q*r;b[4]=(m*c-e*k)*r;b[5]=(-l*c+e*g)*r;b[6]=p*r;b[7]=(-h*c+d*k)*r;b[8]=(f*c-d*g)*r;return b};
mat4.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],g=a[2],f=a[3],l=a[4],k=a[5],h=a[6],m=a[7],n=a[8],q=a[9],p=a[10],r=a[11],s=a[12],t=a[13],v=a[14];a=a[15];var w=b[0],y=b[1],C=b[2],z=b[3],x=b[4],A=b[5],D=b[6],G=b[7],F=b[8],u=b[9],B=b[10],H=b[11],E=b[12],J=b[13],I=b[14];b=b[15];c[0]=w*d+y*l+C*n+z*s;c[1]=w*e+y*k+C*q+z*t;c[2]=w*g+y*h+C*p+z*v;c[3]=w*f+y*m+C*r+z*a;c[4]=x*d+A*l+D*n+G*s;c[5]=x*e+A*k+D*q+G*t;c[6]=x*g+A*h+D*p+G*v;c[7]=x*f+A*m+D*r+G*a;c[8]=F*d+u*l+B*n+H*s;c[9]=F*e+u*k+B*q+H*t;c[10]=F*
g+u*h+B*p+H*v;c[11]=F*f+u*m+B*r+H*a;c[12]=E*d+J*l+I*n+b*s;c[13]=E*e+J*k+I*q+b*t;c[14]=E*g+J*h+I*p+b*v;c[15]=E*f+J*m+I*r+b*a;return c};mat4.multiplyVec3=function(a,b,c){c||(c=b);var d=b[0],e=b[1];b=b[2];c[0]=a[0]*d+a[4]*e+a[8]*b+a[12];c[1]=a[1]*d+a[5]*e+a[9]*b+a[13];c[2]=a[2]*d+a[6]*e+a[10]*b+a[14];return c};
mat4.multiplyVec4=function(a,b,c){c||(c=b);var d=b[0],e=b[1],g=b[2];b=b[3];c[0]=a[0]*d+a[4]*e+a[8]*g+a[12]*b;c[1]=a[1]*d+a[5]*e+a[9]*g+a[13]*b;c[2]=a[2]*d+a[6]*e+a[10]*g+a[14]*b;c[3]=a[3]*d+a[7]*e+a[11]*g+a[15]*b;return c};
mat4.translate=function(a,b,c){var d=b[0],e=b[1];b=b[2];var g,f,l,k,h,m,n,q,p,r,s,t;if(!c||a===c)return a[12]=a[0]*d+a[4]*e+a[8]*b+a[12],a[13]=a[1]*d+a[5]*e+a[9]*b+a[13],a[14]=a[2]*d+a[6]*e+a[10]*b+a[14],a[15]=a[3]*d+a[7]*e+a[11]*b+a[15],a;g=a[0];f=a[1];l=a[2];k=a[3];h=a[4];m=a[5];n=a[6];q=a[7];p=a[8];r=a[9];s=a[10];t=a[11];c[0]=g;c[1]=f;c[2]=l;c[3]=k;c[4]=h;c[5]=m;c[6]=n;c[7]=q;c[8]=p;c[9]=r;c[10]=s;c[11]=t;c[12]=g*d+h*e+p*b+a[12];c[13]=f*d+m*e+r*b+a[13];c[14]=l*d+n*e+s*b+a[14];c[15]=k*d+q*e+t*b+
a[15];return c};mat4.scale=function(a,b,c){var d=b[0],e=b[1];b=b[2];if(!c||a===c)return a[0]*=d,a[1]*=d,a[2]*=d,a[3]*=d,a[4]*=e,a[5]*=e,a[6]*=e,a[7]*=e,a[8]*=b,a[9]*=b,a[10]*=b,a[11]*=b,a;c[0]=a[0]*d;c[1]=a[1]*d;c[2]=a[2]*d;c[3]=a[3]*d;c[4]=a[4]*e;c[5]=a[5]*e;c[6]=a[6]*e;c[7]=a[7]*e;c[8]=a[8]*b;c[9]=a[9]*b;c[10]=a[10]*b;c[11]=a[11]*b;c[12]=a[12];c[13]=a[13];c[14]=a[14];c[15]=a[15];return c};
mat4.rotate=function(a,b,c,d){var e=c[0],g=c[1];c=c[2];var f=Math.sqrt(e*e+g*g+c*c),l,k,h,m,n,q,p,r,s,t,v,w,y,C,z,x,A,D,G,F;if(!f)return null;1!==f&&(f=1/f,e*=f,g*=f,c*=f);l=Math.sin(b);k=Math.cos(b);h=1-k;b=a[0];f=a[1];m=a[2];n=a[3];q=a[4];p=a[5];r=a[6];s=a[7];t=a[8];v=a[9];w=a[10];y=a[11];C=e*e*h+k;z=g*e*h+c*l;x=c*e*h-g*l;A=e*g*h-c*l;D=g*g*h+k;G=c*g*h+e*l;F=e*c*h+g*l;e=g*c*h-e*l;g=c*c*h+k;d?a!==d&&(d[12]=a[12],d[13]=a[13],d[14]=a[14],d[15]=a[15]):d=a;d[0]=b*C+q*z+t*x;d[1]=f*C+p*z+v*x;d[2]=m*C+r*
z+w*x;d[3]=n*C+s*z+y*x;d[4]=b*A+q*D+t*G;d[5]=f*A+p*D+v*G;d[6]=m*A+r*D+w*G;d[7]=n*A+s*D+y*G;d[8]=b*F+q*e+t*g;d[9]=f*F+p*e+v*g;d[10]=m*F+r*e+w*g;d[11]=n*F+s*e+y*g;return d};
mat4.rotateX=function(a,b,c){var d=Math.sin(b);b=Math.cos(b);var e=a[4],g=a[5],f=a[6],l=a[7],k=a[8],h=a[9],m=a[10],n=a[11];c?a!==c&&(c[0]=a[0],c[1]=a[1],c[2]=a[2],c[3]=a[3],c[12]=a[12],c[13]=a[13],c[14]=a[14],c[15]=a[15]):c=a;c[4]=e*b+k*d;c[5]=g*b+h*d;c[6]=f*b+m*d;c[7]=l*b+n*d;c[8]=e*-d+k*b;c[9]=g*-d+h*b;c[10]=f*-d+m*b;c[11]=l*-d+n*b;return c};
mat4.rotateY=function(a,b,c){var d=Math.sin(b);b=Math.cos(b);var e=a[0],g=a[1],f=a[2],l=a[3],k=a[8],h=a[9],m=a[10],n=a[11];c?a!==c&&(c[4]=a[4],c[5]=a[5],c[6]=a[6],c[7]=a[7],c[12]=a[12],c[13]=a[13],c[14]=a[14],c[15]=a[15]):c=a;c[0]=e*b+k*-d;c[1]=g*b+h*-d;c[2]=f*b+m*-d;c[3]=l*b+n*-d;c[8]=e*d+k*b;c[9]=g*d+h*b;c[10]=f*d+m*b;c[11]=l*d+n*b;return c};
mat4.rotateZ=function(a,b,c){var d=Math.sin(b);b=Math.cos(b);var e=a[0],g=a[1],f=a[2],l=a[3],k=a[4],h=a[5],m=a[6],n=a[7];c?a!==c&&(c[8]=a[8],c[9]=a[9],c[10]=a[10],c[11]=a[11],c[12]=a[12],c[13]=a[13],c[14]=a[14],c[15]=a[15]):c=a;c[0]=e*b+k*d;c[1]=g*b+h*d;c[2]=f*b+m*d;c[3]=l*b+n*d;c[4]=e*-d+k*b;c[5]=g*-d+h*b;c[6]=f*-d+m*b;c[7]=l*-d+n*b;return c};
mat4.frustum=function(a,b,c,d,e,g,f){f||(f=mat4.create());var l=b-a,k=d-c,h=g-e;f[0]=2*e/l;f[1]=0;f[2]=0;f[3]=0;f[4]=0;f[5]=2*e/k;f[6]=0;f[7]=0;f[8]=(b+a)/l;f[9]=(d+c)/k;f[10]=-(g+e)/h;f[11]=-1;f[12]=0;f[13]=0;f[14]=-(2*g*e)/h;f[15]=0;return f};mat4.perspective=function(a,b,c,d,e){a=c*Math.tan(a*Math.PI/360);b*=a;return mat4.frustum(-b,b,-a,a,c,d,e)};
mat4.ortho=function(a,b,c,d,e,g,f){f||(f=mat4.create());var l=b-a,k=d-c,h=g-e;f[0]=2/l;f[1]=0;f[2]=0;f[3]=0;f[4]=0;f[5]=2/k;f[6]=0;f[7]=0;f[8]=0;f[9]=0;f[10]=-2/h;f[11]=0;f[12]=-(a+b)/l;f[13]=-(d+c)/k;f[14]=-(g+e)/h;f[15]=1;return f};
mat4.lookAt=function(a,b,c,d){d||(d=mat4.create());var e,g,f,l,k,h,m,n,q=a[0],p=a[1];a=a[2];g=c[0];f=c[1];e=c[2];c=b[1];h=b[2];if(q===b[0]&&p===c&&a===h)return mat4.identity(d);c=q-b[0];h=p-b[1];m=a-b[2];n=1/Math.sqrt(c*c+h*h+m*m);c*=n;h*=n;m*=n;b=f*m-e*h;e=e*c-g*m;g=g*h-f*c;(n=Math.sqrt(b*b+e*e+g*g))?(n=1/n,b*=n,e*=n,g*=n):g=e=b=0;f=h*g-m*e;l=m*b-c*g;k=c*e-h*b;(n=Math.sqrt(f*f+l*l+k*k))?(n=1/n,f*=n,l*=n,k*=n):k=l=f=0;d[0]=b;d[1]=f;d[2]=c;d[3]=0;d[4]=e;d[5]=l;d[6]=h;d[7]=0;d[8]=g;d[9]=k;d[10]=m;d[11]=
0;d[12]=-(b*q+e*p+g*a);d[13]=-(f*q+l*p+k*a);d[14]=-(c*q+h*p+m*a);d[15]=1;return d};mat4.fromRotationTranslation=function(a,b,c){c||(c=mat4.create());var d=a[0],e=a[1],g=a[2],f=a[3],l=d+d,k=e+e,h=g+g;a=d*l;var m=d*k,d=d*h,n=e*k,e=e*h,g=g*h,l=l*f,k=k*f,f=f*h;c[0]=1-(n+g);c[1]=m+f;c[2]=d-k;c[3]=0;c[4]=m-f;c[5]=1-(a+g);c[6]=e+l;c[7]=0;c[8]=d+k;c[9]=e-l;c[10]=1-(a+n);c[11]=0;c[12]=b[0];c[13]=b[1];c[14]=b[2];c[15]=1;return c};
mat4.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+", "+a[4]+", "+a[5]+", "+a[6]+", "+a[7]+", "+a[8]+", "+a[9]+", "+a[10]+", "+a[11]+", "+a[12]+", "+a[13]+", "+a[14]+", "+a[15]+"]"};quat4.create=function(a){var b=new MatrixArray(4);a&&(b[0]=a[0],b[1]=a[1],b[2]=a[2],b[3]=a[3]);return b};quat4.set=function(a,b){b[0]=a[0];b[1]=a[1];b[2]=a[2];b[3]=a[3];return b};
quat4.calculateW=function(a,b){var c=a[0],d=a[1],e=a[2];if(!b||a===b)return a[3]=-Math.sqrt(Math.abs(1-c*c-d*d-e*e)),a;b[0]=c;b[1]=d;b[2]=e;b[3]=-Math.sqrt(Math.abs(1-c*c-d*d-e*e));return b};quat4.inverse=function(a,b){if(!b||a===b)return a[0]*=-1,a[1]*=-1,a[2]*=-1,a;b[0]=-a[0];b[1]=-a[1];b[2]=-a[2];b[3]=a[3];return b};quat4.length=function(a){var b=a[0],c=a[1],d=a[2];a=a[3];return Math.sqrt(b*b+c*c+d*d+a*a)};
quat4.normalize=function(a,b){b||(b=a);var c=a[0],d=a[1],e=a[2],g=a[3],f=Math.sqrt(c*c+d*d+e*e+g*g);if(0===f)return b[0]=0,b[1]=0,b[2]=0,b[3]=0,b;f=1/f;b[0]=c*f;b[1]=d*f;b[2]=e*f;b[3]=g*f;return b};quat4.multiply=function(a,b,c){c||(c=a);var d=a[0],e=a[1],g=a[2];a=a[3];var f=b[0],l=b[1],k=b[2];b=b[3];c[0]=d*b+a*f+e*k-g*l;c[1]=e*b+a*l+g*f-d*k;c[2]=g*b+a*k+d*l-e*f;c[3]=a*b-d*f-e*l-g*k;return c};
quat4.multiplyVec3=function(a,b,c){c||(c=b);var d=b[0],e=b[1],g=b[2];b=a[0];var f=a[1],l=a[2];a=a[3];var k=a*d+f*g-l*e,h=a*e+l*d-b*g,m=a*g+b*e-f*d,d=-b*d-f*e-l*g;c[0]=k*a+d*-b+h*-l-m*-f;c[1]=h*a+d*-f+m*-b-k*-l;c[2]=m*a+d*-l+k*-f-h*-b;return c};quat4.toMat3=function(a,b){b||(b=mat3.create());var c=a[0],d=a[1],e=a[2],g=a[3],f=c+c,l=d+d,k=e+e,h=c*f,m=c*l,c=c*k,n=d*l,d=d*k,e=e*k,f=f*g,l=l*g,g=g*k;b[0]=1-(n+e);b[1]=m+g;b[2]=c-l;b[3]=m-g;b[4]=1-(h+e);b[5]=d+f;b[6]=c+l;b[7]=d-f;b[8]=1-(h+n);return b};
quat4.toMat4=function(a,b){b||(b=mat4.create());var c=a[0],d=a[1],e=a[2],g=a[3],f=c+c,l=d+d,k=e+e,h=c*f,m=c*l,c=c*k,n=d*l,d=d*k,e=e*k,f=f*g,l=l*g,g=g*k;b[0]=1-(n+e);b[1]=m+g;b[2]=c-l;b[3]=0;b[4]=m-g;b[5]=1-(h+e);b[6]=d+f;b[7]=0;b[8]=c+l;b[9]=d-f;b[10]=1-(h+n);b[11]=0;b[12]=0;b[13]=0;b[14]=0;b[15]=1;return b};
quat4.slerp=function(a,b,c,d){d||(d=a);var e=a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3],g,f;if(1<=Math.abs(e))return d!==a&&(d[0]=a[0],d[1]=a[1],d[2]=a[2],d[3]=a[3]),d;g=Math.acos(e);f=Math.sqrt(1-e*e);if(0.001>Math.abs(f))return d[0]=0.5*a[0]+0.5*b[0],d[1]=0.5*a[1]+0.5*b[1],d[2]=0.5*a[2]+0.5*b[2],d[3]=0.5*a[3]+0.5*b[3],d;e=Math.sin((1-c)*g)/f;c=Math.sin(c*g)/f;d[0]=a[0]*e+b[0]*c;d[1]=a[1]*e+b[1]*c;d[2]=a[2]*e+b[2]*c;d[3]=a[3]*e+b[3]*c;return d};
quat4.str=function(a){return"["+a[0]+", "+a[1]+", "+a[2]+", "+a[3]+"]"};
(function(){function a(a,b){this.height=this.width=0;this.cam=vec3.create([0,0,100]);this.look=vec3.create([0,0,0]);this.up=vec3.create([0,1,0]);this.worldScale=vec3.create([1,1,1]);this.matP=mat4.create();this.matMV=mat4.create();this.lastMV=mat4.create();this.currentMV=mat4.create();this.gl=a;this.initState()}function b(a,b,c){this.gl=a;this.shaderProgram=b;this.name=c;this.locAPos=a.getAttribLocation(b,"aPos");this.locATex=a.getAttribLocation(b,"aTex");this.locMatP=a.getUniformLocation(b,"matP");
this.locMatMV=a.getUniformLocation(b,"matMV");this.locOpacity=a.getUniformLocation(b,"opacity");this.locSamplerFront=a.getUniformLocation(b,"samplerFront");this.locSamplerBack=a.getUniformLocation(b,"samplerBack");this.locDestStart=a.getUniformLocation(b,"destStart");this.locDestEnd=a.getUniformLocation(b,"destEnd");this.locSeconds=a.getUniformLocation(b,"seconds");this.locPixelWidth=a.getUniformLocation(b,"pixelWidth");this.locPixelHeight=a.getUniformLocation(b,"pixelHeight");this.locLayerScale=
a.getUniformLocation(b,"layerScale");this.locOpacity&&a.uniform1f(this.locOpacity,1);this.locSamplerFront&&a.uniform1i(this.locSamplerFront,0);this.locSamplerBack&&a.uniform1i(this.locSamplerBack,1);this.locDestStart&&a.uniform2f(this.locDestStart,0,0);this.locDestEnd&&a.uniform2f(this.locDestEnd,1,1);this.hasCurrentMatMV=!1}function c(a,b){this.type=a;this.glwrap=b;this.gl=b.gl;this.indexCount=this.startIndex=this.opacityParam=0;this.mat4param=this.texParam=null;this.shaderParams=[];cr.seal(this)}
function d(a){--a;for(var b=1;32>b;b<<=1)a|=a>>b;return a+1}a.prototype.initState=function(){var a=this.gl,b;this.lastOpacity=1;this.lastTexture=null;this.currentOpacity=1;a.clearColor(0,0,0,0);a.clear(a.COLOR_BUFFER_BIT);a.enable(a.BLEND);a.blendFunc(a.ONE,a.ONE_MINUS_SRC_ALPHA);a.disable(a.CULL_FACE);a.disable(a.DEPTH_TEST);this.maxTextureSize=a.getParameter(a.MAX_TEXTURE_SIZE);this.lastSrcBlend=a.ONE;this.lastDestBlend=a.ONE_MINUS_SRC_ALPHA;this.pointBuffer=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,
this.pointBuffer);this.vertexBuffers=Array(4);this.texcoordBuffers=Array(4);for(b=0;4>b;b++)this.vertexBuffers[b]=a.createBuffer(),a.bindBuffer(a.ARRAY_BUFFER,this.vertexBuffers[b]),this.texcoordBuffers[b]=a.createBuffer(),a.bindBuffer(a.ARRAY_BUFFER,this.texcoordBuffers[b]);this.curBuffer=0;this.indexBuffer=a.createBuffer();a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this.indexBuffer);this.vertexData=new Float32Array(16E3);this.texcoordData=new Float32Array(16E3);this.pointData=new Float32Array(32E3);for(var c=
new Uint16Array(12E3),d=b=0;12E3>b;)c[b++]=d,c[b++]=d+1,c[b++]=d+2,c[b++]=d,c[b++]=d+2,c[b++]=d+3,d+=4;a.bufferData(a.ELEMENT_ARRAY_BUFFER,c,a.STATIC_DRAW);this.pointPtr=this.vertexPtr=0;this.shaderPrograms=[];b=this.createShaderProgram({src:"varying mediump vec2 vTex;\nuniform lowp float opacity;\nuniform lowp sampler2D samplerFront;\nvoid main(void) {\n\tgl_FragColor = texture2D(samplerFront, vTex);\n\tgl_FragColor *= opacity;\n}"},"attribute highp vec2 aPos;\nattribute mediump vec2 aTex;\nvarying mediump vec2 vTex;\nuniform highp mat4 matP;\nuniform highp mat4 matMV;\nvoid main(void) {\n\tgl_Position = matP * matMV * vec4(aPos.x, aPos.y, 0.0, 1.0);\n\tvTex = aTex;\n}",
"<default>");this.shaderPrograms.push(b);b=this.createShaderProgram({src:"uniform mediump sampler2D samplerFront;\nvarying lowp float opacity;\nvoid main(void) {\n\tgl_FragColor = texture2D(samplerFront, gl_PointCoord);\n\tgl_FragColor *= opacity;\n}"},"attribute vec4 aPos;\nvarying float opacity;\nuniform mat4 matP;\nuniform mat4 matMV;\nvoid main(void) {\n\tgl_Position = matP * matMV * vec4(aPos.x, aPos.y, 0.0, 1.0);\n\tgl_PointSize = aPos.z;\n\topacity = aPos.w;\n}","<point>");this.shaderPrograms.push(b);
for(var e in cr.shaders)cr.shaders.hasOwnProperty(e)&&this.shaderPrograms.push(this.createShaderProgram(cr.shaders[e],"attribute highp vec2 aPos;\nattribute mediump vec2 aTex;\nvarying mediump vec2 vTex;\nuniform highp mat4 matP;\nuniform highp mat4 matMV;\nvoid main(void) {\n\tgl_Position = matP * matMV * vec4(aPos.x, aPos.y, 0.0, 1.0);\n\tvTex = aTex;\n}",e));a.activeTexture(a.TEXTURE0);a.bindTexture(a.TEXTURE_2D,null);this.batch=[];this.batchPtr=0;this.hasPointBatchTop=this.hasQuadBatchTop=!1;
this.currentProgram=this.lastProgram=-1;this.currentShader=null;this.fbo=a.createFramebuffer();this.renderToTex=null;this.tmpVec3=vec3.create([0,0,0]);a=a.getParameter(a.ALIASED_POINT_SIZE_RANGE);this.minPointSize=a[0];this.maxPointSize=a[1];this.switchProgram(0);cr.seal(this)};a.prototype.createShaderProgram=function(a,c,d){var e=this.gl,g=e.createShader(e.FRAGMENT_SHADER);e.shaderSource(g,a.src);e.compileShader(g);if(!e.getShaderParameter(g,e.COMPILE_STATUS))return e.deleteShader(g),null;var n=
e.createShader(e.VERTEX_SHADER);e.shaderSource(n,c);e.compileShader(n);if(!e.getShaderParameter(n,e.COMPILE_STATUS))return e.deleteShader(g),e.deleteShader(n),null;c=e.createProgram();e.attachShader(c,g);e.attachShader(c,n);e.linkProgram(c);if(!e.getProgramParameter(c,e.LINK_STATUS))return e.deleteShader(g),e.deleteShader(n),e.deleteProgram(c),null;e.useProgram(c);e.validateProgram(c);e.deleteShader(g);e.deleteShader(n);d=new b(e,c,d);d.extendBoxHorizontal=a.extendBoxHorizontal||0;d.extendBoxVertical=
a.extendBoxVertical||0;d.crossSampling=!!a.crossSampling;d.animated=!!a.animated;d.parameters=a.parameters||[];a=0;for(g=d.parameters.length;a<g;a++)d.parameters[a][1]=e.getUniformLocation(c,d.parameters[a][0]),e.uniform1f(d.parameters[a][1],0);cr.seal(d);return d};a.prototype.getShaderIndex=function(a){var b,c;b=0;for(c=this.shaderPrograms.length;b<c;b++)if(this.shaderPrograms[b].name===a)return b;return-1};a.prototype.project=function(a,b,c){var d=[0,0,this.width,this.height],e=this.matMV,g=this.matP,
q=[0,0,0,0,0,0,0,0];q[0]=e[0]*a+e[4]*b+e[12];q[1]=e[1]*a+e[5]*b+e[13];q[2]=e[2]*a+e[6]*b+e[14];q[3]=e[3]*a+e[7]*b+e[15];q[4]=g[0]*q[0]+g[4]*q[1]+g[8]*q[2]+g[12]*q[3];q[5]=g[1]*q[0]+g[5]*q[1]+g[9]*q[2]+g[13]*q[3];q[6]=g[2]*q[0]+g[6]*q[1]+g[10]*q[2]+g[14]*q[3];q[7]=-q[2];0!==q[7]&&(q[7]=1/q[7],q[4]*=q[7],q[5]*=q[7],q[6]*=q[7],c[0]=(0.5*q[4]+0.5)*d[2]+d[0],c[1]=(0.5*q[5]+0.5)*d[3]+d[1])};a.prototype.setSize=function(a,b,c){if(!(this.width===a&&this.height===b&&!c)){this.endBatch();this.width=a;this.height=
b;this.gl.viewport(0,0,a,b);mat4.perspective(45,a/b,1,1E3,this.matP);mat4.lookAt(this.cam,this.look,this.up,this.matMV);a=[0,0];b=[0,0];this.project(0,0,a);this.project(1,1,b);this.worldScale[0]=1/(b[0]-a[0]);this.worldScale[1]=-1/(b[1]-a[1]);a=0;for(b=this.shaderPrograms.length;a<b;a++)c=this.shaderPrograms[a],c.hasCurrentMatMV=!1,c.locMatP&&(this.gl.useProgram(c.shaderProgram),this.gl.uniformMatrix4fv(c.locMatP,!1,this.matP));this.gl.useProgram(this.shaderPrograms[this.lastProgram].shaderProgram);
this.gl.bindTexture(this.gl.TEXTURE_2D,null);this.lastTexture=null}};a.prototype.resetModelView=function(){mat4.lookAt(this.cam,this.look,this.up,this.matMV);mat4.scale(this.matMV,this.worldScale)};a.prototype.translate=function(a,b){0===a&&0===b||(this.tmpVec3[0]=a,this.tmpVec3[1]=b,this.tmpVec3[2]=0,mat4.translate(this.matMV,this.tmpVec3))};a.prototype.scale=function(a,b){1===a&&1===b||(this.tmpVec3[0]=a,this.tmpVec3[1]=b,this.tmpVec3[2]=1,mat4.scale(this.matMV,this.tmpVec3))};a.prototype.rotateZ=
function(a){0!==a&&mat4.rotateZ(this.matMV,a)};a.prototype.updateModelView=function(){for(var a=!1,b=0;16>b;b++)if(this.lastMV[b]!==this.matMV[b]){a=!0;break}a&&(a=this.pushBatch(),a.type=5,a.mat4param?mat4.set(this.matMV,a.mat4param):a.mat4param=mat4.create(this.matMV),mat4.set(this.matMV,this.lastMV),this.hasPointBatchTop=this.hasQuadBatchTop=!1)};c.prototype.doSetTexture=function(){this.gl.bindTexture(this.gl.TEXTURE_2D,this.texParam)};c.prototype.doSetOpacity=function(){var a=this.opacityParam,
b=this.glwrap;b.currentOpacity=a;b=b.currentShader;b.locOpacity&&this.gl.uniform1f(b.locOpacity,a)};c.prototype.doQuad=function(){this.gl.drawElements(this.gl.TRIANGLES,this.indexCount,this.gl.UNSIGNED_SHORT,2*this.startIndex)};c.prototype.doSetBlend=function(){this.gl.blendFunc(this.startIndex,this.indexCount)};c.prototype.doUpdateModelView=function(){var a,b,c,d=this.glwrap.shaderPrograms,e=this.glwrap.currentProgram;a=0;for(b=d.length;a<b;a++)c=d[a],a===e&&c.locMatMV?(this.gl.uniformMatrix4fv(c.locMatMV,
!1,this.mat4param),c.hasCurrentMatMV=!0):c.hasCurrentMatMV=!1;mat4.set(this.mat4param,this.glwrap.currentMV)};c.prototype.doRenderToTexture=function(){var a=this.gl,b=this.glwrap;this.texParam?(a.bindFramebuffer(a.FRAMEBUFFER,b.fbo),a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,this.texParam,0)):(a.framebufferTexture2D(a.FRAMEBUFFER,a.COLOR_ATTACHMENT0,a.TEXTURE_2D,null,0),a.bindFramebuffer(a.FRAMEBUFFER,null))};c.prototype.doClear=function(){var a=this.gl;0===this.startIndex?
(a.clearColor(this.mat4param[0],this.mat4param[1],this.mat4param[2],this.mat4param[3]),a.clear(a.COLOR_BUFFER_BIT)):(a.enable(a.SCISSOR_TEST),a.scissor(this.mat4param[0],this.mat4param[1],this.mat4param[2],this.mat4param[3]),a.clearColor(0,0,0,0),a.clear(this.gl.COLOR_BUFFER_BIT),a.disable(a.SCISSOR_TEST))};c.prototype.doPoints=function(){var a=this.gl,b=this.glwrap,c=b.shaderPrograms[1];a.useProgram(c.shaderProgram);!c.hasCurrentMatMV&&c.locMatMV&&(a.uniformMatrix4fv(c.locMatMV,!1,b.currentMV),c.hasCurrentMatMV=
!0);a.enableVertexAttribArray(c.locAPos);a.bindBuffer(a.ARRAY_BUFFER,b.pointBuffer);a.vertexAttribPointer(c.locAPos,4,a.FLOAT,!1,0,0);a.drawArrays(a.POINTS,this.startIndex/4,this.indexCount);c=b.currentShader;a.useProgram(c.shaderProgram);0<=c.locAPos&&(a.enableVertexAttribArray(c.locAPos),a.bindBuffer(a.ARRAY_BUFFER,b.vertexBuffers[b.curBuffer]),a.vertexAttribPointer(c.locAPos,2,a.FLOAT,!1,0,0));0<=c.locATex&&(a.enableVertexAttribArray(c.locATex),a.bindBuffer(a.ARRAY_BUFFER,b.texcoordBuffers[b.curBuffer]),
a.vertexAttribPointer(c.locATex,2,a.FLOAT,!1,0,0))};c.prototype.doSetProgram=function(){var a=this.gl,b=this.glwrap,c=b.shaderPrograms[this.startIndex];b.currentProgram=this.startIndex;b.currentShader=c;a.useProgram(c.shaderProgram);!c.hasCurrentMatMV&&c.locMatMV&&(a.uniformMatrix4fv(c.locMatMV,!1,b.currentMV),c.hasCurrentMatMV=!0);c.locOpacity&&a.uniform1f(c.locOpacity,b.currentOpacity);0<=c.locAPos&&(a.enableVertexAttribArray(c.locAPos),a.bindBuffer(a.ARRAY_BUFFER,b.vertexBuffers[b.curBuffer]),
a.vertexAttribPointer(c.locAPos,2,a.FLOAT,!1,0,0));0<=c.locATex&&(a.enableVertexAttribArray(c.locATex),a.bindBuffer(a.ARRAY_BUFFER,b.texcoordBuffers[b.curBuffer]),a.vertexAttribPointer(c.locATex,2,a.FLOAT,!1,0,0))};c.prototype.doSetProgramParameters=function(){var a,b,c=this.glwrap.currentShader,d=this.gl;c.locSamplerBack&&(d.activeTexture(d.TEXTURE1),d.bindTexture(d.TEXTURE_2D,this.texParam),d.activeTexture(d.TEXTURE0));c.locPixelWidth&&d.uniform1f(c.locPixelWidth,this.mat4param[0]);c.locPixelHeight&&
d.uniform1f(c.locPixelHeight,this.mat4param[1]);c.locDestStart&&d.uniform2f(c.locDestStart,this.mat4param[2],this.mat4param[3]);c.locDestEnd&&d.uniform2f(c.locDestEnd,this.mat4param[4],this.mat4param[5]);c.locLayerScale&&d.uniform1f(c.locLayerScale,this.mat4param[6]);c.locSeconds&&d.uniform1f(c.locSeconds,cr.performance_now()/1E3);if(c.parameters.length){a=0;for(b=c.parameters.length;a<b;a++)d.uniform1f(c.parameters[a][1],this.shaderParams[a])}};a.prototype.pushBatch=function(){this.batchPtr===this.batch.length&&
this.batch.push(new c(0,this));return this.batch[this.batchPtr++]};a.prototype.endBatch=function(){if(0!==this.batchPtr&&!this.gl.isContextLost()){var a=this.gl;0<this.pointPtr&&(a.bindBuffer(a.ARRAY_BUFFER,this.pointBuffer),a.bufferData(a.ARRAY_BUFFER,this.pointData.subarray(0,this.pointPtr),a.STREAM_DRAW),b&&(0<=b.locAPos&&"<point>"===b.name)&&a.vertexAttribPointer(b.locAPos,4,a.FLOAT,!1,0,0));if(0<this.vertexPtr){var b=this.currentShader;a.bindBuffer(a.ARRAY_BUFFER,this.vertexBuffers[this.curBuffer]);
a.bufferData(a.ARRAY_BUFFER,this.vertexData.subarray(0,this.vertexPtr),a.STREAM_DRAW);b&&(0<=b.locAPos&&"<point>"!==b.name)&&a.vertexAttribPointer(b.locAPos,2,a.FLOAT,!1,0,0);a.bindBuffer(a.ARRAY_BUFFER,this.texcoordBuffers[this.curBuffer]);a.bufferData(a.ARRAY_BUFFER,this.texcoordData.subarray(0,this.vertexPtr),a.STREAM_DRAW);b&&(0<=b.locATex&&"<point>"!==b.name)&&a.vertexAttribPointer(b.locATex,2,a.FLOAT,!1,0,0)}for(var c,a=0,b=this.batchPtr;a<b;a++)switch(c=this.batch[a],c.type){case 1:c.doQuad();
break;case 2:c.doSetTexture();break;case 3:c.doSetOpacity();break;case 4:c.doSetBlend();break;case 5:c.doUpdateModelView();break;case 6:c.doRenderToTexture();break;case 7:c.doClear();break;case 8:c.doPoints();break;case 9:c.doSetProgram();break;case 10:c.doSetProgramParameters()}this.pointPtr=this.vertexPtr=this.batchPtr=0;this.hasPointBatchTop=this.hasQuadBatchTop=!1;this.curBuffer++;4<=this.curBuffer&&(this.curBuffer=0)}};a.prototype.setOpacity=function(a){if(a!==this.lastOpacity){var b=this.pushBatch();
b.type=3;this.lastOpacity=b.opacityParam=a;this.hasPointBatchTop=this.hasQuadBatchTop=!1}};a.prototype.setTexture=function(a){if(a!==this.lastTexture){var b=this.pushBatch();b.type=2;this.lastTexture=b.texParam=a;this.hasPointBatchTop=this.hasQuadBatchTop=!1}};a.prototype.setBlend=function(a,b){if(!(a===this.lastSrcBlend&&b===this.lastDestBlend)){var c=this.pushBatch();c.type=4;c.startIndex=a;c.indexCount=b;this.lastSrcBlend=a;this.lastDestBlend=b;this.hasPointBatchTop=this.hasQuadBatchTop=!1}};a.prototype.setAlphaBlend=
function(){this.setBlend(this.gl.ONE,this.gl.ONE_MINUS_SRC_ALPHA)};a.prototype.quad=function(a,b,c,d,e,g,q,p){15992<=this.vertexPtr&&this.endBatch();var r=this.vertexPtr,s=this.vertexData,t=this.texcoordData;if(this.hasQuadBatchTop)this.batch[this.batchPtr-1].indexCount+=6;else{var v=this.pushBatch();v.type=1;v.startIndex=3*(r/4);v.indexCount=6;this.hasQuadBatchTop=!0;this.hasPointBatchTop=!1}s[r]=a;t[r++]=0;s[r]=b;t[r++]=0;s[r]=c;t[r++]=1;s[r]=d;t[r++]=0;s[r]=e;t[r++]=1;s[r]=g;t[r++]=1;s[r]=q;t[r++]=
0;s[r]=p;t[r++]=1;this.vertexPtr=r};a.prototype.quadTex=function(a,b,c,d,e,g,q,p,r){15992<=this.vertexPtr&&this.endBatch();var s=this.vertexPtr,t=this.vertexData,v=this.texcoordData;if(this.hasQuadBatchTop)this.batch[this.batchPtr-1].indexCount+=6;else{var w=this.pushBatch();w.type=1;w.startIndex=3*(s/4);w.indexCount=6;this.hasQuadBatchTop=!0;this.hasPointBatchTop=!1}t[s]=a;v[s++]=r.left;t[s]=b;v[s++]=r.top;t[s]=c;v[s++]=r.right;t[s]=d;v[s++]=r.top;t[s]=e;v[s++]=r.right;t[s]=g;v[s++]=r.bottom;t[s]=
q;v[s++]=r.left;t[s]=p;v[s++]=r.bottom;this.vertexPtr=s};a.prototype.point=function(a,b,c,d){7996<=this.pointPtr&&this.endBatch();var e=this.pointPtr,g=this.pointData;if(this.hasPointBatchTop)this.batch[this.batchPtr-1].indexCount++;else{var q=this.pushBatch();q.type=8;q.startIndex=e;q.indexCount=1;this.hasPointBatchTop=!0;this.hasQuadBatchTop=!1}g[e++]=a;g[e++]=b;g[e++]=c;g[e++]=d;this.pointPtr=e};a.prototype.switchProgram=function(a){if(this.lastProgram!==a){if(!this.shaderPrograms[a]){if(0===this.lastProgram)return;
a=0}var b=this.pushBatch();b.type=9;this.lastProgram=b.startIndex=a;this.hasPointBatchTop=this.hasQuadBatchTop=!1}};a.prototype.programUsesDest=function(a){a=this.shaderPrograms[a];return!(!a.locDestStart&&!a.locDestEnd)};a.prototype.programUsesCrossSampling=function(a){return this.shaderPrograms[a].crossSampling};a.prototype.programExtendsBox=function(a){a=this.shaderPrograms[a];return 0!==a.extendBoxHorizontal||0!==a.extendBoxVertical};a.prototype.getProgramBoxExtendHorizontal=function(a){return this.shaderPrograms[a].extendBoxHorizontal};
a.prototype.getProgramBoxExtendVertical=function(a){return this.shaderPrograms[a].extendBoxVertical};a.prototype.getProgramParameterType=function(a,b){return this.shaderPrograms[a].parameters[b][2]};a.prototype.programIsAnimated=function(a){return this.shaderPrograms[a].animated};a.prototype.setProgramParameters=function(a,b,c,d,e,g,q,p,r){var s=this.shaderPrograms[this.lastProgram];if(s.locPixelWidth||s.locPixelHeight||s.locSeconds||s.locSamplerBack||s.locDestStart||s.locDestEnd||s.locLayerScale||
r.length){s=this.pushBatch();s.type=10;s.mat4param?mat4.set(this.matMV,s.mat4param):s.mat4param=mat4.create();s.mat4param[0]=b;s.mat4param[1]=c;s.mat4param[2]=d;s.mat4param[3]=e;s.mat4param[4]=g;s.mat4param[5]=q;s.mat4param[6]=p;s.texParam=a;if(r.length){s.shaderParams.length=r.length;a=0;for(b=r.length;a<b;a++)s.shaderParams[a]=r[a]}this.hasPointBatchTop=this.hasQuadBatchTop=!1}};a.prototype.clear=function(a,b,c,d){var e=this.pushBatch();e.type=7;e.startIndex=0;e.mat4param||(e.mat4param=mat4.create());
e.mat4param[0]=a;e.mat4param[1]=b;e.mat4param[2]=c;e.mat4param[3]=d;this.hasPointBatchTop=this.hasQuadBatchTop=!1};a.prototype.clearRect=function(a,b,c,d){var e=this.pushBatch();e.type=7;e.startIndex=1;e.mat4param||(e.mat4param=mat4.create());e.mat4param[0]=a;e.mat4param[1]=b;e.mat4param[2]=c;e.mat4param[3]=d;this.hasPointBatchTop=this.hasQuadBatchTop=!1};a.prototype.present=function(){this.endBatch();this.gl.flush()};var e=[],g={};a.prototype.loadTexture=function(a,b,c,h,m){b=!!b;c=!!c;var n=a.src+
","+b+","+c+(b?","+m:""),q=null;if("undefined"!==typeof a.src&&g.hasOwnProperty(n))return q=g[n],q.c2refcount++,q;this.endBatch();var p=this.gl,r=cr.isPOT(a.width)&&cr.isPOT(a.height),q=p.createTexture();p.bindTexture(p.TEXTURE_2D,q);p.pixelStorei(p.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0);var s=p.RGBA,t=p.RGBA,v=p.UNSIGNED_BYTE;if(h)switch(h){case 1:t=s=p.RGB;break;case 2:v=p.UNSIGNED_SHORT_4_4_4_4;break;case 3:v=p.UNSIGNED_SHORT_5_5_5_1;break;case 4:t=s=p.RGB,v=p.UNSIGNED_SHORT_5_6_5}!r&&b?(h=document.createElement("canvas"),
h.width=d(a.width),h.height=d(a.height),h.getContext("2d").drawImage(a,0,0,a.width,a.height,0,0,h.width,h.height),p.texImage2D(p.TEXTURE_2D,0,s,t,v,h)):p.texImage2D(p.TEXTURE_2D,0,s,t,v,a);b?"repeat-x"===m?(p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_S,p.REPEAT),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_T,p.CLAMP_TO_EDGE)):("repeat-y"===m?p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_S,p.CLAMP_TO_EDGE):p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_S,p.REPEAT),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_T,
p.REPEAT)):(p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_S,p.CLAMP_TO_EDGE),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_WRAP_T,p.CLAMP_TO_EDGE));c?(p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MAG_FILTER,p.LINEAR),r?(p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MIN_FILTER,p.LINEAR_MIPMAP_LINEAR),p.generateMipmap(p.TEXTURE_2D)):p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MIN_FILTER,p.LINEAR)):(p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MAG_FILTER,p.NEAREST),p.texParameteri(p.TEXTURE_2D,p.TEXTURE_MIN_FILTER,p.NEAREST));p.bindTexture(p.TEXTURE_2D,
null);this.lastTexture=null;q.c2width=a.width;q.c2height=a.height;q.c2refcount=1;q.c2texkey=n;e.push(q);return g[n]=q};a.prototype.createEmptyTexture=function(a,b,c,d){this.endBatch();var g=this.gl,n=g.createTexture();g.bindTexture(g.TEXTURE_2D,n);g.texImage2D(g.TEXTURE_2D,0,g.RGBA,a,b,0,g.RGBA,d?g.UNSIGNED_SHORT_4_4_4_4:g.UNSIGNED_BYTE,null);g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_S,g.CLAMP_TO_EDGE);g.texParameteri(g.TEXTURE_2D,g.TEXTURE_WRAP_T,g.CLAMP_TO_EDGE);g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MAG_FILTER,
c?g.LINEAR:g.NEAREST);g.texParameteri(g.TEXTURE_2D,g.TEXTURE_MIN_FILTER,c?g.LINEAR:g.NEAREST);g.bindTexture(g.TEXTURE_2D,null);this.lastTexture=null;n.c2width=a;n.c2height=b;e.push(n);return n};a.prototype.videoToTexture=function(a,b,c){this.endBatch();var d=this.gl;d.bindTexture(d.TEXTURE_2D,b);d.texImage2D(d.TEXTURE_2D,0,d.RGBA,d.RGBA,c?d.UNSIGNED_SHORT_4_4_4_4:d.UNSIGNED_BYTE,a);d.bindTexture(d.TEXTURE_2D,null);this.lastTexture=null};a.prototype.deleteTexture=function(a){a&&("undefined"!==typeof a.c2refcount&&
1<a.c2refcount?a.c2refcount--:(this.endBatch(),this.gl.bindTexture(this.gl.TEXTURE_2D,null),this.lastTexture=null,cr.arrayFindRemove(e,a),"undefined"!==typeof a.c2texkey&&delete g[a.c2texkey],this.gl.deleteTexture(a)))};a.prototype.estimateVRAM=function(){var a=8*this.width*this.height,b,c,d;b=0;for(c=e.length;b<c;b++)d=e[b],a+=4*d.c2width*d.c2height;return a};a.prototype.textureCount=function(){return e.length};a.prototype.setRenderingToTexture=function(a){if(a!==this.renderToTex){var b=this.pushBatch();
b.type=6;this.renderToTex=b.texParam=a;this.hasPointBatchTop=this.hasQuadBatchTop=!1}};cr.GLWrap=a})();
(function(){function a(a){if(a&&(a.getContext||a.dc)&&!a.c2runtime){a.c2runtime=this;var b=this;this.isPhoneGap="undefined"!==typeof window.device&&("undefined"!==typeof window.device.cordova||"undefined"!==typeof window.device.phonegap);this.isDirectCanvas=!!a.dc;this.isAppMobi="undefined"!==typeof window.AppMobi||this.isDirectCanvas;if(this.isCocoonJs=!!window.c2cocoonjs)CocoonJS.App.onSuspended.addEventListener(function(){b.setSuspended(!0)}),CocoonJS.App.onActivated.addEventListener(function(){b.setSuspended(!1)});
this.isDomFree=this.isDirectCanvas||this.isCocoonJs;this.isTizen=/tizen/i.test(navigator.userAgent);this.isAndroid=/android/i.test(navigator.userAgent)&&!this.isTizen;this.isIE=/msie/i.test(navigator.userAgent);this.isiPhone=/iphone/i.test(navigator.userAgent)||/ipod/i.test(navigator.userAgent);this.isiPad=/ipad/i.test(navigator.userAgent);this.isiOS=this.isiPhone||this.isiPad;this.isChrome=/chrome/i.test(navigator.userAgent)||/chromium/i.test(navigator.userAgent);this.isSafari=!this.isChrome&&/safari/i.test(navigator.userAgent);
this.isWindows=/windows/i.test(navigator.userAgent);this.isNodeWebkit="undefined"!==typeof window.c2nodewebkit;this.isArcade="undefined"!==typeof window.is_scirra_arcade;this.isWindows8App=!!("undefined"!==typeof window.c2isWindows8&&window.c2isWindows8);this.isWindowsPhone8=!!("undefined"!==typeof window.c2isWindowsPhone8&&window.c2isWindowsPhone8);this.isBlackberry10=!!("undefined"!==typeof window.c2isBlackberry10&&window.c2isBlackberry10);this.devicePixelRatio=1;this.isMobile=this.isPhoneGap||
this.isAppMobi||this.isCocoonJs||this.isAndroid||this.isiOS||this.isWindowsPhone8||this.isBlackberry10||this.isTizen;this.isMobile||(this.isMobile=/(blackberry|bb10|playbook|palm|symbian|nokia|windows\s+ce|phone|mobile|tablet)/i.test(navigator.userAgent));if("undefined"!==typeof cr_is_preview&&!this.isNodeWebkit&&("?nw"===window.location.search||/nodewebkit/i.test(navigator.userAgent)))this.isNodeWebkit=!0;this.isDebug="undefined"!==typeof cr_is_preview&&-1<window.location.search.indexOf("debug");
this.canvas=a;this.canvasdiv=document.getElementById("c2canvasdiv");this.ctx=this.glwrap=this.gl=null;this.canvas.oncontextmenu=function(a){a.preventDefault&&a.preventDefault();return!1};this.canvas.onselectstart=function(a){a.preventDefault&&a.preventDefault();return!1};this.isDirectCanvas&&(window.c2runtime=this);this.isNodeWebkit&&(window.ondragover=function(a){a.preventDefault();return!1},window.ondrop=function(a){a.preventDefault();return!1});this.width=a.width;this.height=a.height;this.lastwidth=
this.width;this.lastheight=this.height;this.redraw=!0;this.isSuspended=!1;Date.now||(Date.now=function(){return+new Date});this.plugins=[];this.types={};this.types_by_index=[];this.behaviors=[];this.layouts={};this.layouts_by_index=[];this.eventsheets={};this.eventsheets_by_index=[];this.wait_for_textures=[];this.triggers_to_postinit=[];this.all_global_vars=[];this.all_local_vars=[];this.deathRow=new cr.ObjectSet;this.isInClearDeathRow=!1;this.isInOnDestroy=0;this.isRunningEvents=!1;this.createRow=
[];this.isLoadingState=!1;this.lastSaveJson=this.loadFromJson=this.loadFromSlot=this.saveToSlot="";this.suspendDrawing=this.signalledContinuousPreview=!1;this.zeroDtCount=this.cpuutilisation=this.logictime=this.dt1=this.dt=0;this.timescale=1;this.kahanTime=new cr.KahanAdder;this.last_tick_time=0;this.measuring_dt=!0;this.objectcount=this.framecount=this.execcount=this.tickcount=this.last_fps_time=this.fps=0;this.changelayout=null;this.destroycallbacks=[];this.event_stack=[];this.event_stack_index=
-1;this.localvar_stack=[[]];this.trigger_depth=this.localvar_stack_index=0;this.pushEventStack(null);this.loop_stack=[];this.loop_stack_index=-1;this.next_puid=this.next_uid=0;this.layout_first_tick=!0;this.family_count=0;this.suspend_events=[];this.timeout_id=this.raf_id=0;this.isloading=!0;this.loadingprogress=0;this.isNodeFullscreen=!1;this.stackLocalCount=0;this.had_a_click=!1;this.objects_to_tick=new cr.ObjectSet;this.objects_to_tick2=new cr.ObjectSet;this.registered_collisions=[];this.temp_poly=
new cr.CollisionPoly([]);this.temp_poly2=new cr.CollisionPoly([]);this.allGroups=[];this.activeGroups={};this.cndsBySid={};this.actsBySid={};this.varsBySid={};this.blocksBySid={};this.layout_tex=this.layer_tex=this.layer_ctx=this.layer_canvas=this.running_layout=null;this.uses_background_blending=this.is_WebGL_context_lost=!1;this.fx_tex=[null,null];this.fullscreen_scaling=0;this.files_subfolder="";this.objectsByUid={};this.snapshotCanvas=this.loaderlogo=null;this.snapshotData="";this.load();this.devicePixelRatio=
(this.isRetina=!this.isDomFree&&this.useiOSRetina&&(this.isiOS||this.isTizen))?window.devicePixelRatio||1:1;this.ClearDeathRow();var c;"undefined"!==typeof jQuery&&0<this.fullscreen_mode&&this.setSize(jQuery(window).width(),jQuery(window).height());try{if(this.enableWebGL&&(this.isCocoonJs||!this.isDomFree)){c={depth:!1,antialias:!this.isMobile};var d=!0;if(this.isChrome&&this.isWindows){var e=document.createElement("canvas");if("OES_texture_float,OES_standard_derivatives,WEBKIT_WEBGL_lose_context"===
(e.getContext("webgl",c)||e.getContext("experimental-webgl",c)).getSupportedExtensions().toString())d=!1}d&&(this.gl=a.getContext("webgl",c)||a.getContext("experimental-webgl",c))}}catch(g){}if(this.gl){this.isDomFree||(this.overlay_canvas=document.createElement("canvas"),jQuery(this.overlay_canvas).appendTo(this.canvas.parentNode),this.overlay_canvas.oncontextmenu=function(a){return!1},this.overlay_canvas.onselectstart=function(a){return!1},this.overlay_canvas.width=a.width,this.overlay_canvas.height=
a.height,this.positionOverlayCanvas(),this.overlay_ctx=this.overlay_canvas.getContext("2d"));this.glwrap=new cr.GLWrap(this.gl,this.isMobile);this.glwrap.setSize(a.width,a.height);this.ctx=null;this.canvas.addEventListener("webglcontextlost",function(a){a.preventDefault();b.onContextLost();window.cr_setSuspended(!0)},!1);this.canvas.addEventListener("webglcontextrestored",function(a){b.glwrap.initState();b.glwrap.setSize(b.glwrap.width,b.glwrap.height,!0);b.layer_tex=null;b.layout_tex=null;b.fx_tex[0]=
null;b.fx_tex[1]=null;b.onContextRestored();b.redraw=!0;window.cr_setSuspended(!1)},!1);var f,h,m,l,k;a=0;for(c=this.types_by_index.length;a<c;a++){f=this.types_by_index[a];d=0;for(e=f.effect_types.length;d<e;d++)m=f.effect_types[d],m.shaderindex=this.glwrap.getShaderIndex(m.id),this.uses_background_blending=this.uses_background_blending||this.glwrap.programUsesDest(m.shaderindex)}a=0;for(c=this.layouts_by_index.length;a<c;a++){l=this.layouts_by_index[a];d=0;for(e=l.effect_types.length;d<e;d++)m=
l.effect_types[d],m.shaderindex=this.glwrap.getShaderIndex(m.id);d=0;for(e=l.layers.length;d<e;d++){k=l.layers[d];f=0;for(h=k.effect_types.length;f<h;f++)m=k.effect_types[f],m.shaderindex=this.glwrap.getShaderIndex(m.id),this.uses_background_blending=this.uses_background_blending||this.glwrap.programUsesDest(m.shaderindex)}}}else{if(0<this.fullscreen_mode&&this.isDirectCanvas){this.canvas=null;document.oncontextmenu=function(a){return!1};document.onselectstart=function(a){return!1};this.ctx=AppMobi.canvas.getContext("2d");
try{this.ctx.samplingMode=this.linearSampling?"smooth":"sharp",this.ctx.globalScale=1,this.ctx.HTML5CompatibilityMode=!0}catch(p){}0!==this.width&&0!==this.height&&(this.ctx.width=this.width,this.ctx.height=this.height)}this.ctx||(this.isCocoonJs?(c={antialias:!!this.linearSampling},this.ctx=a.getContext("2d",c)):this.ctx=a.getContext("2d"),this.ctx.webkitImageSmoothingEnabled=this.linearSampling,this.ctx.mozImageSmoothingEnabled=this.linearSampling,this.ctx.msImageSmoothingEnabled=this.linearSampling,
this.ctx.imageSmoothingEnabled=this.linearSampling);this.overlay_ctx=this.overlay_canvas=null}this.tickFunc=function(){b.tick()};window!=window.top&&(!this.isDomFree&&!this.isWindows8App)&&(document.addEventListener("mousedown",function(){window.focus()},!0),document.addEventListener("touchstart",function(){window.focus()},!0));"undefined"!==typeof cr_is_preview&&(this.isCocoonJs&&console.log("[Construct 2] In preview-over-wifi via CocoonJS mode"),-1<window.location.search.indexOf("continuous")&&
(cr.logexport("Reloading for continuous preview"),this.loadFromSlot="__c2_continuouspreview",this.suspendDrawing=!0),this.pauseOnBlur&&!this.isMobile&&(jQuery(window).focus(function(){b.setSuspended(!1)}),jQuery(window).blur(function(){b.setSuspended(!0)})));this.go();this.extra={};cr.seal(this)}}function b(a){a.target.result.createObjectStore("saves",{keyPath:"slot"})}function c(a,c,d,e){var g=indexedDB.open("_C2SaveStates");g.onupgradeneeded=b;g.onerror=e;g.onsuccess=function(b){b=b.target.result;
b.onerror=e;b.transaction(["saves"],"readwrite").objectStore("saves").put({slot:a,data:c}).onsuccess=d}}function d(a,c,d){var e=indexedDB.open("_C2SaveStates");e.onupgradeneeded=b;e.onerror=d;e.onsuccess=function(b){b=b.target.result;b.onerror=d;var e=b.transaction(["saves"]).objectStore("saves").get(a);e.onsuccess=function(a){e.result?c(e.result.data):c(null)}}}function e(){cr.logexport("Reloading for continuous preview");window.c2cocoonjs?CocoonJS.App.reload():-1<window.location.search.indexOf("continuous")?
window.location.reload(!0):window.location+="?continuous"}function g(a){var b,c={};for(b in a)a.hasOwnProperty(b)&&!(a[b]instanceof cr.ObjectSet)&&"undefined"===typeof a[b].c2userdata&&"mouseOverInverted"!==b&&(c[b]=a[b]);return c}a.prototype.setSize=function(a,b){var c=this.hideAddressBar&&this.isiPhone&&!navigator.standalone&&!this.isDomFree&&!this.isPhoneGap,d=0;c&&(this.isiPhone?d=60:this.isAndroid&&(d=56),b+=d);var e=0,g=0,f=0,h=0,m=0,m=this.fullscreen_mode,l=document.mozFullScreen||document.webkitIsFullScreen||
document.fullScreen||this.isNodeFullscreen;l&&0<this.fullscreen_scaling&&(m=this.fullscreen_scaling);4<=m?(f=this.original_width/this.original_height,a/b>f?(f*=b,5===m?(m=f/this.original_width,1<m?m=Math.floor(m):1>m&&(m=1/Math.ceil(1/m)),f=this.original_width*m,h=this.original_height*m,e=(a-f)/2,g=(b-h)/2,a=f,b=h):(e=(a-f)/2,a=f)):(h=a/f,5===m?(m=h/this.original_height,1<m?m=Math.floor(m):1>m&&(m=1/Math.ceil(1/m)),f=this.original_width*m,h=this.original_height*m,e=(a-f)/2,g=(b-h)/2,a=f):g=(b-h)/
2,b=h),l&&!this.isNodeWebkit&&(g=e=0),e=Math.floor(e),g=Math.floor(g),a=Math.floor(a),b=Math.floor(b)):this.isNodeWebkit&&(this.isNodeFullscreen&&0===this.fullscreen_mode_set)&&(e=Math.floor((a-this.original_width)/2),g=Math.floor((b-this.original_height)/2),a=this.original_width,b=this.original_height);this.isRetina&&(this.isiPad&&1<this.devicePixelRatio)&&(1024<=a&&(a=1023),1024<=b&&(b=1023));l=this.devicePixelRatio;this.width=a*l;this.height=b*l;this.redraw=!0;this.canvasdiv&&!this.isDomFree&&
(jQuery(this.canvasdiv).css({width:a+"px",height:b+"px","margin-left":e,"margin-top":g}),"undefined"!==typeof cr_is_preview&&jQuery("#borderwrap").css({width:a+"px",height:b+"px"}));this.canvas&&(this.canvas.width=a*l,this.canvas.height=b*l,this.isRetina&&jQuery(this.canvas).css({width:a+"px",height:b+"px"}));this.overlay_canvas&&(this.overlay_canvas.width=a,this.overlay_canvas.height=b);this.glwrap&&this.glwrap.setSize(a,b);this.isDirectCanvas&&this.ctx&&(this.ctx.width=a,this.ctx.height=b);this.ctx&&
(this.ctx.webkitImageSmoothingEnabled=this.linearSampling,this.ctx.mozImageSmoothingEnabled=this.linearSampling,this.ctx.msImageSmoothingEnabled=this.linearSampling,this.ctx.imageSmoothingEnabled=this.linearSampling);c&&0<d&&window.setTimeout(function(){window.scrollTo(0,1)},100)};a.prototype.onContextLost=function(){this.is_WebGL_context_lost=!0;var a,b,c;a=0;for(b=this.types_by_index.length;a<b;a++)if(c=this.types_by_index[a],c.onLostWebGLContext)c.onLostWebGLContext()};a.prototype.onContextRestored=
function(){this.is_WebGL_context_lost=!1;var a,b,c;a=0;for(b=this.types_by_index.length;a<b;a++)if(c=this.types_by_index[a],c.onRestoreWebGLContext)c.onRestoreWebGLContext()};a.prototype.positionOverlayCanvas=function(){if(!this.isDomFree){var a=document.mozFullScreen||document.webkitIsFullScreen||document.fullScreen||this.isNodeFullscreen?jQuery(this.canvas).offset():jQuery(this.canvas).position();a.position="absolute";jQuery(this.overlay_canvas).css(a)}};var f=window.cancelAnimationFrame||window.mozCancelAnimationFrame||
window.webkitCancelAnimationFrame||window.msCancelAnimationFrame||window.oCancelAnimationFrame;a.prototype.setSuspended=function(a){var b;if(a&&!this.isSuspended){cr.logexport("[Construct 2] Suspending");this.isSuspended=!0;0!==this.raf_id&&f&&f(this.raf_id);0!==this.timeout_id&&clearTimeout(this.timeout_id);a=0;for(b=this.suspend_events.length;a<b;a++)this.suspend_events[a](!0)}else if(!a&&this.isSuspended){cr.logexport("[Construct 2] Resuming");this.isSuspended=!1;this.last_tick_time=cr.performance_now();
this.last_fps_time=cr.performance_now();a=this.logictime=this.framecount=0;for(b=this.suspend_events.length;a<b;a++)this.suspend_events[a](!1);this.tick()}};a.prototype.addSuspendCallback=function(a){this.suspend_events.push(a)};a.prototype.load=function(){var a=cr.getProjectModel();this.name=a[0];this.first_layout=a[1];this.fullscreen_mode=a[11];this.fullscreen_mode_set=a[11];if(this.isDomFree&&(4<=a[11]||0===a[11]))cr.logexport("[Construct 2] Letterbox scale fullscreen modes are not supported on this platform - falling back to 'Scale outer'"),
this.fullscreen_mode_set=this.fullscreen_mode=3;this.uses_loader_layout=a[17];this.loaderstyle=a[18];0===this.loaderstyle&&(this.loaderlogo=new Image,this.loaderlogo.src="loading-logo.png");this.next_uid=a[20];this.system=new cr.system_object(this);var b,c,d,e,f,g,m,h,l;b=0;for(c=a[2].length;b<c;b++){m=a[2][b];cr.add_common_aces(m);l=new m[0](this);l.singleglobal=m[1];l.is_world=m[2];l.must_predraw=m[9];if(l.onCreate)l.onCreate();cr.seal(l);this.plugins.push(l)}a=cr.getProjectModel();b=0;for(c=a[3].length;b<
c;b++){m=a[3][b];f=m[1];l=null;d=0;for(e=this.plugins.length;d<e;d++)if(this.plugins[d]instanceof f){l=this.plugins[d];break}var k=new l.Type(l);k.name=m[0];k.is_family=m[2];k.instvar_sids=m[3].slice(0);k.vars_count=m[3].length;k.behs_count=m[4];k.fx_count=m[5];k.sid=m[11];k.is_family?(k.members=[],k.family_index=this.family_count++,k.families=null):(k.members=null,k.family_index=-1,k.families=[]);k.family_var_map=null;k.family_beh_map=null;k.family_fx_map=null;k.is_contained=!1;k.container=null;
m[6]?(k.texture_file=m[6][0],k.texture_filesize=m[6][1],k.texture_pixelformat=m[6][2]):(k.texture_file=null,k.texture_filesize=0,k.texture_pixelformat=0);k.animations=m[7]?m[7]:null;k.index=b;k.instances=[];k.deadCache=[];k.solstack=[new cr.selection(k)];k.cur_sol=0;k.default_instance=null;k.stale_iids=!0;k.updateIIDs=cr.type_updateIIDs;k.getFirstPicked=cr.type_getFirstPicked;k.getPairedInstance=cr.type_getPairedInstance;k.getCurrentSol=cr.type_getCurrentSol;k.pushCleanSol=cr.type_pushCleanSol;k.pushCopySol=
cr.type_pushCopySol;k.popSol=cr.type_popSol;k.getBehaviorByName=cr.type_getBehaviorByName;k.getBehaviorIndexByName=cr.type_getBehaviorIndexByName;k.getEffectIndexByName=cr.type_getEffectIndexByName;k.applySolToContainer=cr.type_applySolToContainer;k.extra={};k.toString=cr.type_toString;k.behaviors=[];d=0;for(e=m[8].length;d<e;d++){h=m[8][d];var p=h[1],n=null;f=0;for(g=this.behaviors.length;f<g;f++)if(this.behaviors[f]instanceof p){n=this.behaviors[f];break}if(!n){n=new p(this);n.my_instances=new cr.ObjectSet;
if(n.onCreate)n.onCreate();cr.seal(n);this.behaviors.push(n)}f=new n.Type(n,k);f.name=h[0];f.sid=h[2];f.onCreate();cr.seal(f);k.behaviors.push(f)}k.global=m[9];k.isOnLoaderLayout=m[10];k.effect_types=[];d=0;for(e=m[12].length;d<e;d++)k.effect_types.push({id:m[12][d][0],name:m[12][d][1],shaderindex:-1,active:!0,index:d});if(!this.uses_loader_layout||k.is_family||k.isOnLoaderLayout||!l.is_world)k.onCreate(),cr.seal(k);k.name&&(this.types[k.name]=k);this.types_by_index.push(k);l.singleglobal&&(d=new l.Instance(k),
d.uid=this.next_uid++,d.puid=this.next_puid++,d.iid=0,d.get_iid=cr.inst_get_iid,d.toString=cr.inst_toString,d.properties=m[13],d.onCreate(),cr.seal(d),k.instances.push(d))}b=0;for(c=a[4].length;b<c;b++){f=a[4][b];g=this.types_by_index[f[0]];d=1;for(e=f.length;d<e;d++)m=this.types_by_index[f[d]],m.families.push(g),g.members.push(m)}b=0;for(c=a[22].length;b<c;b++){f=a[22][b];g=[];d=0;for(e=f.length;d<e;d++)g.push(this.types_by_index[f[d]]);d=0;for(e=g.length;d<e;d++)g[d].is_contained=!0,g[d].container=
g}if(0<this.family_count){b=0;for(c=this.types_by_index.length;b<c;b++)if(m=this.types_by_index[b],!m.is_family&&m.families.length){m.family_var_map=Array(this.family_count);m.family_beh_map=Array(this.family_count);m.family_fx_map=Array(this.family_count);k=[];d=n=p=h=0;for(e=m.families.length;d<e;d++){l=m.families[d];m.family_var_map[l.family_index]=h;h+=l.vars_count;m.family_beh_map[l.family_index]=p;p+=l.behs_count;m.family_fx_map[l.family_index]=n;n+=l.fx_count;f=0;for(g=l.effect_types.length;f<
g;f++)k.push(cr.shallowCopy({},l.effect_types[f]))}m.effect_types=k.concat(m.effect_types);d=0;for(e=m.effect_types.length;d<e;d++)m.effect_types[d].index=d}}b=0;for(c=a[5].length;b<c;b++)m=a[5][b],d=new cr.layout(this,m),cr.seal(d),this.layouts[d.name]=d,this.layouts_by_index.push(d);b=0;for(c=a[6].length;b<c;b++)m=a[6][b],d=new cr.eventsheet(this,m),cr.seal(d),this.eventsheets[d.name]=d,this.eventsheets_by_index.push(d);b=0;for(c=this.eventsheets_by_index.length;b<c;b++)this.eventsheets_by_index[b].postInit();
b=0;for(c=this.triggers_to_postinit.length;b<c;b++)this.triggers_to_postinit[b].postInit();this.triggers_to_postinit.length=0;this.files_subfolder=a[7];this.pixel_rounding=a[8];this.original_width=a[9];this.original_height=a[10];this.aspect_scale=1;this.enableWebGL=a[12];this.linearSampling=a[13];this.clearBackground=a[14];this.versionstr=a[15];b=a[16];2===b&&(b=this.isiPhone?1:0);this.useiOSRetina=0!==b;this.hideAddressBar=a[19];this.pauseOnBlur=a[21];this.start_time=Date.now()};a.prototype.findWaitingTexture=
function(a){var b,c;b=0;for(c=this.wait_for_textures.length;b<c;b++)if(this.wait_for_textures[b].cr_src===a)return this.wait_for_textures[b];return null};a.prototype.areAllTexturesLoaded=function(){var a=0,b=0,c=!0,d,e;d=0;for(e=this.wait_for_textures.length;d<e;d++){var f=this.wait_for_textures[d].cr_filesize;if(!f||0>=f)f=5E4;a+=f;this.wait_for_textures[d].complete||this.wait_for_textures[d].loaded?b+=f:c=!1}this.progress=0==a?0:b/a;return c};a.prototype.go=function(){if(this.ctx||this.glwrap){var a=
this.ctx||this.overlay_ctx;this.overlay_canvas&&this.positionOverlayCanvas();this.progress=0;this.last_progress=-1;if(this.areAllTexturesLoaded())this.go_textures_done();else{var b=Date.now()-this.start_time,c=1;this.isTizen&&(c=this.devicePixelRatio);if(a){if(3!==this.loaderstyle&&500<=b&&this.last_progress!=this.progress){a.clearRect(0,0,this.width,this.height);var b=this.width/(2*c),c=this.height/(2*c),d=0===this.loaderstyle&&this.loaderlogo.complete,e=40,f=0,g=80;d&&(g=this.loaderlogo.width,e=
g/2,f=this.loaderlogo.height/2,a.drawImage(this.loaderlogo,cr.floor(b-e),cr.floor(c-f)));1>=this.loaderstyle?(c+=f+(d?12:0),b=cr.floor(b-e)+0.5,c=cr.floor(c)+0.5,a.fillStyle="DodgerBlue",a.fillRect(b,c,Math.floor(g*this.progress),6),a.strokeStyle="black",a.strokeRect(b,c,g,6),a.strokeStyle="white",a.strokeRect(b-1,c-1,g+2,8)):2===this.loaderstyle&&(a.font="12pt Arial",a.fillStyle="#999",a.textBaseLine="middle",d=Math.round(100*this.progress)+"%",e=a.measureText?a.measureText(d):null,a.fillText(d,
b-(e?e.width:0)/2,c))}this.last_progress=this.progress}setTimeout(function(a){return function(){a.go()}}(this),100)}}};a.prototype.go_textures_done=function(){this.overlay_canvas&&(this.canvas.parentNode.removeChild(this.overlay_canvas),this.overlay_canvas=this.overlay_ctx=null);this.start_time=Date.now();this.last_fps_time=cr.performance_now();var a,b,c;if(this.uses_loader_layout){a=0;for(b=this.types_by_index.length;a<b;a++)c=this.types_by_index[a],!c.is_family&&(!c.isOnLoaderLayout&&c.plugin.is_world)&&
(c.onCreate(),cr.seal(c))}else this.isloading=!1;a=0;for(b=this.layouts_by_index.length;a<b;a++)this.layouts_by_index[a].createGlobalNonWorlds();2<=this.fullscreen_mode&&(a=this.original_width/this.original_height,b=this.width/this.height,this.aspect_scale=2!==this.fullscreen_mode&&b>a||2===this.fullscreen_mode&&b<a?this.height/this.original_height:this.width/this.original_width);this.first_layout?this.layouts[this.first_layout].startRunning():this.layouts_by_index[0].startRunning();this.uses_loader_layout||
(this.loadingprogress=1,this.trigger(cr.system_object.prototype.cnds.OnLoadFinished,null));this.tick();this.isDirectCanvas&&AppMobi.webview.execute("onGameReady();")};var l=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame||window.oRequestAnimationFrame;a.prototype.tick=function(){if(this.running_layout){var a=cr.performance_now();if(this.isArcade){var b=jQuery(window).width(),c=jQuery(window).height();if(this.lastwidth!==
b||this.lastheight!==c)this.lastwidth=b,this.lastheight=c,this.setSize(b,c)}this.isloading&&(b=this.areAllTexturesLoaded(),this.loadingprogress=this.progress,b&&(this.isloading=!1,this.progress=1,this.trigger(cr.system_object.prototype.cnds.OnLoadFinished,null)));this.logic();if((this.redraw||this.isCocoonJs)&&!this.is_WebGL_context_lost&&!this.suspendDrawing)this.redraw=!1,this.glwrap?this.drawGL():this.draw(),this.snapshotCanvas&&(this.canvas&&this.canvas.toDataURL&&(this.snapshotData=this.canvas.toDataURL(this.snapshotCanvas[0],
this.snapshotCanvas[1]),this.trigger(cr.system_object.prototype.cnds.OnCanvasSnapshot,null)),this.snapshotCanvas=null);this.tickcount++;this.execcount++;this.framecount++;this.logictime+=cr.performance_now()-a;this.isSuspended||(l?this.raf_id=l(this.tickFunc,this.canvas):this.timeout_id=setTimeout(this.tickFunc,this.isMobile?1:16))}};a.prototype.logic=function(){var a,b,c,d,e,f,g,m,h;a=cr.performance_now();1E3<=a-this.last_fps_time&&(this.last_fps_time+=1E3,this.fps=this.framecount,this.framecount=
0,this.cpuutilisation=this.logictime,this.logictime=0);this.measuring_dt&&(0!==this.last_tick_time&&(b=a-this.last_tick_time,0===b&&!this.isDebug?(this.zeroDtCount++,10<=this.zeroDtCout&&(this.measuring_dt=!1),this.dt1=1/60):(this.dt1=b/1E3,0.5<this.dt1?this.dt1=0:0.1<this.dt1&&(this.dt1=0.1))),this.last_tick_time=a);this.dt=this.dt1*this.timescale;this.kahanTime.add(this.dt);a=document.mozFullScreen||document.webkitIsFullScreen||document.fullScreen||this.isNodeFullscreen;2<=this.fullscreen_mode||
a&&0<this.fullscreen_scaling?(b=this.original_width/this.original_height,c=this.width/this.height,d=this.fullscreen_mode,a&&0<this.fullscreen_scaling&&(d=this.fullscreen_scaling),this.aspect_scale=2!==d&&c>b||2===d&&c<b?this.height/this.original_height:this.width/this.original_width,this.running_layout&&(this.running_layout.scrollToX(this.running_layout.scrollX),this.running_layout.scrollToY(this.running_layout.scrollY))):this.aspect_scale=1;this.ClearDeathRow();this.isInOnDestroy++;this.system.runWaits();
this.isInOnDestroy--;this.ClearDeathRow();this.isInOnDestroy++;a=0;for(b=this.types_by_index.length;a<b;a++)if(g=this.types_by_index[a],!(g.is_family||!g.behaviors.length&&!g.families.length)){c=0;for(d=g.instances.length;c<d;c++){m=g.instances[c];e=0;for(f=m.behavior_insts.length;e<f;e++)m.behavior_insts[e].tick()}}a=0;for(b=this.types_by_index.length;a<b;a++)if(g=this.types_by_index[a],!(g.is_family||!g.behaviors.length&&!g.families.length)){c=0;for(d=g.instances.length;c<d;c++){m=g.instances[c];
e=0;for(f=m.behavior_insts.length;e<f;e++)h=m.behavior_insts[e],h.posttick&&h.posttick()}}c=this.objects_to_tick.valuesRef();a=0;for(b=c.length;a<b;a++)c[a].tick();this.isInOnDestroy--;this.handleSaveLoad();for(a=0;this.changelayout&&10>a++;)this.doChangeLayout(this.changelayout);a=0;for(b=this.eventsheets_by_index.length;a<b;a++)this.eventsheets_by_index[a].hasRun=!1;this.running_layout.event_sheet&&this.running_layout.event_sheet.run();this.registered_collisions.length=0;this.layout_first_tick=
!1;this.isInOnDestroy++;a=0;for(b=this.types_by_index.length;a<b;a++)if(g=this.types_by_index[a],!(g.is_family||!g.behaviors.length&&!g.families.length)){c=0;for(d=g.instances.length;c<d;c++){m=g.instances[c];e=0;for(f=m.behavior_insts.length;e<f;e++)h=m.behavior_insts[e],h.tick2&&h.tick2()}}c=this.objects_to_tick2.valuesRef();a=0;for(b=c.length;a<b;a++)c[a].tick2();this.isInOnDestroy--};a.prototype.doChangeLayout=function(a){var b=this.running_layout;this.running_layout.stopRunning();var c,d,e,f,
g,m,h;if(this.glwrap){c=0;for(d=this.types_by_index.length;c<d;c++)g=this.types_by_index[c],g.is_family||g.unloadTextures&&((!g.global||0===g.instances.length)&&-1===a.initial_types.indexOf(g))&&g.unloadTextures()}b==a&&(this.system.waits.length=0);a.startRunning();c=0;for(d=this.types_by_index.length;c<d;c++)if(g=this.types_by_index[c],g.global||g.plugin.singleglobal){a=0;for(b=g.instances.length;a<b;a++){m=g.instances[a];if(m.onLayoutChange)m.onLayoutChange();if(m.behavior_insts){e=0;for(f=m.behavior_insts.length;e<
f;e++)if(h=m.behavior_insts[e],h.onLayoutChange)h.onLayoutChange()}}}this.layout_first_tick=this.redraw=!0;this.ClearDeathRow()};a.prototype.tickMe=function(a){this.objects_to_tick.add(a)};a.prototype.untickMe=function(a){this.objects_to_tick.remove(a)};a.prototype.tick2Me=function(a){this.objects_to_tick2.add(a)};a.prototype.untick2Me=function(a){this.objects_to_tick2.remove(a)};a.prototype.getDt=function(a){return!a||-1===a.my_timescale?this.dt:this.dt1*a.my_timescale};a.prototype.draw=function(){this.running_layout.draw(this.ctx);
this.isDirectCanvas&&this.ctx.present()};a.prototype.drawGL=function(){this.running_layout.drawGL(this.glwrap);this.glwrap.present()};a.prototype.addDestroyCallback=function(a){a&&this.destroycallbacks.push(a)};a.prototype.removeDestroyCallback=function(a){cr.arrayFindRemove(this.destroycallbacks,a)};a.prototype.getObjectByUID=function(a){return this.objectsByUid[a.toString()]};a.prototype.DestroyInstance=function(a){var b,c;if(!this.deathRow.contains(a)){this.deathRow.add(a);if(a.is_contained){b=
0;for(c=a.siblings.length;b<c;b++)this.DestroyInstance(a.siblings[b])}this.isInClearDeathRow&&this.deathRow.values_cache.push(a);this.isInOnDestroy++;this.trigger(Object.getPrototypeOf(a.type.plugin).cnds.OnDestroyed,a);this.isInOnDestroy--}};a.prototype.ClearDeathRow=function(){var a,b,c,d,e,g,f,m,h,k;this.isInClearDeathRow=!0;d=0;for(g=this.createRow.length;d<g;d++){a=this.createRow[d];b=a.type;b.instances.push(a);b.stale_iids=!0;e=0;for(f=b.families.length;e<f;e++)b.families[e].instances.push(a),
b.families[e].stale_iids=!0}this.createRow.length=0;g=this.deathRow.valuesRef();for(d=0;d<g.length;d++){a=g[d];b=a.type;c=b.instances;e=0;for(f=this.destroycallbacks.length;e<f;e++)this.destroycallbacks[e](a);cr.arrayFindRemove(c,a);a.layer&&(cr.arrayRemove(a.layer.instances,a.get_zindex()),a.layer.zindices_stale=!0);e=0;for(f=b.families.length;e<f;e++)cr.arrayFindRemove(b.families[e].instances,a),b.families[e].stale_iids=!0;if(a.behavior_insts){e=0;for(f=a.behavior_insts.length;e<f;e++){c=a.behavior_insts[e];
if(c.onDestroy)c.onDestroy();c.behavior.my_instances.remove(a)}}this.objects_to_tick.remove(a);this.objects_to_tick2.remove(a);e=0;for(f=this.system.waits.length;e<f;e++)if(h=this.system.waits[e],h.sols.hasOwnProperty(b.index)&&cr.arrayFindRemove(h.sols[b.index].insts,a),!b.is_family){c=0;for(m=b.families.length;c<m;c++)k=b.families[c],h.sols.hasOwnProperty(k.index)&&cr.arrayFindRemove(h.sols[k.index].insts,a)}if(a.onDestroy)a.onDestroy();this.objectsByUid.hasOwnProperty(a.uid.toString())&&delete this.objectsByUid[a.uid.toString()];
this.objectcount--;64>b.deadCache.length&&b.deadCache.push(a);b.stale_iids=!0}this.deathRow.isEmpty()||(this.redraw=!0);this.deathRow.clear();this.isInClearDeathRow=!1};a.prototype.createInstance=function(a,b,c,d){if(a.is_family){var e=cr.floor(Math.random()*a.members.length);return this.createInstance(a.members[e],b,c,d)}return!a.default_instance?null:this.createInstanceFromInit(a.default_instance,b,!1,c,d,!1)};var k=[];a.prototype.createInstanceFromInit=function(a,b,c,d,e,g){var f,m,h,l;if(!a)return null;
var p=this.types_by_index[a[1]],n=p.plugin.is_world;if(this.isloading&&n&&!p.isOnLoaderLayout||n&&!this.glwrap&&11===a[0][11])return null;var q=b;n||(b=null);var u;p.deadCache.length?(u=p.deadCache.pop(),u.recycled=!0,p.plugin.Instance.call(u,p)):(u=new p.plugin.Instance(p),u.recycled=!1);u.uid=c&&!g?a[2]:this.next_uid++;this.objectsByUid[u.uid.toString()]=u;u.puid=this.next_puid++;u.iid=0;u.get_iid=cr.inst_get_iid;p.stale_iids=!0;h=a[3];if(u.recycled)cr.wipe(u.extra);else{u.extra={};if("undefined"!==
typeof cr_is_preview){u.instance_var_names=[];u.instance_var_names.length=h.length;f=0;for(m=h.length;f<m;f++)u.instance_var_names[f]=h[f][1]}u.instance_vars=[];u.instance_vars.length=h.length}f=0;for(m=h.length;f<m;f++)u.instance_vars[f]=h[f][0];if(n){var B=a[0];u.x=cr.is_undefined(d)?B[0]:d;u.y=cr.is_undefined(e)?B[1]:e;u.z=B[2];u.width=B[3];u.height=B[4];u.depth=B[5];u.angle=B[6];u.opacity=B[7];u.hotspotX=B[8];u.hotspotY=B[9];u.blend_mode=B[10];f=B[11];!this.glwrap&&p.effect_types.length&&(u.blend_mode=
f);u.compositeOp=cr.effectToCompositeOp(u.blend_mode);this.gl&&cr.setGLBlend(u,u.blend_mode,this.gl);if(u.recycled){f=0;for(m=B[12].length;f<m;f++){h=0;for(l=B[12][f].length;h<l;h++)u.effect_params[f][h]=B[12][f][h]}u.bbox.set(0,0,0,0);u.bquad.set_from_rect(u.bbox);u.bbox_changed_callbacks.length=0}else{u.effect_params=B[12].slice(0);f=0;for(m=u.effect_params.length;f<m;f++)u.effect_params[f]=B[12][f].slice(0);u.active_effect_types=[];u.active_effect_flags=[];u.active_effect_flags.length=p.effect_types.length;
u.bbox=new cr.rect(0,0,0,0);u.bquad=new cr.quad;u.bbox_changed_callbacks=[];u.set_bbox_changed=cr.set_bbox_changed;u.add_bbox_changed_callback=cr.add_bbox_changed_callback;u.contains_pt=cr.inst_contains_pt;u.update_bbox=cr.update_bbox;u.get_zindex=cr.inst_get_zindex}f=0;for(m=p.effect_types.length;f<m;f++)u.active_effect_flags[f]=!0;u.updateActiveEffects=cr.inst_updateActiveEffects;u.updateActiveEffects();u.uses_shaders=!!u.active_effect_types.length;u.bbox_changed=!0;u.visible=!0;u.my_timescale=
-1;u.layer=b;u.zindex=b.instances.length;"undefined"===typeof u.collision_poly&&(u.collision_poly=null);this.redraw=u.collisionsEnabled=!0}u.toString=cr.inst_toString;var H;f=k.length=0;for(m=p.families.length;f<m;f++)k.push.apply(k,p.families[f].behaviors);k.push.apply(k,p.behaviors);if(u.recycled){f=0;for(m=k.length;f<m;f++){var E=k[f];H=u.behavior_insts[f];H.recycled=!0;E.behavior.Instance.call(H,E,u);B=a[4][f];h=0;for(l=B.length;h<l;h++)H.properties[h]=B[h];H.onCreate();E.behavior.my_instances.add(u)}}else{u.behavior_insts=
[];f=0;for(m=k.length;f<m;f++)E=k[f],H=new E.behavior.Instance(E,u),H.recycled=!1,H.properties=a[4][f].slice(0),H.onCreate(),cr.seal(H),u.behavior_insts.push(H),E.behavior.my_instances.add(u)}B=a[5];if(u.recycled){f=0;for(m=B.length;f<m;f++)u.properties[f]=B[f]}else u.properties=B.slice(0);this.createRow.push(u);b&&b.instances.push(u);this.objectcount++;if(p.is_contained){if(u.is_contained=!0,u.recycled?u.siblings.length=0:u.siblings=[],!c&&!g){f=0;for(m=p.container.length;f<m;f++)if(p.container[f]!==
p){if(!p.container[f].default_instance)return null;u.siblings.push(this.createInstanceFromInit(p.container[f].default_instance,q,!1,n?u.x:d,n?u.y:e,!0))}f=0;for(m=u.siblings.length;f<m;f++){u.siblings[f].siblings.push(u);for(h=0;h<m;h++)f!==h&&u.siblings[f].siblings.push(u.siblings[h])}}}else u.is_contained=!1,u.siblings=null;u.onCreate();u.recycled||cr.seal(u);f=0;for(m=u.behavior_insts.length;f<m;f++)u.behavior_insts[f].postCreate&&u.behavior_insts[f].postCreate();return u};a.prototype.getLayerByName=
function(a){var b,c;b=0;for(c=this.running_layout.layers.length;b<c;b++){var d=this.running_layout.layers[b];if(cr.equals_nocase(d.name,a))return d}return null};a.prototype.getLayerByNumber=function(a){a=cr.floor(a);0>a&&(a=0);a>=this.running_layout.layers.length&&(a=this.running_layout.layers.length-1);return this.running_layout.layers[a]};a.prototype.getLayer=function(a){return cr.is_number(a)?this.getLayerByNumber(a):this.getLayerByName(a.toString())};a.prototype.clearSol=function(a){var b,c;b=
0;for(c=a.length;b<c;b++)a[b].getCurrentSol().select_all=!0};a.prototype.pushCleanSol=function(a){var b,c;b=0;for(c=a.length;b<c;b++)a[b].pushCleanSol()};a.prototype.pushCopySol=function(a){var b,c;b=0;for(c=a.length;b<c;b++)a[b].pushCopySol()};a.prototype.popSol=function(a){var b,c;b=0;for(c=a.length;b<c;b++)a[b].popSol()};a.prototype.testAndSelectCanvasPointOverlap=function(a,b,c,d){var e=a.getCurrentSol(),f,g,m,h,k,l;if(e.select_all){d||(e.select_all=!1,e.instances.length=0);f=0;for(h=a.instances.length;f<
h;f++)if(m=a.instances[f],m.update_bbox(),k=m.layer.canvasToLayer(b,c,!0),l=m.layer.canvasToLayer(b,c,!1),m.contains_pt(k,l)){if(d)return!1;e.instances.push(m)}}else{f=g=0;for(h=e.instances.length;f<h;f++)if(m=e.instances[f],m.update_bbox(),k=m.layer.canvasToLayer(b,c,!0),l=m.layer.canvasToLayer(b,c,!1),m.contains_pt(k,l)){if(d)return!1;e.instances[g]=e.instances[f];g++}d||(e.instances.length=g)}a.applySolToContainer();return d?!0:e.hasObjects()};a.prototype.testOverlap=function(a,b){if(!a||!b||a===
b||!a.collisionsEnabled||!b.collisionsEnabled)return!1;a.update_bbox();b.update_bbox();var c=a.layer,d=b.layer,e,f,g,m,h,k;if(c!==d&&(c.parallaxX!==d.parallaxX||d.parallaxY!==d.parallaxY||c.scale!==d.scale||c.angle!==d.angle||c.zoomRate!==d.zoomRate)){h=a.collision_poly&&!a.collision_poly.is_empty();e=b.collision_poly&&!b.collision_poly.is_empty();h?(a.collision_poly.cache_poly(a.width,a.height,a.angle),this.temp_poly.set_from_poly(a.collision_poly)):this.temp_poly.set_from_quad(a.bquad,a.x,a.y,a.width,
a.height);h=this.temp_poly;e?(b.collision_poly.cache_poly(b.width,b.height,b.angle),this.temp_poly2.set_from_poly(b.collision_poly)):this.temp_poly2.set_from_quad(b.bquad,b.x,b.y,b.width,b.height);k=this.temp_poly2;e=0;for(f=h.pts_count;e<f;e++)g=h.pts_cache[2*e],m=h.pts_cache[2*e+1],h.pts_cache[2*e]=c.layerToCanvas(g+a.x,m+a.y,!0),h.pts_cache[2*e+1]=c.layerToCanvas(g+a.x,m+a.y,!1);e=0;for(f=k.pts_count;e<f;e++)g=k.pts_cache[2*e],m=k.pts_cache[2*e+1],k.pts_cache[2*e]=d.layerToCanvas(g+b.x,m+b.y,!0),
k.pts_cache[2*e+1]=d.layerToCanvas(g+b.x,m+b.y,!1);return h.intersects_poly(k,0,0)}if(!a.bbox.intersects_rect(b.bbox)||!a.bquad.intersects_quad(b.bquad))return!1;h=a.collision_poly&&!a.collision_poly.is_empty();e=b.collision_poly&&!b.collision_poly.is_empty();if(!h&&!e)return!0;h?(a.collision_poly.cache_poly(a.width,a.height,a.angle),h=a.collision_poly):(this.temp_poly.set_from_quad(a.bquad,a.x,a.y,a.width,a.height),h=this.temp_poly);e?(b.collision_poly.cache_poly(b.width,b.height,b.angle),k=b.collision_poly):
(this.temp_poly.set_from_quad(b.bquad,b.x,b.y,b.width,b.height),k=this.temp_poly);return h.intersects_poly(k,b.x-a.x,b.y-a.y)};var h=new cr.quad,m=new cr.rect(0,0,0,0);a.prototype.testRectOverlap=function(a,b){if(!b||!b.collisionsEnabled)return!1;b.update_bbox();if(!b.bbox.intersects_rect(a))return!1;h.set_from_rect(a);if(!b.bquad.intersects_quad(h))return!1;if(!b.collision_poly||b.collision_poly.is_empty())return!0;b.collision_poly.cache_poly(b.width,b.height,b.angle);h.offset(-a.left,-a.top);this.temp_poly.set_from_quad(h,
0,0,1,1);return b.collision_poly.intersects_poly(this.temp_poly,a.left-b.x,a.top-b.y)};a.prototype.testSegmentOverlap=function(a,b,c,d,e){if(!e||!e.collisionsEnabled)return!1;e.update_bbox();m.set(cr.min(a,c),cr.min(b,d),cr.max(a,c),cr.max(b,d));if(!e.bbox.intersects_rect(m)||!e.bquad.intersects_segment(a,b,c,d))return!1;if(!e.collision_poly||e.collision_poly.is_empty())return!0;e.collision_poly.cache_poly(e.width,e.height,e.angle);return e.collision_poly.intersects_segment(e.x,e.y,a,b,c,d)};a.prototype.typeHasBehavior=
function(a,b){if(!b)return!1;var c,d,e,f,g;c=0;for(d=a.behaviors.length;c<d;c++)if(a.behaviors[c].behavior instanceof b)return!0;if(!a.is_family){c=0;for(d=a.families.length;c<d;c++){g=a.families[c];e=0;for(f=g.behaviors.length;e<f;e++)if(g.behaviors[e].behavior instanceof b)return!0}}return!1};a.prototype.typeHasNoSaveBehavior=function(a){return this.typeHasBehavior(a,cr.behaviors.NoSave)};a.prototype.typeHasPersistBehavior=function(a){return this.typeHasBehavior(a,cr.behaviors.Persist)};a.prototype.getSolidBehavior=
function(){if(!cr.behaviors.solid)return null;var a,b;a=0;for(b=this.behaviors.length;a<b;a++)if(this.behaviors[a]instanceof cr.behaviors.solid)return this.behaviors[a];return null};a.prototype.testOverlapSolid=function(a){var b=this.getSolidBehavior();if(!b)return null;var c,d,e=b.my_instances.valuesRef(),b=0;for(c=e.length;b<c;++b)if(d=e[b],d.extra.solidEnabled&&this.testOverlap(a,d))return d;return null};a.prototype.testRectOverlapSolid=function(a){var b=this.getSolidBehavior();if(!b)return null;
var c,d,e=b.my_instances.valuesRef(),b=0;for(c=e.length;b<c;++b)if(d=e[b],d.extra.solidEnabled&&this.testRectOverlap(a,d))return d;return null};var n=[];a.prototype.testOverlapJumpThru=function(a,b){var c=null,d,e;if(!cr.behaviors.jumpthru)return null;d=0;for(e=this.behaviors.length;d<e;d++)if(this.behaviors[d]instanceof cr.behaviors.jumpthru){c=this.behaviors[d];break}if(!c)return null;var f=null;b&&(f=n,f.length=0);var g=c.my_instances.valuesRef();d=0;for(e=g.length;d<e;++d)if(c=g[d],c.extra.jumpthruEnabled&&
this.testOverlap(a,c))if(b)f.push(c);else return c;return f};a.prototype.pushOutSolid=function(a,b,c,d,e,f){d=d||50;var g=a.x,m=a.y,h,k=null,l=null;for(h=0;h<d;h++)if(a.x=g+b*h,a.y=m+c*h,a.set_bbox_changed(),!this.testOverlap(a,k)&&((k=this.testOverlapSolid(a))&&(l=k),!k&&(e&&(k=f?this.testOverlap(a,f)?f:null:this.testOverlapJumpThru(a))&&(l=k),!k)))return l&&this.pushInFractional(a,b,c,l,16),!0;a.x=g;a.y=m;a.set_bbox_changed();return!1};a.prototype.pushOut=function(a,b,c,d,e){d=d||50;var f=a.x,g=
a.y,m;for(m=0;m<d;m++)if(a.x=f+b*m,a.y=g+c*m,a.set_bbox_changed(),!this.testOverlap(a,e))return!0;a.x=f;a.y=g;a.set_bbox_changed();return!1};a.prototype.pushInFractional=function(a,b,c,d,e){var f=2,g,m=!1;g=!1;for(var h=a.x,k=a.y;f<=e;)g=1/f,f*=2,a.x+=b*g*(m?1:-1),a.y+=c*g*(m?1:-1),a.set_bbox_changed(),this.testOverlap(a,d)?g=m=!0:(g=m=!1,h=a.x,k=a.y);g&&(a.x=h,a.y=k,a.set_bbox_changed())};a.prototype.pushOutSolidNearest=function(a,b){var c=cr.is_undefined(b)?100:b,d=0,e=a.x,f=a.y,g=0,m=0,h=0,k=this.testOverlapSolid(a);
if(!k)return!0;for(;d<=c;){switch(g){case 0:m=0;h=-1;d++;break;case 1:m=1;h=-1;break;case 2:m=1;h=0;break;case 3:h=m=1;break;case 4:m=0;h=1;break;case 5:m=-1;h=1;break;case 6:m=-1;h=0;break;case 7:h=m=-1}g=(g+1)%8;a.x=cr.floor(e+m*d);a.y=cr.floor(f+h*d);a.set_bbox_changed();if(!this.testOverlap(a,k)&&(k=this.testOverlapSolid(a),!k))return!0}a.x=e;a.y=f;a.set_bbox_changed();return!1};a.prototype.registerCollision=function(a,b){a.collisionsEnabled&&b.collisionsEnabled&&this.registered_collisions.push([a,
b])};a.prototype.checkRegisteredCollision=function(a,b){var c,d,e;c=0;for(d=this.registered_collisions.length;c<d;c++)if(e=this.registered_collisions[c],e[0]==a&&e[1]==b||e[0]==b&&e[1]==a)return!0;return!1};a.prototype.calculateSolidBounceAngle=function(a,b,c,d){var e=a.x,f=a.y,g=cr.max(10,cr.distanceTo(b,c,e,f)),m=cr.angleTo(b,c,e,f),h=d||this.testOverlapSolid(a);if(!h)return cr.clamp_angle(m+cr.PI);var k=h,l,p,n,q,B=cr.to_radians(5);for(l=1;36>l;l++)if(p=m-l*B,a.x=b+Math.cos(p)*g,a.y=c+Math.sin(p)*
g,a.set_bbox_changed(),!this.testOverlap(a,k)&&(k=d?null:this.testOverlapSolid(a),!k)){n=p;break}36===l&&(n=cr.clamp_angle(m+cr.PI));k=h;for(l=1;36>l;l++)if(p=m+l*B,a.x=b+Math.cos(p)*g,a.y=c+Math.sin(p)*g,a.set_bbox_changed(),!this.testOverlap(a,k)&&(k=d?null:this.testOverlapSolid(a),!k)){q=p;break}36===l&&(q=cr.clamp_angle(m+cr.PI));a.x=e;a.y=f;a.set_bbox_changed();if(q===n)return q;a=cr.angleDiff(q,n)/2;a=cr.angleClockwise(q,n)?cr.clamp_angle(n+a+cr.PI):cr.clamp_angle(q+a);n=Math.cos(m);m=Math.sin(m);
q=Math.cos(a);a=Math.sin(a);b=n*q+m*a;return cr.angleTo(0,0,n-2*b*q,m-2*b*a)};var q=[],p=-1;a.prototype.trigger=function(a,b,c){if(!this.running_layout)return!1;var d=this.running_layout.event_sheet;if(!d)return!1;p++;p===q.length?q.push(new cr.ObjectSet):q[p].clear();a=this.triggerOnSheet(a,b,d,c);p--;return a};a.prototype.triggerOnSheet=function(a,b,c,d){var e=q[p];if(e.contains(c))return!1;e.add(c);var e=c.includes.valuesRef(),f=!1,g,m,h;g=0;for(m=e.length;g<m;g++)e[g].isActive()&&(h=this.triggerOnSheet(a,
b,e[g].include_sheet,d),f=f||h);if(b){h=this.triggerOnSheetForTypeName(a,b,b.type.name,c,d);f=f||h;g=0;for(m=b.type.families.length;g<m;g++)h=this.triggerOnSheetForTypeName(a,b,b.type.families[g].name,c,d),f=f||h}else h=this.triggerOnSheetForTypeName(a,b,"system",c,d),f=f||h;return f};a.prototype.triggerOnSheetForTypeName=function(a,b,c,d,e){var f,g=!1,m=!1,m="undefined"!==typeof e,h=(m?d.fasttriggers:d.triggers)[c];if(!h)return g;var k=null;d=0;for(f=h.length;d<f;d++)if(h[d].method==a){k=h[d].evs;
break}if(!k)return g;a=m?k[e]:k;if(!a)return null;d=0;for(f=a.length;d<f;d++)e=a[d][0],m=a[d][1],m=this.executeSingleTrigger(b,c,e,m),g=g||m;return g};a.prototype.executeSingleTrigger=function(a,b,c,d){var e,f,g=!1;this.trigger_depth++;var m=this.getCurrentEventStack().current_event;m&&this.pushCleanSol(m.solModifiersIncludingParents);var h=1<this.trigger_depth;this.pushCleanSol(c.solModifiersIncludingParents);h&&this.pushLocalVarStack();var k=this.pushEventStack(c);k.current_event=c;a&&(e=this.types[b].getCurrentSol(),
e.select_all=!1,e.instances.length=1,e.instances[0]=a,this.types[b].applySolToContainer());a=!0;if(c.parent){b=k.temp_parents_arr;for(e=c.parent;e;)b.push(e),e=e.parent;b.reverse();e=0;for(f=b.length;e<f;e++)if(!b[e].run_pretrigger()){a=!1;break}}a&&(this.execcount++,c.orblock?c.run_orblocktrigger(d):c.run(),g=g||k.last_event_true);this.popEventStack();h&&this.popLocalVarStack();this.popSol(c.solModifiersIncludingParents);m&&this.popSol(m.solModifiersIncludingParents);0===this.isInOnDestroy&&(0===
p&&!this.isRunningEvents&&(!this.deathRow.isEmpty()||this.createRow.length))&&this.ClearDeathRow();this.trigger_depth--;return g};a.prototype.getCurrentCondition=function(){var a=this.getCurrentEventStack();return a.current_event.conditions[a.cndindex]};a.prototype.getCurrentAction=function(){var a=this.getCurrentEventStack();return a.current_event.actions[a.actindex]};a.prototype.pushLocalVarStack=function(){this.localvar_stack_index++;this.localvar_stack_index>=this.localvar_stack.length&&this.localvar_stack.push([])};
a.prototype.popLocalVarStack=function(){this.localvar_stack_index--};a.prototype.getCurrentLocalVarStack=function(){return this.localvar_stack[this.localvar_stack_index]};a.prototype.pushEventStack=function(a){this.event_stack_index++;this.event_stack_index>=this.event_stack.length&&this.event_stack.push(new cr.eventStackFrame);var b=this.getCurrentEventStack();b.reset(a);return b};a.prototype.popEventStack=function(){this.event_stack_index--};a.prototype.getCurrentEventStack=function(){return this.event_stack[this.event_stack_index]};
a.prototype.pushLoopStack=function(a){this.loop_stack_index++;this.loop_stack_index>=this.loop_stack.length&&this.loop_stack.push(cr.seal({name:a,index:0,stopped:!1}));var b=this.getCurrentLoop();b.name=a;b.index=0;b.stopped=!1;return b};a.prototype.popLoopStack=function(){this.loop_stack_index--};a.prototype.getCurrentLoop=function(){return this.loop_stack[this.loop_stack_index]};a.prototype.getEventVariableByName=function(a,b){for(var c,d,e,f,g,m;b;){c=0;for(d=b.subevents.length;c<d;c++)if(m=b.subevents[c],
m instanceof cr.eventvariable&&cr.equals_nocase(a,m.name))return m;b=b.parent}c=0;for(d=this.eventsheets_by_index.length;c<d;c++){g=this.eventsheets_by_index[c];e=0;for(f=g.events.length;e<f;e++)if(m=g.events[e],m instanceof cr.eventvariable&&cr.equals_nocase(a,m.name))return m}return null};a.prototype.getLayoutBySid=function(a){var b,c;b=0;for(c=this.layouts_by_index.length;b<c;b++)if(this.layouts_by_index[b].sid===a)return this.layouts_by_index[b];return null};a.prototype.getObjectTypeBySid=function(a){var b,
c;b=0;for(c=this.types_by_index.length;b<c;b++)if(this.types_by_index[b].sid===a)return this.types_by_index[b];return null};a.prototype.getGroupBySid=function(a){var b,c;b=0;for(c=this.allGroups.length;b<c;b++)if(this.allGroups[b].sid===a)return this.allGroups[b];return null};a.prototype.signalContinuousPreview=function(){this.signalledContinuousPreview=!0};a.prototype.handleSaveLoad=function(){var a=this,b=this.saveToSlot,f=this.lastSaveJson,g=this.loadFromSlot,m=!1;this.signalledContinuousPreview&&
(m=!0,b="__c2_continuouspreview",this.signalledContinuousPreview=!1);if(b.length){this.ClearDeathRow();f=this.saveToJSONString();if(window.indexedDB&&!this.isCocoonJs)c(b,f,function(){cr.logexport("Saved state to IndexedDB storage ("+f.length+" bytes)");a.lastSaveJson=f;a.trigger(cr.system_object.prototype.cnds.OnSaveComplete,null);a.lastSaveJson="";m&&e()},function(c){try{localStorage.setItem("__c2save_"+b,f),cr.logexport("Saved state to WebStorage ("+f.length+" bytes)"),a.lastSaveJson=f,a.trigger(cr.system_object.prototype.cnds.OnSaveComplete,
null),a.lastSaveJson="",m&&e()}catch(d){cr.logexport("Failed to save game state: "+c+"; "+d)}});else try{localStorage.setItem("__c2save_"+b,f),cr.logexport("Saved state to WebStorage ("+f.length+" bytes)"),a.lastSaveJson=f,this.trigger(cr.system_object.prototype.cnds.OnSaveComplete,null),a.lastSaveJson="",m&&e()}catch(h){cr.logexport("Error saving to WebStorage: "+h)}this.loadFromJson=this.loadFromSlot=this.saveToSlot=""}g.length&&(window.indexedDB&&!this.isCocoonJs?d(g,function(b){b?(a.loadFromJson=
b,cr.logexport("Loaded state from IndexedDB storage ("+a.loadFromJson.length+" bytes)")):(a.loadFromJson=localStorage.getItem("__c2save_"+g)||"",cr.logexport("Loaded state from WebStorage ("+a.loadFromJson.length+" bytes)"));a.suspendDrawing=!1;a.loadFromJson.length||a.trigger(cr.system_object.prototype.cnds.OnLoadFailed,null)},function(b){a.loadFromJson=localStorage.getItem("__c2save_"+g)||"";cr.logexport("Loaded state from WebStorage ("+a.loadFromJson.length+" bytes)");a.suspendDrawing=!1;a.loadFromJson.length||
a.trigger(cr.system_object.prototype.cnds.OnLoadFailed,null)}):(this.loadFromJson=localStorage.getItem("__c2save_"+g)||"",cr.logexport("Loaded state from WebStorage ("+this.loadFromJson.length+" bytes)"),this.suspendDrawing=!1,a.loadFromJson.length||a.trigger(cr.system_object.prototype.cnds.OnLoadFailed,null)),this.saveToSlot=this.loadFromSlot="");this.loadFromJson.length&&(this.ClearDeathRow(),this.loadFromJSONString(this.loadFromJson),this.lastSaveJson=this.loadFromJson,this.trigger(cr.system_object.prototype.cnds.OnLoadComplete,
null),this.loadFromJson=this.lastSaveJson="")};a.prototype.saveToJSONString=function(){var a,b,c,d,e,f,m,h={c2save:!0,version:1,rt:{time:this.kahanTime.sum,timescale:this.timescale,tickcount:this.tickcount,execcount:this.execcount,next_uid:this.next_uid,running_layout:this.running_layout.sid,start_time_offset:Date.now()-this.start_time},types:{},layouts:{},events:{groups:{},cnds:{},acts:{},vars:{}}};a=0;for(b=this.types_by_index.length;a<b;a++)if(e=this.types_by_index[a],!e.is_family&&!this.typeHasNoSaveBehavior(e)){f=
{instances:[]};cr.hasAnyOwnProperty(e.extra)&&(f.ex=g(e.extra));c=0;for(d=e.instances.length;c<d;c++)f.instances.push(this.saveInstanceToJSON(e.instances[c]));h.types[e.sid.toString()]=f}a=0;for(b=this.layouts_by_index.length;a<b;a++)c=this.layouts_by_index[a],h.layouts[c.sid.toString()]=c.saveToJSON();d=h.events.groups;a=0;for(b=this.allGroups.length;a<b;a++)c=this.allGroups[a],d[c.sid.toString()]=!!this.activeGroups[c.group_name];b=h.events.cnds;for(m in this.cndsBySid)this.cndsBySid.hasOwnProperty(m)&&
(a=this.cndsBySid[m],cr.hasAnyOwnProperty(a.extra)&&(b[m]={ex:g(a.extra)}));b=h.events.acts;for(m in this.actsBySid)this.actsBySid.hasOwnProperty(m)&&(a=this.actsBySid[m],cr.hasAnyOwnProperty(a.extra)&&(b[m]={ex:a.extra}));b=h.events.vars;for(m in this.varsBySid)if(this.varsBySid.hasOwnProperty(m)&&(a=this.varsBySid[m],!a.is_constant&&(!a.parent||a.is_static)))b[m]=a.data;h.system=this.system.saveToJSON();return JSON.stringify(h)};a.prototype.refreshUidMap=function(){var a,b,c,d,e,f;this.objectsByUid=
{};a=0;for(b=this.types_by_index.length;a<b;a++)if(c=this.types_by_index[a],!c.is_family){d=0;for(e=c.instances.length;d<e;d++)f=c.instances[d],this.objectsByUid[f.uid.toString()]=f}};a.prototype.loadFromJSONString=function(a){a=JSON.parse(a);if(a.c2save&&!(1<a.version)){var b=a.rt;this.kahanTime.reset();this.kahanTime.sum=b.time;this.timescale=b.timescale;this.tickcount=b.tickcount;this.execcount=b.execcount;this.start_time=Date.now()-b.start_time_offset;var c=b.running_layout;if(c!==this.running_layout.sid)if(c=
this.getLayoutBySid(c))this.doChangeLayout(c);else return;this.isLoadingState=!0;var d,e,f,g,m,h,k;h=a.types;for(e in h)if(h.hasOwnProperty(e)&&(g=this.getObjectTypeBySid(parseInt(e,10)))&&!g.is_family&&!this.typeHasNoSaveBehavior(g)){h[e].ex?g.extra=h[e].ex:cr.wipe(g.extra);m=g.instances;f=h[e].instances;c=0;for(d=cr.min(m.length,f.length);c<d;c++)this.loadInstanceFromJSON(m[c],f[c]);c=f.length;for(d=m.length;c<d;c++)this.DestroyInstance(m[c]);c=m.length;for(d=f.length;c<d;c++){m=null;if(g.plugin.is_world&&
(m=this.running_layout.getLayerBySid(f[c].w.l),!m))continue;m=this.createInstanceFromInit(g.default_instance,m,!1,0,0,!0);this.loadInstanceFromJSON(m,f[c])}g.stale_iids=!0}this.ClearDeathRow();this.refreshUidMap();d=a.layouts;for(e in d)d.hasOwnProperty(e)&&(c=this.getLayoutBySid(parseInt(e,10)))&&c.loadFromJSON(d[e]);d=a.events.groups;for(e in d)d.hasOwnProperty(e)&&(c=this.getGroupBySid(parseInt(e,10)))&&(this.activeGroups[c.group_name]=d[e]);c=a.events.cnds;for(e in c)c.hasOwnProperty(e)&&this.cndsBySid.hasOwnProperty(e)&&
(this.cndsBySid[e].extra=c[e].ex);c=a.events.acts;for(e in c)c.hasOwnProperty(e)&&this.actsBySid.hasOwnProperty(e)&&(this.actsBySid[e].extra=c[e].ex);c=a.events.vars;for(e in c)c.hasOwnProperty(e)&&this.varsBySid.hasOwnProperty(e)&&(this.varsBySid[e].data=c[e]);this.next_uid=b.next_uid;this.isLoadingState=!1;this.system.loadFromJSON(a.system);c=0;for(d=this.types_by_index.length;c<d;c++)if(g=this.types_by_index[c],!g.is_family){e=0;for(a=g.instances.length;e<a;e++){m=g.instances[e];if(g.is_contained){h=
m.get_iid();b=m.siblings.length=0;for(f=g.container.length;b<f;b++)k=g.container[b],g!==k&&m.siblings.push(k.instances[h])}m.afterLoad&&m.afterLoad();if(m.behavior_insts){b=0;for(f=m.behavior_insts.length;b<f;b++)h=m.behavior_insts[b],h.afterLoad&&h.afterLoad()}}}this.redraw=!0}};a.prototype.saveInstanceToJSON=function(a){var b,c,d,e,f;e=a.type;d=e.plugin;var m={uid:a.uid};cr.hasAnyOwnProperty(a.extra)&&(m.ex=g(a.extra));if(a.instance_vars&&a.instance_vars.length){m.ivs={};b=0;for(c=a.instance_vars.length;b<
c;b++)m.ivs[a.type.instvar_sids[b].toString()]=a.instance_vars[b]}if(d.is_world){d={x:a.x,y:a.y,w:a.width,h:a.height,l:a.layer.sid,zi:a.get_zindex()};0!==a.angle&&(d.a=a.angle);1!==a.opacity&&(d.o=a.opacity);0.5!==a.hotspotX&&(d.hX=a.hotspotX);0.5!==a.hotspotY&&(d.hY=a.hotspotY);0!==a.blend_mode&&(d.bm=a.blend_mode);a.visible||(d.v=a.visible);a.collisionsEnabled||(d.ce=a.collisionsEnabled);-1!==a.my_timescale&&(d.mts=a.my_timescale);if(e.effect_types.length){d.fx=[];b=0;for(c=e.effect_types.length;b<
c;b++)f=e.effect_types[b],d.fx.push({name:f.name,active:a.active_effect_flags[f.index],params:a.effect_params[f.index]})}m.w=d}if(a.behavior_insts&&a.behavior_insts.length){m.behs={};b=0;for(c=a.behavior_insts.length;b<c;b++)e=a.behavior_insts[b],e.saveToJSON&&(m.behs[e.type.sid.toString()]=e.saveToJSON())}a.saveToJSON&&(m.data=a.saveToJSON());return m};a.prototype.getInstanceVarIndexBySid=function(a,b){var c,d;c=0;for(d=a.instvar_sids.length;c<d;c++)if(a.instvar_sids[c]===b)return c;return-1};a.prototype.getBehaviorIndexBySid=
function(a,b){var c,d;c=0;for(d=a.behavior_insts.length;c<d;c++)if(a.behavior_insts[c].type.sid===b)return c;return-1};a.prototype.loadInstanceFromJSON=function(a,b){var c,d,e,f,g,m;m=a.type;e=m.plugin;a.uid=b.uid;b.ex?a.extra=b.ex:cr.wipe(a.extra);if(d=b.ivs)for(c in d)d.hasOwnProperty(c)&&(f=this.getInstanceVarIndexBySid(m,parseInt(c,10)),0>f||f>=a.instance_vars.length||(a.instance_vars[f]=d[c]));if(e.is_world){f=b.w;a.layer.sid!==f.l&&(d=a.layer,a.layer=this.running_layout.getLayerBySid(f.l),a.layer?
(a.layer.instances.push(a),a.layer.zindices_stale=!0,cr.arrayFindRemove(d.instances,a),d.zindices_stale=!0):(a.layer=d,this.DestroyInstance(a)));a.x=f.x;a.y=f.y;a.width=f.w;a.height=f.h;a.zindex=f.zi;a.angle=f.hasOwnProperty("a")?f.a:0;a.opacity=f.hasOwnProperty("o")?f.o:1;a.hotspotX=f.hasOwnProperty("hX")?f.hX:0.5;a.hotspotY=f.hasOwnProperty("hY")?f.hY:0.5;a.visible=f.hasOwnProperty("v")?f.v:!0;a.collisionsEnabled=f.hasOwnProperty("ce")?f.ce:!0;a.my_timescale=f.hasOwnProperty("mts")?f.mts:-1;a.blend_mode=
f.hasOwnProperty("bm")?f.bm:0;a.compositeOp=cr.effectToCompositeOp(a.blend_mode);this.gl&&cr.setGLBlend(a,a.blend_mode,this.gl);a.set_bbox_changed();if(f.hasOwnProperty("fx")){d=0;for(e=f.fx.length;d<e;d++)g=m.getEffectIndexByName(f.fx[d].name),0>g||(a.active_effect_flags[g]=f.fx[d].active,a.effect_params[g]=f.fx[d].params)}a.updateActiveEffects()}if(m=b.behs)for(c in m)m.hasOwnProperty(c)&&(f=this.getBehaviorIndexBySid(a,parseInt(c,10)),0>f||a.behavior_insts[f].loadFromJSON(m[c]));b.data&&a.loadFromJSON(b.data)};
cr.runtime=a;cr.createRuntime=function(b){return new a(document.getElementById(b))};cr.createDCRuntime=function(b,c){return new a({dc:!0,width:b,height:c})};window.cr_createRuntime=cr.createRuntime;window.cr_createDCRuntime=cr.createDCRuntime;window.createCocoonJSRuntime=function(){window.c2cocoonjs=!0;var b=document.createElement("screencanvas")||document.createElement("canvas");document.body.appendChild(b);b=new a(b);window.c2runtime=b;window.addEventListener("orientationchange",function(){window.c2runtime.setSize(window.innerWidth,
window.innerHeight)});window.c2runtime.setSize(window.innerWidth,window.innerHeight);return b}})();window.cr_getC2Runtime=function(){var a=document.getElementById("c2canvas");return a?a.c2runtime:window.c2runtime?window.c2runtime:null};window.cr_sizeCanvas=function(a,b){if(!(0===a||0===b)){var c=window.cr_getC2Runtime();c&&c.setSize(a,b)}};window.cr_setSuspended=function(a){var b=window.cr_getC2Runtime();b&&b.setSuspended(a)};
(function(){function a(a,b){this.runtime=a;this.event_sheet=null;this.scrollX=this.runtime.original_width/2;this.scrollY=this.runtime.original_height/2;this.scale=1;this.angle=0;this.first_visit=!0;this.name=b[0];this.width=b[1];this.height=b[2];this.unbounded_scrolling=b[3];this.sheetname=b[4];this.sid=b[5];var c=b[6],d,k;this.layers=[];this.initial_types=[];d=0;for(k=c.length;d<k;d++){var h=new cr.layer(this,c[d]);h.number=d;cr.seal(h);this.layers.push(h)}c=b[7];this.initial_nonworld=[];d=0;for(k=
c.length;d<k;d++){var h=c[d],m=this.runtime.types_by_index[h[1]];m.default_instance||(m.default_instance=h);this.initial_nonworld.push(h);-1===this.initial_types.indexOf(m)&&this.initial_types.push(m)}this.effect_types=[];this.active_effect_types=[];this.effect_params=[];d=0;for(k=b[8].length;d<k;d++)this.effect_types.push({id:b[8][d][0],name:b[8][d][1],shaderindex:-1,active:!0,index:d}),this.effect_params.push(b[8][d][2].slice(0));this.updateActiveEffects();this.rcTex=new cr.rect(0,0,1,1);this.rcTex2=
new cr.rect(0,0,1,1);this.persist_data={}}function b(a,b){this.layout=a;this.runtime=a.runtime;this.instances=[];this.scale=1;this.angle=0;this.disableAngle=!1;this.tmprect=new cr.rect(0,0,0,0);this.tmpquad=new cr.quad;this.viewBottom=this.viewTop=this.viewRight=this.viewLeft=0;this.zindices_stale=!1;this.name=b[0];this.index=b[1];this.sid=b[2];this.visible=b[3];this.background_color=b[4];this.transparent=b[5];this.parallaxX=b[6];this.parallaxY=b[7];this.opacity=b[8];this.forceOwnTexture=b[9];this.zoomRate=
b[10];this.blend_mode=b[11];this.effect_fallback=b[12];this.compositeOp="source-over";this.destBlend=this.srcBlend=0;this.render_offscreen=!1;var c=b[13],d,k;this.initial_instances=[];d=0;for(k=c.length;d<k;d++){var h=c[d],m=this.runtime.types_by_index[h[1]];m.default_instance||(m.default_instance=h);this.initial_instances.push(h);-1===this.layout.initial_types.indexOf(m)&&this.layout.initial_types.push(m)}this.effect_types=[];this.active_effect_types=[];this.effect_params=[];d=0;for(k=b[14].length;d<
k;d++)this.effect_types.push({id:b[14][d][0],name:b[14][d][1],shaderindex:-1,active:!0,index:d}),this.effect_params.push(b[14][d][2].slice(0));this.updateActiveEffects();this.rcTex=new cr.rect(0,0,1,1);this.rcTex2=new cr.rect(0,0,1,1)}function c(a,b){return a.zindex-b.zindex}a.prototype.saveObjectToPersist=function(a){var b=a.type.sid.toString();this.persist_data.hasOwnProperty(b)||(this.persist_data[b]=[]);this.persist_data[b].push(this.runtime.saveInstanceToJSON(a))};a.prototype.hasOpaqueBottomLayer=
function(){var a=this.layers[0];return!a.transparent&&1===a.opacity&&!a.forceOwnTexture&&a.visible};a.prototype.updateActiveEffects=function(){this.active_effect_types.length=0;var a,b,c;a=0;for(b=this.effect_types.length;a<b;a++)c=this.effect_types[a],c.active&&this.active_effect_types.push(c)};a.prototype.getEffectByName=function(a){var b,c,d;b=0;for(c=this.effect_types.length;b<c;b++)if(d=this.effect_types[b],d.name===a)return d;return null};var d=[];a.prototype.startRunning=function(){this.sheetname&&
(this.event_sheet=this.runtime.eventsheets[this.sheetname]);this.runtime.running_layout=this;this.scrollX=this.runtime.original_width/2;this.scrollY=this.runtime.original_height/2;var a,b,f,l,k,h,m;a=0;for(f=this.runtime.types_by_index.length;a<f;a++)if(b=this.runtime.types_by_index[a],!b.is_family){k=b.instances;b=0;for(l=k.length;b<l;b++)if(h=k[b],h.layer){var n=h.layer.number;n>=this.layers.length&&(n=this.layers.length-1);h.layer=this.layers[n];h.layer.instances.push(h);h.layer.zindices_stale=
!0}}d.length=0;this.boundScrolling();a=0;for(f=this.layers.length;a<f;a++)h=this.layers[a],h.createInitialInstances(),h.disableAngle=!0,b=h.canvasToLayer(0,0,!0),l=h.canvasToLayer(0,0,!1),h.disableAngle=!1,this.runtime.pixel_rounding&&(b=b+0.5|0,l=l+0.5|0),h.rotateViewport(b,l,null);k=!1;if(!this.first_visit){for(m in this.persist_data)if(this.persist_data.hasOwnProperty(m)&&(b=this.runtime.getObjectTypeBySid(parseInt(m,10)))&&!b.is_family&&this.runtime.typeHasPersistBehavior(b)){l=this.persist_data[m];
a=0;for(f=l.length;a<f;a++){h=null;if(b.plugin.is_world&&(h=this.getLayerBySid(l[a].w.l),!h))continue;h=this.runtime.createInstanceFromInit(b.default_instance,h,!1,0,0,!0);this.runtime.loadInstanceFromJSON(h,l[a]);k=!0;d.push(h)}l.length=0}a=0;for(f=this.layers.length;a<f;a++)this.layers[a].instances.sort(c),this.layers[a].zindices_stale=!0}k&&(this.runtime.ClearDeathRow(),this.runtime.refreshUidMap());for(a=0;a<d.length;a++)if(h=d[a],h.type.is_contained){f=h.get_iid();b=0;for(l=h.type.container.length;b<
l;b++)m=h.type.container[b],h.type!==m&&(m.instances.length>f?h.siblings.push(m.instances[f]):m.default_instance&&(k=this.runtime.createInstanceFromInit(m.default_instance,h.layer,!0,h.x,h.y,!0),this.runtime.ClearDeathRow(),m.updateIIDs(),h.siblings.push(k),d.push(k)))}a=0;for(f=this.initial_nonworld.length;a<f;a++)this.runtime.createInstanceFromInit(this.initial_nonworld[a],null,!0);this.runtime.changelayout=null;this.runtime.ClearDeathRow();if(this.runtime.ctx&&!this.runtime.isDomFree){a=0;for(f=
this.runtime.types_by_index.length;a<f;a++)m=this.runtime.types_by_index[a],!m.is_family&&(m.instances.length&&m.preloadCanvas2D)&&m.preloadCanvas2D(this.runtime.ctx)}a=0;for(f=d.length;a<f;a++)h=d[a],this.runtime.trigger(Object.getPrototypeOf(h.type.plugin).cnds.OnCreated,h);d.length=0;this.runtime.trigger(cr.system_object.prototype.cnds.OnLayoutStart,null);this.first_visit=!1};a.prototype.createGlobalNonWorlds=function(){var a,b,c,d,k;b=a=0;for(c=this.initial_nonworld.length;a<c;a++)d=this.initial_nonworld[a],
k=this.runtime.types_by_index[d[1]],k.global?this.runtime.createInstanceFromInit(d,null,!0):(this.initial_nonworld[b]=d,b++);this.initial_nonworld.length=b};a.prototype.stopRunning=function(){this.runtime.trigger(cr.system_object.prototype.cnds.OnLayoutEnd,null);this.runtime.system.waits.length=0;var a,b,c,d,k,h;a=0;for(b=this.layers.length;a<b;a++){k=this.layers[a].instances;c=0;for(d=k.length;c<d;c++)h=k[c],h.type.global||(this.runtime.typeHasPersistBehavior(h.type)&&this.saveObjectToPersist(h),
this.runtime.DestroyInstance(h));this.runtime.ClearDeathRow();k.length=0;this.layers[a].zindices_stale=!0}a=0;for(b=this.runtime.types_by_index.length;a<b;a++)if(k=this.runtime.types_by_index[a],!k.global&&!k.plugin.is_world&&!k.plugin.singleglobal&&!k.is_family){c=0;for(d=k.instances.length;c<d;c++)this.runtime.DestroyInstance(k.instances[c]);this.runtime.ClearDeathRow()}};a.prototype.draw=function(a){a.globalAlpha=1;a.globalCompositeOperation="source-over";this.runtime.clearBackground&&!this.hasOpaqueBottomLayer()&&
a.clearRect(0,0,this.runtime.width,this.runtime.height);var b,c,d;b=0;for(c=this.layers.length;b<c;b++)d=this.layers[b],d.visible&&(0<d.opacity&&11!==d.blend_mode)&&d.draw(a)};a.prototype.drawGL=function(a){var b=0<this.active_effect_types.length||this.runtime.uses_background_blending;if(b){this.runtime.layout_tex||(this.runtime.layout_tex=a.createEmptyTexture(this.runtime.width,this.runtime.height,this.runtime.linearSampling));if(this.runtime.layout_tex.c2width!==this.runtime.width||this.runtime.layout_tex.c2height!==
this.runtime.height)a.deleteTexture(this.runtime.layout_tex),this.runtime.layout_tex=a.createEmptyTexture(this.runtime.width,this.runtime.height,this.runtime.linearSampling);a.setRenderingToTexture(this.runtime.layout_tex)}this.runtime.clearBackground&&!this.hasOpaqueBottomLayer()&&a.clear(0,0,0,0);var c,d;c=0;for(d=this.layers.length;c<d;c++)this.layers[c].visible&&0<this.layers[c].opacity&&this.layers[c].drawGL(a);b&&(1>=this.active_effect_types.length?(1===this.active_effect_types.length?(b=this.active_effect_types[0].index,
a.switchProgram(this.active_effect_types[0].shaderindex),a.setProgramParameters(null,1/this.runtime.width,1/this.runtime.height,0,0,1,1,this.scale,this.effect_params[b]),a.programIsAnimated(this.active_effect_types[0].shaderindex)&&(this.runtime.redraw=!0)):a.switchProgram(0),a.setRenderingToTexture(null),a.setOpacity(1),a.setTexture(this.runtime.layout_tex),a.setAlphaBlend(),a.resetModelView(),a.updateModelView(),b=this.runtime.width/2,c=this.runtime.height/2,a.quad(-b,c,b,c,b,-c,-b,-c),a.setTexture(null)):
this.renderEffectChain(a,null,null,null))};a.prototype.getRenderTarget=function(){return 0<this.active_effect_types.length||this.runtime.uses_background_blending?this.runtime.layout_tex:null};a.prototype.getMinLayerScale=function(){var a=this.layers[0].getScale(),b,c,d;b=1;for(c=this.layers.length;b<c;b++)d=this.layers[b],0===d.parallaxX&&0===d.parallaxY||d.getScale()<a&&(a=d.getScale());return a};a.prototype.scrollToX=function(a){if(!this.unbounded_scrolling){var b=this.runtime.width*(1/this.getMinLayerScale())/
2;a>this.width-b&&(a=this.width-b);a<b&&(a=b)}this.scrollX!==a&&(this.scrollX=a,this.runtime.redraw=!0)};a.prototype.scrollToY=function(a){if(!this.unbounded_scrolling){var b=this.runtime.height*(1/this.getMinLayerScale())/2;a>this.height-b&&(a=this.height-b);a<b&&(a=b)}this.scrollY!==a&&(this.scrollY=a,this.runtime.redraw=!0)};a.prototype.boundScrolling=function(){this.scrollToX(this.scrollX);this.scrollToY(this.scrollY)};a.prototype.renderEffectChain=function(a,b,c,d){var k=c?c.active_effect_types:
b?b.active_effect_types:this.active_effect_types,h=c?c.layer.getScale():b?b.getScale():1,m=this.runtime.fx_tex,n,q,p,r,s=0,t=1,v,w=this.runtime.width,y=this.runtime.height,C=w/2,z=y/2,x=b?b.rcTex:this.rcTex,A=b?b.rcTex2:this.rcTex2,D=0,G=0,F=0,u=0,B=w,H=w,E=y,J=y,I=p=0,K=c?c.layer.getAngle():0;if(c){n=0;for(q=k.length;n<q;n++)p+=a.getProgramBoxExtendHorizontal(k[n].shaderindex),I+=a.getProgramBoxExtendVertical(k[n].shaderindex);r=c.bbox;D=b.layerToCanvas(r.left,r.top,!0);F=b.layerToCanvas(r.left,
r.top,!1);B=b.layerToCanvas(r.right,r.bottom,!0);E=b.layerToCanvas(r.right,r.bottom,!1);0!==K&&(n=b.layerToCanvas(r.right,r.top,!0),q=b.layerToCanvas(r.right,r.top,!1),G=b.layerToCanvas(r.left,r.bottom,!0),u=b.layerToCanvas(r.left,r.bottom,!1),r=Math.min(D,B,n,G),B=Math.max(D,B,n,G),D=r,r=Math.min(F,E,q,u),E=Math.max(F,E,q,u),F=r);D-=p;F-=I;B+=p;E+=I;A.left=D/w;A.top=1-F/y;A.right=B/w;A.bottom=1-E/y;G=D=Math.floor(D);u=F=Math.floor(F);H=B=Math.ceil(B);J=E=Math.ceil(E);G-=p;u-=I;H+=p;J+=I;0>D&&(D=
0);0>F&&(F=0);B>w&&(B=w);E>y&&(E=y);0>G&&(G=0);0>u&&(u=0);H>w&&(H=w);J>y&&(J=y);x.left=D/w;x.top=1-F/y;x.right=B/w;x.bottom=1-E/y}else x.left=A.left=0,x.top=A.top=0,x.right=A.right=1,x.bottom=A.bottom=1;I=c&&((c.angle||K)&&a.programUsesDest(k[0].shaderindex)||0!==p||0!==I||1!==c.opacity||c.type.plugin.must_predraw)||b&&!c&&1!==b.opacity;a.setAlphaBlend();if(I){m[s]||(m[s]=a.createEmptyTexture(w,y,this.runtime.linearSampling));if(m[s].c2width!==w||m[s].c2height!==y)a.deleteTexture(m[s]),m[s]=a.createEmptyTexture(w,
y,this.runtime.linearSampling);a.switchProgram(0);a.setRenderingToTexture(m[s]);v=J-u;a.clearRect(G,y-u-v,H-G,v);c?c.drawGL(a):(a.setTexture(this.runtime.layer_tex),a.setOpacity(b.opacity),a.resetModelView(),a.translate(-C,-z),a.updateModelView(),a.quadTex(D,E,B,E,B,F,D,F,x));A.left=A.top=0;A.right=A.bottom=1;c&&(r=x.top,x.top=x.bottom,x.bottom=r);s=1;t=0}a.setOpacity(1);p=k.length-1;var K=a.programUsesCrossSampling(k[p].shaderindex),L=0;n=0;for(q=k.length;n<q;n++){m[s]||(m[s]=a.createEmptyTexture(w,
y,this.runtime.linearSampling));if(m[s].c2width!==w||m[s].c2height!==y)a.deleteTexture(m[s]),m[s]=a.createEmptyTexture(w,y,this.runtime.linearSampling);a.switchProgram(k[n].shaderindex);L=k[n].index;a.programIsAnimated(k[n].shaderindex)&&(this.runtime.redraw=!0);0==n&&!I?(a.setRenderingToTexture(m[s]),v=J-u,r=y-u-v,a.clearRect(G,r,H-G,v),c?(a.setProgramParameters(d,1/c.width,1/c.height,A.left,A.top,A.right,A.bottom,h,c.effect_params[L]),c.drawGL(a)):(a.setProgramParameters(d,1/w,1/y,0,0,1,1,h,b?b.effect_params[L]:
this.effect_params[L]),a.setTexture(b?this.runtime.layer_tex:this.runtime.layout_tex),a.resetModelView(),a.translate(-C,-z),a.updateModelView(),a.quadTex(D,E,B,E,B,F,D,F,x)),A.left=A.top=0,A.right=A.bottom=1,c&&!K&&(r=E,E=F,F=r)):(a.setProgramParameters(d,1/w,1/y,A.left,A.top,A.right,A.bottom,h,c?c.effect_params[L]:b?b.effect_params[L]:this.effect_params[L]),n===p&&!K?(c?a.setBlend(c.srcBlend,c.destBlend):b&&a.setBlend(b.srcBlend,b.destBlend),a.setRenderingToTexture(d)):(a.setRenderingToTexture(m[s]),
v=J-u,r=y-u-v,a.clearRect(G,r,H-G,v)),a.setTexture(m[t]),a.resetModelView(),a.translate(-C,-z),a.updateModelView(),a.quadTex(D,E,B,E,B,F,D,F,x),n===p&&!K&&a.setTexture(null));s=0===s?1:0;t=0===s?1:0}K&&(a.switchProgram(0),c?a.setBlend(c.srcBlend,c.destBlend):b&&a.setBlend(b.srcBlend,b.destBlend),a.setRenderingToTexture(d),a.setTexture(m[t]),a.resetModelView(),a.translate(-C,-z),a.updateModelView(),c&&1===k.length&&!I?a.quadTex(D,F,B,F,B,E,D,E,x):a.quadTex(D,E,B,E,B,F,D,F,x),a.setTexture(null))};a.prototype.getLayerBySid=
function(a){var b,c;b=0;for(c=this.layers.length;b<c;b++)if(this.layers[b].sid===a)return this.layers[b];return null};a.prototype.saveToJSON=function(){var a,b,c,d={sx:this.scrollX,sy:this.scrollY,s:this.scale,a:this.angle,w:this.width,h:this.height,fv:this.first_visit,persist:this.persist_data,fx:[],layers:{}};a=0;for(b=this.effect_types.length;a<b;a++)c=this.effect_types[a],d.fx.push({name:c.name,active:c.active,params:this.effect_params[c.index]});a=0;for(b=this.layers.length;a<b;a++)c=this.layers[a],
d.layers[c.sid.toString()]=c.saveToJSON();return d};a.prototype.loadFromJSON=function(a){var b,c,d,k;this.scrollX=a.sx;this.scrollY=a.sy;this.scale=a.s;this.angle=a.a;this.width=a.w;this.height=a.h;this.persist_data=a.persist;"undefined"!==typeof a.fv&&(this.first_visit=a.fv);var h=a.fx;b=0;for(c=h.length;b<c;b++)if(d=this.getEffectByName(h[b].name))d.active=h[b].active,this.effect_params[d.index]=h[b].params;this.updateActiveEffects();b=a.layers;for(k in b)b.hasOwnProperty(k)&&(a=this.getLayerBySid(parseInt(k,
10)))&&a.loadFromJSON(b[k])};cr.layout=a;b.prototype.updateActiveEffects=function(){this.active_effect_types.length=0;var a,b,c;a=0;for(b=this.effect_types.length;a<b;a++)c=this.effect_types[a],c.active&&this.active_effect_types.push(c)};b.prototype.getEffectByName=function(a){var b,c,d;b=0;for(c=this.effect_types.length;b<c;b++)if(d=this.effect_types[b],d.name===a)return d;return null};b.prototype.createInitialInstances=function(){var a,b,c,l,k,h;b=a=0;for(c=this.initial_instances.length;a<c;a++){l=
this.initial_instances[a];k=this.runtime.types_by_index[l[1]];h=this.runtime.typeHasPersistBehavior(k);k=!0;if(!h||this.layout.first_visit)l=this.runtime.createInstanceFromInit(l,this,!0),d.push(l),l.type.global&&(k=!1);k&&(this.initial_instances[b]=this.initial_instances[a],b++)}this.initial_instances.length=b;this.runtime.ClearDeathRow();!this.runtime.glwrap&&this.effect_types.length&&(this.blend_mode=this.effect_fallback);this.compositeOp=cr.effectToCompositeOp(this.blend_mode);this.runtime.gl&&
cr.setGLBlend(this,this.blend_mode,this.runtime.gl)};b.prototype.updateZIndices=function(){if(this.zindices_stale){var a,b;a=0;for(b=this.instances.length;a<b;a++)this.instances[a].zindex=a;this.zindices_stale=!1}};b.prototype.getScale=function(){return this.getNormalScale()*this.runtime.aspect_scale};b.prototype.getNormalScale=function(){return(this.scale*this.layout.scale-1)*this.zoomRate+1};b.prototype.getAngle=function(){return this.disableAngle?0:cr.clamp_angle(this.layout.angle+this.angle)};
b.prototype.draw=function(a){this.render_offscreen=this.forceOwnTexture||1!==this.opacity||0!==this.blend_mode;var b=this.runtime.canvas,c=a;a.globalAlpha=1;a.globalCompositeOperation="source-over";this.render_offscreen&&(this.runtime.layer_canvas||(this.runtime.layer_canvas=document.createElement("canvas"),b=this.runtime.layer_canvas,b.width=this.runtime.width,b.height=this.runtime.height,this.runtime.layer_ctx=b.getContext("2d")),b=this.runtime.layer_canvas,c=this.runtime.layer_ctx,b.width!==this.runtime.width&&
(b.width=this.runtime.width),b.height!==this.runtime.height&&(b.height=this.runtime.height),this.transparent&&c.clearRect(0,0,this.runtime.width,this.runtime.height));this.transparent||(c.fillStyle="rgb("+this.background_color[0]+","+this.background_color[1]+","+this.background_color[2]+")",c.fillRect(0,0,this.runtime.width,this.runtime.height));c.save();this.disableAngle=!0;var d=this.canvasToLayer(0,0,!0),k=this.canvasToLayer(0,0,!1);this.disableAngle=!1;this.runtime.pixel_rounding&&(d=d+0.5|0,
k=k+0.5|0);this.rotateViewport(d,k,c);var h=this.getScale();c.scale(h,h);c.translate(-d,-k);for(var m,d=0,k=this.instances.length;d<k;d++)if(h=this.instances[d],h.visible&&!(0===h.width||0===h.height))h.update_bbox(),m=h.bbox,m.right<this.viewLeft||(m.bottom<this.viewTop||m.left>this.viewRight||m.top>this.viewBottom)||(c.globalCompositeOperation=h.compositeOp,h.draw(c));c.restore();this.render_offscreen&&(a.globalCompositeOperation=this.compositeOp,a.globalAlpha=this.opacity,a.drawImage(b,0,0))};
b.prototype.rotateViewport=function(a,b,c){var d=this.getScale();this.viewLeft=a;this.viewTop=b;this.viewRight=a+this.runtime.width*(1/d);this.viewBottom=b+this.runtime.height*(1/d);a=this.getAngle();0!==a&&(c&&(c.translate(this.runtime.width/2,this.runtime.height/2),c.rotate(-a),c.translate(this.runtime.width/-2,this.runtime.height/-2)),this.tmprect.set(this.viewLeft,this.viewTop,this.viewRight,this.viewBottom),this.tmprect.offset((this.viewLeft+this.viewRight)/-2,(this.viewTop+this.viewBottom)/
-2),this.tmpquad.set_from_rotated_rect(this.tmprect,a),this.tmpquad.bounding_box(this.tmprect),this.tmprect.offset((this.viewLeft+this.viewRight)/2,(this.viewTop+this.viewBottom)/2),this.viewLeft=this.tmprect.left,this.viewTop=this.tmprect.top,this.viewRight=this.tmprect.right,this.viewBottom=this.tmprect.bottom)};b.prototype.drawGL=function(a){var b=this.runtime.width,c=this.runtime.height,d=0,k=0;if(this.render_offscreen=this.forceOwnTexture||1!==this.opacity||0<this.active_effect_types.length||
0!==this.blend_mode){this.runtime.layer_tex||(this.runtime.layer_tex=a.createEmptyTexture(this.runtime.width,this.runtime.height,this.runtime.linearSampling));if(this.runtime.layer_tex.c2width!==this.runtime.width||this.runtime.layer_tex.c2height!==this.runtime.height)a.deleteTexture(this.runtime.layer_tex),this.runtime.layer_tex=a.createEmptyTexture(this.runtime.width,this.runtime.height,this.runtime.linearSampling);a.setRenderingToTexture(this.runtime.layer_tex);this.transparent&&a.clear(0,0,0,
0)}this.transparent||a.clear(this.background_color[0]/255,this.background_color[1]/255,this.background_color[2]/255,1);this.disableAngle=!0;var k=this.canvasToLayer(0,0,!0),h=this.canvasToLayer(0,0,!1);this.disableAngle=!1;this.runtime.pixel_rounding&&(k=k+0.5|0,h=h+0.5|0);this.rotateViewport(k,h,null);h=this.getScale();a.resetModelView();a.scale(h,h);a.rotateZ(-this.getAngle());a.translate((this.viewLeft+this.viewRight)/-2,(this.viewTop+this.viewBottom)/-2);a.updateModelView();var m,n,q;m=0;for(n=
this.instances.length;m<n;m++)if(q=this.instances[m],q.visible&&!(0===q.width||0===q.height))if(q.update_bbox(),d=q.bbox,!(d.right<this.viewLeft||d.bottom<this.viewTop||d.left>this.viewRight||d.top>this.viewBottom))if(q.uses_shaders)if(d=q.active_effect_types[0].shaderindex,k=q.active_effect_types[0].index,1===q.active_effect_types.length&&!a.programUsesCrossSampling(d)&&!a.programExtendsBox(d)&&(!q.angle&&!q.layer.getAngle()||!a.programUsesDest(d))&&1===q.opacity&&!q.type.plugin.must_predraw){a.switchProgram(d);
a.setBlend(q.srcBlend,q.destBlend);a.programIsAnimated(d)&&(this.runtime.redraw=!0);var p=0,r=0,s=0,t=0;a.programUsesDest(d)&&(d=q.bbox,p=this.layerToCanvas(d.left,d.top,!0),r=this.layerToCanvas(d.left,d.top,!1),s=this.layerToCanvas(d.right,d.bottom,!0),d=this.layerToCanvas(d.right,d.bottom,!1),p/=b,r=1-r/c,s/=b,t=1-d/c);a.setProgramParameters(this.render_offscreen?this.runtime.layer_tex:this.layout.getRenderTarget(),1/q.width,1/q.height,p,r,s,t,this.getScale(),q.effect_params[k]);q.drawGL(a)}else this.layout.renderEffectChain(a,
this,q,this.render_offscreen?this.runtime.layer_tex:this.layout.getRenderTarget()),a.resetModelView(),a.scale(h,h),a.rotateZ(-this.getAngle()),a.translate((this.viewLeft+this.viewRight)/-2,(this.viewTop+this.viewBottom)/-2),a.updateModelView();else a.switchProgram(0),a.setBlend(q.srcBlend,q.destBlend),q.drawGL(a);this.render_offscreen&&(d=this.active_effect_types.length?this.active_effect_types[0].shaderindex:0,k=this.active_effect_types.length?this.active_effect_types[0].index:0,0===this.active_effect_types.length||
1===this.active_effect_types.length&&!a.programUsesCrossSampling(d)&&1===this.opacity?(1===this.active_effect_types.length?(a.switchProgram(d),a.setProgramParameters(this.layout.getRenderTarget(),1/this.runtime.width,1/this.runtime.height,0,0,1,1,this.getScale(),this.effect_params[k]),a.programIsAnimated(d)&&(this.runtime.redraw=!0)):a.switchProgram(0),a.setRenderingToTexture(this.layout.getRenderTarget()),a.setOpacity(this.opacity),a.setTexture(this.runtime.layer_tex),a.setBlend(this.srcBlend,this.destBlend),
a.resetModelView(),a.updateModelView(),b=this.runtime.width/2,c=this.runtime.height/2,a.quad(-b,c,b,c,b,-c,-b,-c),a.setTexture(null)):this.layout.renderEffectChain(a,this,null,this.layout.getRenderTarget()))};b.prototype.canvasToLayer=function(a,b,c){var d=this.runtime.devicePixelRatio;this.runtime.isRetina&&0<this.runtime.fullscreen_mode&&(a*=d,b*=d);var d=this.runtime.original_width/2,k=this.runtime.original_height/2,d=(this.layout.scrollX-d)*this.parallaxX+d,k=(this.layout.scrollY-k)*this.parallaxY+
k,h=1/this.getScale(),d=d-this.runtime.width*h/2,k=k-this.runtime.height*h/2,d=d+a*h,k=k+b*h;b=this.getAngle();0!==b&&(d-=this.layout.scrollX,k-=this.layout.scrollY,a=Math.cos(b),b=Math.sin(b),h=d*a-k*b,k=k*a+d*b,d=h+this.layout.scrollX,k+=this.layout.scrollY);return c?d:k};b.prototype.layerToCanvas=function(a,b,c){var d=this.getAngle();if(0!==d){a-=this.layout.scrollX;b-=this.layout.scrollY;var k=Math.cos(-d),d=Math.sin(-d),h=a*k-b*d;b=b*k+a*d;a=h+this.layout.scrollX;b+=this.layout.scrollY}k=this.runtime.original_width/
2;d=this.runtime.original_height/2;k=(this.layout.scrollX-k)*this.parallaxX+k;d=(this.layout.scrollY-d)*this.parallaxY+d;h=1/this.getScale();k-=this.runtime.width*h/2;d-=this.runtime.height*h/2;k=(a-k)/h;d=(b-d)/h;a=this.runtime.devicePixelRatio;this.runtime.isRetina&&0<this.runtime.fullscreen_mode&&(k/=a,d/=a);return c?k:d};b.prototype.rotatePt=function(a,b,c){if(0===this.getAngle())return c?a:b;var d=this.layerToCanvas(a,b,!0);b=this.layerToCanvas(a,b,!1);this.disableAngle=!0;a=this.canvasToLayer(d,
b,!0);d=this.canvasToLayer(d,b,!0);this.disableAngle=!1;return c?a:d};b.prototype.saveToJSON=function(){var a,b,c,d={s:this.scale,a:this.angle,vl:this.viewLeft,vt:this.viewTop,vr:this.viewRight,vb:this.viewBottom,v:this.visible,bc:this.background_color,t:this.transparent,px:this.parallaxX,py:this.parallaxY,o:this.opacity,zr:this.zoomRate,fx:[],instances:[]};a=0;for(b=this.effect_types.length;a<b;a++)c=this.effect_types[a],d.fx.push({name:c.name,active:c.active,params:this.effect_params[c.index]});
return d};b.prototype.loadFromJSON=function(a){var b,d;this.scale=a.s;this.angle=a.a;this.viewLeft=a.vl;this.viewTop=a.vt;this.viewRight=a.vr;this.viewBottom=a.vb;this.visible=a.v;this.background_color=a.bc;this.transparent=a.t;this.parallaxX=a.px;this.parallaxY=a.py;this.opacity=a.o;this.zoomRate=a.zr;var l=a.fx;a=0;for(b=l.length;a<b;a++)if(d=this.getEffectByName(l[a].name))d.active=l[a].active,this.effect_params[d.index]=l[a].params;this.updateActiveEffects();this.instances.sort(c);this.zindices_stale=
!0};cr.layer=b})();
(function(){function a(a,b){var c,d=a.length;switch(d){case 0:return!0;case 1:return a[0]===b[0];case 2:return a[0]===b[0]&&a[1]===b[1];default:for(c=0;c<d;c++)if(a[c]!==b[c])return!1;return!0}}function b(a,b){return a.index-b.index}function c(c){var d,e,f,m;2===c.length?c[0].index>c[1].index&&(d=c[0],c[0]=c[1],c[1]=d):2<c.length&&c.sort(b);c.length>=p.length&&(p.length=c.length+1);p[c.length]||(p[c.length]=[]);m=p[c.length];d=0;for(e=m.length;d<e;d++)if(f=m[d],a(c,f))return f;m.push(c);return c}
function d(a,b){this.runtime=a;this.triggers={};this.fasttriggers={};this.hasRun=!1;this.includes=new cr.ObjectSet;this.name=b[0];var c=b[1];this.events=[];var d,e;d=0;for(e=c.length;d<e;d++)this.init_event(c[d],null,this.events)}function e(a){this.type=a;this.instances=[];this.else_instances=[];this.select_all=!0}function g(a,b,c){this.sheet=a;this.parent=b;this.runtime=a.runtime;this.solModifiers=[];this.solModifiersIncludingParents=[];this.has_else_block=this.toplevelgroup=this.toplevelevent=this.initially_activated=
this.group=this.solWriterAfterCnds=!1;this.conditions=[];this.actions=[];this.subevents=[];c[1]?(this.group_name=c[1][1].toLowerCase(),this.group=!0,this.initially_activated=!!c[1][0],this.runtime.allGroups.push(this),this.runtime.activeGroups[this.group_name.toLowerCase()]=this.initially_activated):(this.group_name="",this.initially_activated=this.group=!1);this.orblock=c[2];this.sid=c[3];this.group||(this.runtime.blocksBySid[this.sid.toString()]=this);var d=c[4];a=0;for(b=d.length;a<b;a++){var e=
new cr.condition(this,d[a]);cr.seal(e);this.conditions.push(e);this.addSolModifier(e.type)}d=c[5];a=0;for(b=d.length;a<b;a++)e=new cr.action(this,d[a]),cr.seal(e),this.actions.push(e);if(7===c.length){c=c[6];a=0;for(b=c.length;a<b;a++)this.sheet.init_event(c[a],this,this.subevents)}this.is_else_block=!1;this.conditions.length&&(this.is_else_block=null==this.conditions[0].type&&this.conditions[0].func==cr.system_object.prototype.cnds.Else)}function f(a,b){var c,d,e;if(a&&(-1===b.indexOf(a)&&b.push(a),
a.is_contained)){c=0;for(d=a.container.length;c<d;c++)e=a.container[c],a!==e&&-1===b.indexOf(e)&&b.push(e)}}function l(a,b){this.block=a;this.sheet=a.sheet;this.runtime=a.runtime;this.parameters=[];this.results=[];this.extra={};this.func=b[1];this.trigger=0<b[3];this.fasttrigger=2===b[3];this.looping=b[4];this.inverted=b[5];this.isstatic=b[6];this.sid=b[7];this.runtime.cndsBySid[this.sid.toString()]=this;-1===b[0]?(this.type=null,this.run=this.run_system,this.behaviortype=null,this.beh_index=-1):
(this.type=this.runtime.types_by_index[b[0]],this.run=this.isstatic?this.run_static:this.run_object,b[2]?(this.behaviortype=this.type.getBehaviorByName(b[2]),this.beh_index=this.type.getBehaviorIndexByName(b[2])):(this.behaviortype=null,this.beh_index=-1),this.block.parent&&this.block.parent.setSolWriterAfterCnds());this.fasttrigger&&(this.run=this.run_true);if(9===b.length){var c,d,e=b[8];c=0;for(d=e.length;c<d;c++){var f=new cr.parameter(this,e[c]);cr.seal(f);this.parameters.push(f)}this.results.length=
e.length}}function k(a,b){this.block=a;this.sheet=a.sheet;this.runtime=a.runtime;this.parameters=[];this.results=[];this.extra={};this.func=b[1];-1===b[0]?(this.type=null,this.run=this.run_system,this.behaviortype=null,this.beh_index=-1):(this.type=this.runtime.types_by_index[b[0]],this.run=this.run_object,b[2]?(this.behaviortype=this.type.getBehaviorByName(b[2]),this.beh_index=this.type.getBehaviorIndexByName(b[2])):(this.behaviortype=null,this.beh_index=-1));this.sid=b[3];this.runtime.actsBySid[this.sid.toString()]=
this;if(5===b.length){var c,d,e=b[4];c=0;for(d=e.length;c<d;c++){var f=new cr.parameter(this,e[c]);cr.seal(f);this.parameters.push(f)}this.results.length=e.length}}function h(a,b){this.owner=a;this.block=a.block;this.sheet=a.sheet;this.runtime=a.runtime;this.type=b[0];this.expression=null;this.combosel=this.solindex=0;this.layout=null;this.key=0;this.object=null;this.index=0;this.variadicret=this.subparams=this.fileinfo=this.eventvar=this.varname=null;var c,d,e;switch(b[0]){case 0:case 7:this.expression=
new cr.expNode(this,b[1]);this.solindex=0;this.get=this.get_exp;break;case 1:this.expression=new cr.expNode(this,b[1]);this.solindex=0;this.get=this.get_exp_str;break;case 5:this.expression=new cr.expNode(this,b[1]);this.solindex=0;this.get=this.get_layer;break;case 3:case 8:this.combosel=b[1];this.get=this.get_combosel;break;case 6:this.layout=this.runtime.layouts[b[1]];this.get=this.get_layout;break;case 9:this.key=b[1];this.get=this.get_key;break;case 4:this.object=this.runtime.types_by_index[b[1]];
this.get=this.get_object;this.block.addSolModifier(this.object);this.owner instanceof cr.action?this.block.setSolWriterAfterCnds():this.block.parent&&this.block.parent.setSolWriterAfterCnds();break;case 10:this.index=b[1];this.get=a.type.is_family?this.get_familyvar:this.get_instvar;break;case 11:this.varname=b[1];this.eventvar=null;this.get=this.get_eventvar;break;case 2:case 12:this.fileinfo=b[1];this.get=this.get_audiofile;break;case 13:this.get=this.get_variadic;this.subparams=[];this.variadicret=
[];c=1;for(d=b.length;c<d;c++)e=new cr.parameter(this.owner,b[c]),cr.seal(e),this.subparams.push(e),this.variadicret.push(0)}}function m(a,b,c){this.sheet=a;this.parent=b;this.runtime=a.runtime;this.solModifiers=[];this.name=c[1];this.vartype=c[2];this.initial=c[3];this.is_static=!!c[4];this.is_constant=!!c[5];this.sid=c[6];this.runtime.varsBySid[this.sid.toString()]=this;this.data=this.initial;this.parent?(this.localIndex=this.is_static||this.is_constant?-1:this.runtime.stackLocalCount++,this.runtime.all_local_vars.push(this)):
(this.localIndex=-1,this.runtime.all_global_vars.push(this))}function n(a,b,c){this.sheet=a;this.parent=b;this.runtime=a.runtime;this.solModifiers=[];this.include_sheet=null;this.include_sheet_name=c[1]}function q(){this.temp_parents_arr=[];this.reset(null);cr.seal(this)}var p=[];d.prototype.toString=function(){return this.name};d.prototype.init_event=function(a,b,c){switch(a[0]){case 0:a=new cr.eventblock(this,b,a);cr.seal(a);if(a.orblock){c.push(a);c=0;for(b=a.conditions.length;c<b;c++)a.conditions[c].trigger&&
this.init_trigger(a,c)}else a.is_trigger()?this.init_trigger(a,0):c.push(a);break;case 1:a=new cr.eventvariable(this,b,a);cr.seal(a);c.push(a);break;case 2:a=new cr.eventinclude(this,b,a),cr.seal(a),c.push(a)}};d.prototype.postInit=function(){var a,b;a=0;for(b=this.events.length;a<b;a++)this.events[a].postInit(a<b-1&&this.events[a+1].is_else_block)};d.prototype.run=function(){this.hasRun=!0;this.runtime.isRunningEvents=!0;var a,b;a=0;for(b=this.events.length;a<b;a++){var c=this.events[a];c.run();
this.runtime.clearSol(c.solModifiers);(!this.runtime.deathRow.isEmpty()||this.runtime.createRow.length)&&this.runtime.ClearDeathRow()}this.runtime.isRunningEvents=!1};d.prototype.init_trigger=function(a,b){a.orblock||this.runtime.triggers_to_postinit.push(a);var c,d,e=a.conditions[b],f;f=e.type?e.type.name:"system";var m=(c=e.fasttrigger)?this.fasttriggers:this.triggers;m[f]||(m[f]=[]);f=m[f];m=e.func;if(c){if(e.parameters.length&&(e=e.parameters[0],!(1!==e.type||2!==e.expression.type))){e=e.expression.value.toLowerCase();
c=0;for(d=f.length;c<d;c++)if(f[c].method==m){c=f[c].evs;c[e]?c[e].push([a,b]):c[e]=[[a,b]];return}c={};c[e]=[[a,b]];f.push({method:m,evs:c})}}else{c=0;for(d=f.length;c<d;c++)if(f[c].method==m){f[c].evs.push([a,b]);return}f.push({method:m,evs:[[a,b]]})}};cr.eventsheet=d;e.prototype.hasObjects=function(){return this.select_all?this.type.instances.length:this.instances.length};e.prototype.getObjects=function(){return this.select_all?this.type.instances:this.instances};e.prototype.pick_one=function(a){a&&
(a.runtime.getCurrentEventStack().current_event.orblock?(this.select_all&&(this.instances.length=0,cr.shallowAssignArray(this.else_instances,a.type.instances),this.select_all=!1),a=this.else_instances.indexOf(a),-1!==a&&(this.instances.push(this.else_instances[a]),this.else_instances.splice(a,1))):(this.select_all=!1,this.instances.length=1,this.instances[0]=a))};cr.selection=e;g.prototype.postInit=function(a){var b,d=this.parent;if(this.group)for(this.toplevelgroup=!0;d;){if(!d.group){this.toplevelgroup=
!1;break}d=d.parent}this.toplevelevent=!this.is_trigger()&&(!this.parent||this.parent.group&&this.parent.toplevelgroup);this.has_else_block=!!a;this.solModifiersIncludingParents=this.solModifiers.slice(0);for(d=this.parent;d;){a=0;for(b=d.solModifiers.length;a<b;a++)this.addParentSolModifier(d.solModifiers[a]);d=d.parent}this.solModifiers=c(this.solModifiers);this.solModifiersIncludingParents=c(this.solModifiersIncludingParents);a=0;for(b=this.conditions.length;a<b;a++)this.conditions[a].postInit();
a=0;for(b=this.actions.length;a<b;a++)this.actions[a].postInit();a=0;for(b=this.subevents.length;a<b;a++)this.subevents[a].postInit(a<b-1&&this.subevents[a+1].is_else_block)};g.prototype.addSolModifier=function(a){f(a,this.solModifiers)};g.prototype.addParentSolModifier=function(a){f(a,this.solModifiersIncludingParents)};g.prototype.setSolWriterAfterCnds=function(){this.solWriterAfterCnds=!0;this.parent&&this.parent.setSolWriterAfterCnds()};g.prototype.is_trigger=function(){return this.conditions.length?
this.conditions[0].trigger:!1};g.prototype.run=function(){var a,b=!1,c=this.runtime.getCurrentEventStack();c.current_event=this;this.is_else_block||(c.else_branch_ran=!1);if(this.orblock){0===this.conditions.length&&(b=!0);c.cndindex=0;for(a=this.conditions.length;c.cndindex<a;c.cndindex++)this.conditions[c.cndindex].trigger||this.conditions[c.cndindex].run()&&(b=!0);(c.last_event_true=b)&&this.run_actions_and_subevents()}else{c.cndindex=0;for(a=this.conditions.length;c.cndindex<a;c.cndindex++)if(!this.conditions[c.cndindex].run()){c.last_event_true=
!1;this.toplevelevent&&(!this.runtime.deathRow.isEmpty()||this.runtime.createRow.length)&&this.runtime.ClearDeathRow();return}c.last_event_true=!0;this.run_actions_and_subevents()}c.last_event_true&&this.has_else_block&&(c.else_branch_ran=!0);this.toplevelevent&&(!this.runtime.deathRow.isEmpty()||this.runtime.createRow.length)&&this.runtime.ClearDeathRow()};g.prototype.run_orblocktrigger=function(a){this.runtime.getCurrentEventStack().current_event=this;this.conditions[a].run()&&this.run_actions_and_subevents()};
g.prototype.run_actions_and_subevents=function(){var a=this.runtime.getCurrentEventStack(),b;a.actindex=0;for(b=this.actions.length;a.actindex<b;a.actindex++)if(this.actions[a.actindex].run())return;this.run_subevents()};g.prototype.resume_actions_and_subevents=function(){var a=this.runtime.getCurrentEventStack(),b;for(b=this.actions.length;a.actindex<b;a.actindex++)if(this.actions[a.actindex].run())return;this.run_subevents()};g.prototype.run_subevents=function(){if(this.subevents.length){var a,
b,c,d,e=this.subevents.length-1;this.runtime.pushEventStack(this);if(this.solWriterAfterCnds){a=0;for(b=this.subevents.length;a<b;a++)c=this.subevents[a],(d=!this.toplevelgroup||!this.group&&a<e)&&this.runtime.pushCopySol(c.solModifiers),c.run(),d?this.runtime.popSol(c.solModifiers):this.runtime.clearSol(c.solModifiers)}else{a=0;for(b=this.subevents.length;a<b;a++)this.subevents[a].run()}this.runtime.popEventStack()}};g.prototype.run_pretrigger=function(){var a=this.runtime.getCurrentEventStack();
a.current_event=this;var b=!1,c;a.cndindex=0;for(c=this.conditions.length;a.cndindex<c;a.cndindex++)if(this.conditions[a.cndindex].run())b=!0;else if(!this.orblock)return!1;return this.orblock?b:!0};g.prototype.retrigger=function(){this.runtime.execcount++;var a=this.runtime.getCurrentEventStack().cndindex,b=this.runtime.pushEventStack(this);if(!this.orblock){b.cndindex=a+1;for(a=this.conditions.length;b.cndindex<a;b.cndindex++)if(!this.conditions[b.cndindex].run())return this.runtime.popEventStack(),
!1}this.run_actions_and_subevents();this.runtime.popEventStack();return!0};cr.eventblock=g;l.prototype.postInit=function(){var a,b;a=0;for(b=this.parameters.length;a<b;a++)this.parameters[a].postInit()};l.prototype.run_true=function(){return!0};l.prototype.run_system=function(){var a,b;a=0;for(b=this.parameters.length;a<b;a++)this.results[a]=this.parameters[a].get();return cr.xor(this.func.apply(this.runtime.system,this.results),this.inverted)};l.prototype.run_static=function(){var a,b;a=0;for(b=
this.parameters.length;a<b;a++)this.results[a]=this.parameters[a].get(a);a=this.func.apply(this.behaviortype?this.behaviortype:this.type,this.results);this.type.applySolToContainer();return a};l.prototype.run_object=function(){var a,b,c,d,e,f,m,h=this.type.getCurrentSol(),g=this.block.orblock&&!this.trigger,k=0,p=this.type.is_contained;if(h.select_all){h.instances.length=0;a=h.else_instances.length=0;for(c=this.type.instances.length;a<c;a++){f=this.type.instances[a];b=0;for(d=this.parameters.length;b<
d;b++)this.results[b]=this.parameters[b].get(a);-1<this.beh_index?(this.type.is_family&&(k=f.type.family_beh_map[this.type.family_index]),b=this.func.apply(f.behavior_insts[this.beh_index+k],this.results)):b=this.func.apply(f,this.results);(e=cr.xor(b,this.inverted))?h.instances.push(f):g&&h.else_instances.push(f)}this.type.finish&&this.type.finish(!0);h.select_all=!1;this.type.applySolToContainer();return h.hasObjects()}var l=0,n=g?h.else_instances:h.instances;e=!1;a=0;for(c=n.length;a<c;a++){f=
n[a];b=0;for(d=this.parameters.length;b<d;b++)this.results[b]=this.parameters[b].get(a);-1<this.beh_index?(this.type.is_family&&(k=f.type.family_beh_map[this.type.family_index]),b=this.func.apply(f.behavior_insts[this.beh_index+k],this.results)):b=this.func.apply(f,this.results);if(cr.xor(b,this.inverted))if(e=!0,g){if(h.instances.push(f),p){b=0;for(d=f.siblings.length;b<d;b++)m=f.siblings[b],m.type.getCurrentSol().instances.push(m)}}else{n[l]=f;if(p){b=0;for(d=f.siblings.length;b<d;b++)m=f.siblings[b],
m.type.getCurrentSol().instances[l]=m}l++}else if(g){n[l]=f;if(p){b=0;for(d=f.siblings.length;b<d;b++)m=f.siblings[b],m.type.getCurrentSol().else_instances[l]=m}l++}}n.length=l;if(p){a=0;for(c=this.type.container.length;a<c;a++)f=this.type.container[a].getCurrentSol(),g?f.else_instances.length=l:f.instances.length=l}k=e;if(g&&!e){a=0;for(c=h.instances.length;a<c;a++){f=h.instances[a];b=0;for(d=this.parameters.length;b<d;b++)this.results[b]=this.parameters[b].get(a);b=-1<this.beh_index?this.func.apply(f.behavior_insts[this.beh_index],
this.results):this.func.apply(f,this.results);if(cr.xor(b,this.inverted)){e=!0;break}}}this.type.finish&&this.type.finish(k||g);return g?e:h.hasObjects()};cr.condition=l;k.prototype.postInit=function(){var a,b;a=0;for(b=this.parameters.length;a<b;a++)this.parameters[a].postInit()};k.prototype.run_system=function(){var a,b;a=0;for(b=this.parameters.length;a<b;a++)this.results[a]=this.parameters[a].get();return this.func.apply(this.runtime.system,this.results)};k.prototype.run_object=function(){var a=
this.type.getCurrentSol().getObjects(),b,c,d,e,f;b=0;for(d=a.length;b<d;b++){f=a[b];c=0;for(e=this.parameters.length;c<e;c++)this.results[c]=this.parameters[c].get(b);-1<this.beh_index?(c=0,this.type.is_family&&(c=f.type.family_beh_map[this.type.family_index]),this.func.apply(f.behavior_insts[this.beh_index+c],this.results)):this.func.apply(f,this.results)}return!1};cr.action=k;var r=[],s=-1;h.prototype.postInit=function(){var a,b;if(11===this.type)this.eventvar=this.runtime.getEventVariableByName(this.varname,
this.block.parent);else if(13===this.type){a=0;for(b=this.subparams.length;a<b;a++)this.subparams[a].postInit()}this.expression&&this.expression.postInit()};h.prototype.pushTempValue=function(){s++;r.length===s&&r.push(new cr.expvalue);return r[s]};h.prototype.popTempValue=function(){s--};h.prototype.get_exp=function(a){this.solindex=a||0;a=this.pushTempValue();this.expression.get(a);this.popTempValue();return a.data};h.prototype.get_exp_str=function(a){this.solindex=a||0;a=this.pushTempValue();this.expression.get(a);
this.popTempValue();return cr.is_string(a.data)?a.data:""};h.prototype.get_object=function(){return this.object};h.prototype.get_combosel=function(){return this.combosel};h.prototype.get_layer=function(a){this.solindex=a||0;a=this.pushTempValue();this.expression.get(a);this.popTempValue();return a.is_number()?this.runtime.getLayerByNumber(a.data):this.runtime.getLayerByName(a.data)};h.prototype.get_layout=function(){return this.layout};h.prototype.get_key=function(){return this.key};h.prototype.get_instvar=
function(){return this.index};h.prototype.get_familyvar=function(a){var b=this.owner.type,c=null,c=b.getCurrentSol(),d=c.getObjects(),c=d.length?d[a%d.length].type:c.else_instances[a%c.else_instances.length].type;return this.index+c.family_var_map[b.family_index]};h.prototype.get_eventvar=function(){return this.eventvar};h.prototype.get_audiofile=function(){return this.fileinfo};h.prototype.get_variadic=function(){var a,b;a=0;for(b=this.subparams.length;a<b;a++)this.variadicret[a]=this.subparams[a].get();
return this.variadicret};cr.parameter=h;m.prototype.postInit=function(){this.solModifiers=c(this.solModifiers)};m.prototype.setValue=function(a){var b=this.runtime.getCurrentLocalVarStack();!this.parent||this.is_static||!b?this.data=a:(this.localIndex>=b.length&&(b.length=this.localIndex+1),b[this.localIndex]=a)};m.prototype.getValue=function(){var a=this.runtime.getCurrentLocalVarStack();return!this.parent||this.is_static||!a||this.is_constant?this.data:this.localIndex>=a.length||"undefined"===typeof a[this.localIndex]?
this.initial:a[this.localIndex]};m.prototype.run=function(){this.parent&&(!this.is_static&&!this.is_constant)&&this.setValue(this.initial)};cr.eventvariable=m;n.prototype.toString=function(){return"include:"+this.include_sheet.toString()};n.prototype.postInit=function(){this.include_sheet=this.runtime.eventsheets[this.include_sheet_name];this.sheet.includes.add(this);this.solModifiers=c(this.solModifiers)};n.prototype.run=function(){this.parent&&this.runtime.pushCleanSol(this.runtime.types_by_index);
this.include_sheet.hasRun||this.include_sheet.run();this.parent&&this.runtime.popSol(this.runtime.types_by_index)};n.prototype.isActive=function(){for(var a=this.parent;a;){if(a.group&&!this.runtime.activeGroups[a.group_name.toLowerCase()])return!1;a=a.parent}return!0};cr.eventinclude=n;q.prototype.reset=function(a){this.current_event=a;this.actindex=this.cndindex=0;this.temp_parents_arr.length=0;this.else_branch_ran=this.last_event_true=!1};q.prototype.isModifierAfterCnds=function(){return this.current_event.solWriterAfterCnds?
!0:this.cndindex<this.current_event.conditions.length-1?!!this.current_event.solModifiers.length:!1};cr.eventStackFrame=q})();
(function(){function a(a,b){this.owner=a;this.runtime=a.runtime;this.type=b[0];this.get=[this.eval_int,this.eval_float,this.eval_string,this.eval_unaryminus,this.eval_add,this.eval_subtract,this.eval_multiply,this.eval_divide,this.eval_mod,this.eval_power,this.eval_and,this.eval_or,this.eval_equal,this.eval_notequal,this.eval_less,this.eval_lessequal,this.eval_greater,this.eval_greaterequal,this.eval_conditional,this.eval_system_exp,this.eval_object_behavior_exp,this.eval_instvar_exp,this.eval_object_behavior_exp,
this.eval_eventvar_exp][this.type];var e=null;this.object_type=this.parameters=this.results=this.func=this.third=this.second=this.first=this.value=null;this.beh_index=-1;this.instance_expr=null;this.varindex=-1;this.eventvar=this.varname=this.behavior_type=null;this.return_string=!1;switch(this.type){case 0:case 1:case 2:this.value=b[1];break;case 3:this.first=new cr.expNode(a,b[1]);break;case 18:this.first=new cr.expNode(a,b[1]);this.second=new cr.expNode(a,b[2]);this.third=new cr.expNode(a,b[3]);
break;case 19:this.func=b[1];this.results=[];this.parameters=[];3===b.length?(e=b[2],this.results.length=e.length+1):this.results.length=1;break;case 20:this.object_type=this.runtime.types_by_index[b[1]];this.beh_index=-1;this.func=b[2];this.return_string=b[3];this.instance_expr=b[4]?new cr.expNode(a,b[4]):null;this.results=[];this.parameters=[];6===b.length?(e=b[5],this.results.length=e.length+1):this.results.length=1;break;case 21:this.object_type=this.runtime.types_by_index[b[1]];this.return_string=
b[2];this.instance_expr=b[3]?new cr.expNode(a,b[3]):null;this.varindex=b[4];break;case 22:this.object_type=this.runtime.types_by_index[b[1]];this.behavior_type=this.object_type.getBehaviorByName(b[2]);this.beh_index=this.object_type.getBehaviorIndexByName(b[2]);this.func=b[3];this.return_string=b[4];this.instance_expr=b[5]?new cr.expNode(a,b[5]):null;this.results=[];this.parameters=[];7===b.length?(e=b[6],this.results.length=e.length+1):this.results.length=1;break;case 23:this.varname=b[1],this.eventvar=
null}4<=this.type&&17>=this.type&&(this.first=new cr.expNode(a,b[1]),this.second=new cr.expNode(a,b[2]));if(e){var g,f;g=0;for(f=e.length;g<f;g++)this.parameters.push(new cr.expNode(a,e[g]))}cr.seal(this)}function b(a,b){this.type=a||cr.exptype.Integer;this.data=b||0;this.object_class=null;this.type==cr.exptype.Integer&&(this.data=Math.floor(this.data));cr.seal(this)}a.prototype.postInit=function(){23===this.type&&(this.eventvar=this.owner.runtime.getEventVariableByName(this.varname,this.owner.block.parent));
this.first&&this.first.postInit();this.second&&this.second.postInit();this.third&&this.third.postInit();this.instance_expr&&this.instance_expr.postInit();if(this.parameters){var a,b;a=0;for(b=this.parameters.length;a<b;a++)this.parameters[a].postInit()}};a.prototype.eval_system_exp=function(a){this.results[0]=a;a=this.owner.pushTempValue();var b,e;b=0;for(e=this.parameters.length;b<e;b++)this.parameters[b].get(a),this.results[b+1]=a.data;this.owner.popTempValue();this.func.apply(this.runtime.system,
this.results)};a.prototype.eval_object_behavior_exp=function(a){var b=this.object_type.getCurrentSol(),e=b.getObjects();if(!e.length)if(b.else_instances.length)e=b.else_instances;else{this.return_string?a.set_string(""):a.set_int(0);return}this.results[0]=a;a.object_class=this.object_type;a=this.owner.pushTempValue();var g,b=0;for(g=this.parameters.length;b<g;b++)this.parameters[b].get(a),this.results[b+1]=a.data;b=this.owner.solindex;this.instance_expr&&(this.instance_expr.get(a),a.is_number()&&
(b=a.data,e=this.object_type.instances));this.owner.popTempValue();b%=e.length;0>b&&(b+=e.length);e=e[b];-1<this.beh_index?(a=0,this.object_type.is_family&&(a=e.type.family_beh_map[this.object_type.family_index]),this.func.apply(e.behavior_insts[this.beh_index+a],this.results)):this.func.apply(e,this.results)};a.prototype.eval_instvar_exp=function(a){var b=this.object_type.getCurrentSol(),e=b.getObjects();if(!e.length)if(b.else_instances.length)e=b.else_instances;else{this.return_string?a.set_string(""):
a.set_int(0);return}b=this.owner.solindex;if(this.instance_expr){var g=this.owner.pushTempValue();this.instance_expr.get(g);if(g.is_number()){b=g.data;e=this.object_type.instances;b%=e.length;0>b&&(b+=e.length);e=e[b].instance_vars[this.varindex];cr.is_string(e)?a.set_string(e):a.set_float(e);this.owner.popTempValue();return}this.owner.popTempValue()}b%=e.length;0>b&&(b+=e.length);e=e[b];b=0;this.object_type.is_family&&(b=e.type.family_var_map[this.object_type.family_index]);e=e.instance_vars[this.varindex+
b];cr.is_string(e)?a.set_string(e):a.set_float(e)};a.prototype.eval_int=function(a){a.type=cr.exptype.Integer;a.data=this.value};a.prototype.eval_float=function(a){a.type=cr.exptype.Float;a.data=this.value};a.prototype.eval_string=function(a){a.type=cr.exptype.String;a.data=this.value};a.prototype.eval_unaryminus=function(a){this.first.get(a);a.is_number()&&(a.data=-a.data)};a.prototype.eval_add=function(a){this.first.get(a);var b=this.owner.pushTempValue();this.second.get(b);a.is_number()&&b.is_number()&&
(a.data+=b.data,b.is_float()&&a.make_float());this.owner.popTempValue()};a.prototype.eval_subtract=function(a){this.first.get(a);var b=this.owner.pushTempValue();this.second.get(b);a.is_number()&&b.is_number()&&(a.data-=b.data,b.is_float()&&a.make_float());this.owner.popTempValue()};a.prototype.eval_multiply=function(a){this.first.get(a);var b=this.owner.pushTempValue();this.second.get(b);a.is_number()&&b.is_number()&&(a.data*=b.data,b.is_float()&&a.make_float());this.owner.popTempValue()};a.prototype.eval_divide=
function(a){this.first.get(a);var b=this.owner.pushTempValue();this.second.get(b);a.is_number()&&b.is_number()&&(a.data/=b.data,a.make_float());this.owner.popTempValue()};a.prototype.eval_mod=function(a){this.first.get(a);var b=this.owner.pushTempValue();this.second.get(b);a.is_number()&&b.is_number()&&(a.data%=b.data,b.is_float()&&a.make_float());this.owner.popTempValue()};a.prototype.eval_power=function(a){this.first.get(a);var b=this.owner.pushTempValue();this.second.get(b);a.is_number()&&b.is_number()&&
(a.data=Math.pow(a.data,b.data),b.is_float()&&a.make_float());this.owner.popTempValue()};a.prototype.eval_and=function(a){this.first.get(a);var b=this.owner.pushTempValue();this.second.get(b);a.is_number()?b.is_string()?a.set_string(a.data.toString()+b.data):a.data&&b.data?a.set_int(1):a.set_int(0):a.is_string()&&(b.is_string()?a.data+=b.data:a.data+=(Math.round(1E10*b.data)/1E10).toString());this.owner.popTempValue()};a.prototype.eval_or=function(a){this.first.get(a);var b=this.owner.pushTempValue();
this.second.get(b);a.is_number()&&b.is_number()&&(a.data||b.data?a.set_int(1):a.set_int(0));this.owner.popTempValue()};a.prototype.eval_conditional=function(a){this.first.get(a);a.data?this.second.get(a):this.third.get(a)};a.prototype.eval_equal=function(a){this.first.get(a);var b=this.owner.pushTempValue();this.second.get(b);a.set_int(a.data===b.data?1:0);this.owner.popTempValue()};a.prototype.eval_notequal=function(a){this.first.get(a);var b=this.owner.pushTempValue();this.second.get(b);a.set_int(a.data!==
b.data?1:0);this.owner.popTempValue()};a.prototype.eval_less=function(a){this.first.get(a);var b=this.owner.pushTempValue();this.second.get(b);a.set_int(a.data<b.data?1:0);this.owner.popTempValue()};a.prototype.eval_lessequal=function(a){this.first.get(a);var b=this.owner.pushTempValue();this.second.get(b);a.set_int(a.data<=b.data?1:0);this.owner.popTempValue()};a.prototype.eval_greater=function(a){this.first.get(a);var b=this.owner.pushTempValue();this.second.get(b);a.set_int(a.data>b.data?1:0);
this.owner.popTempValue()};a.prototype.eval_greaterequal=function(a){this.first.get(a);var b=this.owner.pushTempValue();this.second.get(b);a.set_int(a.data>=b.data?1:0);this.owner.popTempValue()};a.prototype.eval_eventvar_exp=function(a){var b=this.eventvar.getValue();cr.is_number(b)?a.set_float(b):a.set_string(b)};cr.expNode=a;b.prototype.is_int=function(){return this.type===cr.exptype.Integer};b.prototype.is_float=function(){return this.type===cr.exptype.Float};b.prototype.is_number=function(){return this.type===
cr.exptype.Integer||this.type===cr.exptype.Float};b.prototype.is_string=function(){return this.type===cr.exptype.String};b.prototype.make_int=function(){this.is_int()||(this.is_float()?this.data=Math.floor(this.data):this.is_string()&&(this.data=parseInt(this.data,10)),this.type=cr.exptype.Integer)};b.prototype.make_float=function(){this.is_float()||(this.is_string()&&(this.data=parseFloat(this.data)),this.type=cr.exptype.Float)};b.prototype.make_string=function(){this.is_string()||(this.data=this.data.toString(),
this.type=cr.exptype.String)};b.prototype.set_int=function(a){this.type=cr.exptype.Integer;this.data=Math.floor(a)};b.prototype.set_float=function(a){this.type=cr.exptype.Float;this.data=a};b.prototype.set_string=function(a){this.type=cr.exptype.String;this.data=a};b.prototype.set_any=function(a){cr.is_number(a)?(this.type=cr.exptype.Float,this.data=a):cr.is_string(a)?(this.type=cr.exptype.String,this.data=a.toString()):(this.type=cr.exptype.Integer,this.data=0)};cr.expvalue=b;cr.exptype={Integer:0,
Float:1,String:2}})();cr.system_object=function(a){this.runtime=a;this.waits=[]};
cr.system_object.prototype.saveToJSON=function(){var a={},b,c,d,e,g,f,l,k;a.waits=[];var h=a.waits,m;b=0;for(c=this.waits.length;b<c;b++){f=this.waits[b];m={t:f.time,ev:f.ev.sid,sm:[],sols:{}};f.ev.actions[f.actindex]&&(m.act=f.ev.actions[f.actindex].sid);d=0;for(e=f.solModifiers.length;d<e;d++)m.sm.push(f.solModifiers[d].sid);for(g in f.sols)if(f.sols.hasOwnProperty(g)){l=this.runtime.types_by_index[parseInt(g,10)];k={sa:f.sols[g].sa,insts:[]};d=0;for(e=f.sols[g].insts.length;d<e;d++)k.insts.push(f.sols[g].insts[d].uid);
m.sols[l.sid.toString()]=k}h.push(m)}return a};
cr.system_object.prototype.loadFromJSON=function(a){a=a.waits;var b,c,d,e,g,f,l,k,h,m,n;b=this.waits.length=0;for(c=a.length;b<c;b++)if(f=a[b],k=this.runtime.blocksBySid[f.ev.toString()]){h=-1;d=0;for(e=k.actions.length;d<e;d++)if(k.actions[d].sid===f.act){h=d;break}if(-1!==h){l={sols:{},solModifiers:[],deleteme:!1};l.time=f.t;l.ev=k;l.actindex=h;d=0;for(e=f.sm.length;d<e;d++)(k=this.runtime.getObjectTypeBySid(f.sm[d]))&&l.solModifiers.push(k);for(g in f.sols)if(f.sols.hasOwnProperty(g)&&(k=this.runtime.getObjectTypeBySid(parseInt(g,
10)))){h=f.sols[g];m={sa:h.sa,insts:[]};d=0;for(e=h.insts.length;d<e;d++)(n=this.runtime.getObjectByUID(h.insts[d]))&&m.insts.push(n);l.sols[k.index.toString()]=m}this.waits.push(l)}}};
(function(){function a(){}function b(a,b){var c=a.extra.c2_foreachordered_val,d=b.extra.c2_foreachordered_val;if(cr.is_number(c)&&cr.is_number(d))return c-d;c=""+c;d=""+d;return c<d?-1:c>d?1:0}function c(a,b){if(!h||a!==m||b!==n)h=RegExp(a,b),m=a,n=b;h.lastIndex=0;return h}function d(){}function e(){}function g(a,b,d){if(!(a===t&&b===v&&d===w)){var e=c(b,d);s=a.match(e);t=a;v=b;w=d}}var f=cr.system_object.prototype;a.prototype.EveryTick=function(){return!0};a.prototype.OnLayoutStart=function(){return!0};
a.prototype.OnLayoutEnd=function(){return!0};a.prototype.Compare=function(a,b,c){return cr.do_cmp(a,b,c)};a.prototype.CompareTime=function(a,b){var c=this.runtime.kahanTime.sum;if(0===a){var d=this.runtime.getCurrentCondition();return!d.extra.CompareTime_executed&&c>=b?d.extra.CompareTime_executed=!0:!1}return cr.do_cmp(c,a,b)};a.prototype.LayerVisible=function(a){return a?a.visible:!1};a.prototype.LayerCmpOpacity=function(a,b,c){return!a?!1:cr.do_cmp(100*a.opacity,b,c)};a.prototype.Repeat=function(a){var b=
this.runtime.getCurrentEventStack(),c=b.current_event,d=b.isModifierAfterCnds(),b=this.runtime.pushLoopStack();if(d)for(d=0;d<a&&!b.stopped;d++)this.runtime.pushCopySol(c.solModifiers),b.index=d,c.retrigger(),this.runtime.popSol(c.solModifiers);else for(d=0;d<a&&!b.stopped;d++)b.index=d,c.retrigger();this.runtime.popLoopStack();return!1};a.prototype.While=function(a){var b=this.runtime.getCurrentEventStack();a=b.current_event;var c=b.isModifierAfterCnds(),b=this.runtime.pushLoopStack();if(c)for(c=
0;!b.stopped;c++)this.runtime.pushCopySol(a.solModifiers),b.index=c,a.retrigger()||(b.stopped=!0),this.runtime.popSol(a.solModifiers);else for(c=0;!b.stopped;c++)b.index=c,a.retrigger()||(b.stopped=!0);this.runtime.popLoopStack();return!1};a.prototype.For=function(a,b,c){var d=this.runtime.getCurrentEventStack(),e=d.current_event,d=d.isModifierAfterCnds();a=this.runtime.pushLoopStack(a);if(c<b)if(d)for(;b>=c&&!a.stopped;--b)this.runtime.pushCopySol(e.solModifiers),a.index=b,e.retrigger(),this.runtime.popSol(e.solModifiers);
else for(;b>=c&&!a.stopped;--b)a.index=b,e.retrigger();else if(d)for(;b<=c&&!a.stopped;++b)this.runtime.pushCopySol(e.solModifiers),a.index=b,e.retrigger(),this.runtime.popSol(e.solModifiers);else for(;b<=c&&!a.stopped;++b)a.index=b,e.retrigger();this.runtime.popLoopStack();return!1};var l=[],k=-1;a.prototype.ForEach=function(a){var b=a.getCurrentSol();k++;l.length===k&&l.push([]);var c=l[k];cr.shallowAssignArray(c,b.getObjects());var d=this.runtime.getCurrentEventStack(),e=d.current_event,f=d.isModifierAfterCnds(),
d=this.runtime.pushLoopStack(),m,h,g,p,n,r,q=a.is_contained;if(f){f=0;for(m=c.length;f<m&&!d.stopped;f++){this.runtime.pushCopySol(e.solModifiers);p=c[f];b=a.getCurrentSol();b.select_all=!1;b.instances.length=1;b.instances[0]=p;if(q){h=0;for(g=p.siblings.length;h<g;h++)n=p.siblings[h],r=n.type.getCurrentSol(),r.select_all=!1,r.instances.length=1,r.instances[0]=n}d.index=f;e.retrigger();this.runtime.popSol(e.solModifiers)}}else{b.select_all=!1;b.instances.length=1;f=0;for(m=c.length;f<m&&!d.stopped;f++){p=
c[f];b.instances[0]=p;if(q){h=0;for(g=p.siblings.length;h<g;h++)n=p.siblings[h],r=n.type.getCurrentSol(),r.select_all=!1,r.instances.length=1,r.instances[0]=n}d.index=f;e.retrigger()}}c.length=0;this.runtime.popLoopStack();k--;return!1};a.prototype.ForEachOrdered=function(a,c,d){c=a.getCurrentSol();k++;l.length===k&&l.push([]);var e=l[k];cr.shallowAssignArray(e,c.getObjects());var f=this.runtime.getCurrentEventStack(),m=f.current_event,h=this.runtime.getCurrentCondition(),g=f.isModifierAfterCnds(),
f=this.runtime.pushLoopStack(),p,n,r,q,s;p=0;for(n=e.length;p<n;p++)e[p].extra.c2_foreachordered_val=h.parameters[1].get(p);e.sort(b);1===d&&e.reverse();d=a.is_contained;if(g){p=0;for(n=e.length;p<n&&!f.stopped;p++){this.runtime.pushCopySol(m.solModifiers);r=e[p];c=a.getCurrentSol();c.select_all=!1;c.instances.length=1;c.instances[0]=r;if(d){h=0;for(g=r.siblings.length;h<g;h++)q=r.siblings[h],s=q.type.getCurrentSol(),s.select_all=!1,s.instances.length=1,s.instances[0]=q}f.index=p;m.retrigger();this.runtime.popSol(m.solModifiers)}}else{c.select_all=
!1;c.instances.length=1;p=0;for(n=e.length;p<n&&!f.stopped;p++){r=e[p];c.instances[0]=r;if(d){h=0;for(g=r.siblings.length;h<g;h++)q=r.siblings[h],s=q.type.getCurrentSol(),s.select_all=!1,s.instances.length=1,s.instances[0]=q}f.index=p;m.retrigger()}}e.length=0;this.runtime.popLoopStack();k--;return!1};a.prototype.PickByComparison=function(a,b,c,d){var e,f,m,h;if(a){k++;l.length===k&&l.push([]);var g=l[k],p=a.getCurrentSol();cr.shallowAssignArray(g,p.getObjects());p.select_all&&(p.else_instances.length=
0);var n=this.runtime.getCurrentCondition();m=e=0;for(f=g.length;e<f;e++)h=g[e],g[m]=h,b=n.parameters[1].get(e),d=n.parameters[3].get(e),cr.do_cmp(b,c,d)?m++:p.else_instances.push(h);g.length=m;p.select_all=!1;cr.shallowAssignArray(p.instances,g);g.length=0;k--;a.applySolToContainer();return!!p.instances.length}};a.prototype.PickByEvaluate=function(a,b){var c,d,e,f;if(a){k++;l.length===k&&l.push([]);var m=l[k],h=a.getCurrentSol();cr.shallowAssignArray(m,h.getObjects());h.select_all&&(h.else_instances.length=
0);var g=this.runtime.getCurrentCondition();e=c=0;for(d=m.length;c<d;c++)f=m[c],m[e]=f,(b=g.parameters[1].get(c))?e++:h.else_instances.push(f);m.length=e;h.select_all=!1;cr.shallowAssignArray(h.instances,m);m.length=0;k--;a.applySolToContainer();return!!h.instances.length}};a.prototype.TriggerOnce=function(){var a=this.runtime.getCurrentCondition().extra;"undefined"===typeof a.TriggerOnce_lastTick&&(a.TriggerOnce_lastTick=-1);var b=a.TriggerOnce_lastTick,c=this.runtime.tickcount;a.TriggerOnce_lastTick=
c;return this.runtime.layout_first_tick||b!==c-1};a.prototype.Every=function(a){var b=this.runtime.getCurrentCondition(),c=b.extra.Every_lastTime||0,d=this.runtime.kahanTime.sum;"undefined"===typeof b.extra.Every_seconds&&(b.extra.Every_seconds=a);var e=b.extra.Every_seconds;return d>=c+e?(b.extra.Every_lastTime=c+e,d>=b.extra.Every_lastTime+e&&(b.extra.Every_lastTime=d),b.extra.Every_seconds=a,!0):!1};a.prototype.PickNth=function(a,b){if(!a)return!1;var c=a.getCurrentSol(),d=c.getObjects();b=cr.floor(b);
if(0>b||b>=d.length)return!1;c.pick_one(d[b]);a.applySolToContainer();return!0};a.prototype.PickRandom=function(a){if(!a)return!1;var b=a.getCurrentSol(),c=b.getObjects(),d=cr.floor(Math.random()*c.length);if(d>=c.length)return!1;b.pick_one(c[d]);a.applySolToContainer();return!0};a.prototype.CompareVar=function(a,b,c){return cr.do_cmp(a.getValue(),b,c)};a.prototype.IsGroupActive=function(a){return this.runtime.activeGroups[a.toLowerCase()]};a.prototype.IsPreview=function(){return"undefined"!==typeof cr_is_preview};
a.prototype.PickAll=function(a){if(!a||!a.instances.length)return!1;a.getCurrentSol().select_all=!0;a.applySolToContainer();return!0};a.prototype.IsMobile=function(){return this.runtime.isMobile};a.prototype.CompareBetween=function(a,b,c){return a>=b&&a<=c};a.prototype.Else=function(){var a=this.runtime.getCurrentEventStack();return a.else_branch_ran?!1:!a.last_event_true};a.prototype.OnLoadFinished=function(){return!0};a.prototype.OnCanvasSnapshot=function(){return!0};a.prototype.EffectsSupported=
function(){return!!this.runtime.glwrap};a.prototype.OnSaveComplete=function(){return!0};a.prototype.OnLoadComplete=function(){return!0};a.prototype.OnLoadFailed=function(){return!0};a.prototype.ObjectUIDExists=function(a){return!!this.runtime.getObjectByUID(a)};a.prototype.IsOnPlatform=function(a){var b=this.runtime;switch(a){case 0:return!b.isDomFree&&!b.isNodeWebkit&&!b.isPhoneGap&&!b.isWindows8App&&!b.isWindowsPhone8&&!b.isBlackberry10;case 1:return b.isiOS;case 2:return b.isAndroid;case 3:return b.isWindows8App;
case 4:return b.isWindowsPhone8;case 5:return b.isBlackberry10;case 6:return b.isTizen;case 7:return b.isNodeWebkit;case 8:return b.isCocoonJs;case 9:return b.isPhoneGap;case 10:return b.isArcade;case 11:return b.isNodeWebkit;default:return!1}};var h=null,m="",n="";a.prototype.RegexTest=function(a,b,d){return c(b,d).test(a)};var q=[];a.prototype.PickOverlappingPoint=function(a,b,c){if(!a)return!1;var d=a.getCurrentSol(),e=d.getObjects(),f=this.runtime.getCurrentEventStack().current_event.orblock,
m=this.runtime.getCurrentCondition(),h,g;d.select_all?(cr.shallowAssignArray(q,e),d.else_instances.length=0,d.select_all=!1,d.instances.length=0):f?(cr.shallowAssignArray(q,d.else_instances),d.else_instances.length=0):(cr.shallowAssignArray(q,e),d.instances.length=0);e=0;for(f=q.length;e<f;++e)h=q[e],(g=cr.xor(h.contains_pt(b,c),m.inverted))?d.instances.push(h):d.else_instances.push(h);a.applySolToContainer();return cr.xor(!!d.instances.length,m.inverted)};f.cnds=new a;d.prototype.GoToLayout=function(a){!this.runtime.isloading&&
!this.runtime.changelayout&&(this.runtime.changelayout=a)};d.prototype.CreateObject=function(a,b,c,d){if(b&&a&&(b=this.runtime.createInstance(a,b,c,d))){this.runtime.isInOnDestroy++;var e;this.runtime.trigger(Object.getPrototypeOf(a.plugin).cnds.OnCreated,b);if(b.is_contained){c=0;for(d=b.siblings.length;c<d;c++)e=b.siblings[c],this.runtime.trigger(Object.getPrototypeOf(e.type.plugin).cnds.OnCreated,e)}this.runtime.isInOnDestroy--;a=a.getCurrentSol();a.select_all=!1;a.instances.length=1;a.instances[0]=
b;if(b.is_contained){c=0;for(d=b.siblings.length;c<d;c++)e=b.siblings[c],a=e.type.getCurrentSol(),a.select_all=!1,a.instances.length=1,a.instances[0]=e}}};d.prototype.SetLayerVisible=function(a,b){a&&a.visible!==b&&(a.visible=b,this.runtime.redraw=!0)};d.prototype.SetLayerOpacity=function(a,b){a&&(b=cr.clamp(b/100,0,1),a.opacity!==b&&(a.opacity=b,this.runtime.redraw=!0))};d.prototype.SetLayerScaleRate=function(a,b){a&&a.zoomRate!==b&&(a.zoomRate=b,this.runtime.redraw=!0)};d.prototype.SetLayoutScale=
function(a){this.runtime.running_layout&&this.runtime.running_layout.scale!==a&&(this.runtime.running_layout.scale=a,this.runtime.running_layout.boundScrolling(),this.runtime.redraw=!0)};d.prototype.ScrollX=function(a){this.runtime.running_layout.scrollToX(a)};d.prototype.ScrollY=function(a){this.runtime.running_layout.scrollToY(a)};d.prototype.Scroll=function(a,b){this.runtime.running_layout.scrollToX(a);this.runtime.running_layout.scrollToY(b)};d.prototype.ScrollToObject=function(a){if(a=a.getFirstPicked())this.runtime.running_layout.scrollToX(a.x),
this.runtime.running_layout.scrollToY(a.y)};d.prototype.SetVar=function(a,b){0===a.vartype?cr.is_number(b)?a.setValue(b):a.setValue(parseFloat(b)):1===a.vartype&&a.setValue(b.toString())};d.prototype.AddVar=function(a,b){0===a.vartype?cr.is_number(b)?a.setValue(a.getValue()+b):a.setValue(a.getValue()+parseFloat(b)):1===a.vartype&&a.setValue(a.getValue()+b.toString())};d.prototype.SubVar=function(a,b){0===a.vartype&&(cr.is_number(b)?a.setValue(a.getValue()-b):a.setValue(a.getValue()-parseFloat(b)))};
d.prototype.SetGroupActive=function(a,b){var c=this.runtime.activeGroups,d=a.toLowerCase();switch(b){case 0:c[d]=!1;break;case 1:c[d]=!0;break;case 2:c[d]=!c[d]}};d.prototype.SetTimescale=function(a){0>a&&(a=0);this.runtime.timescale=a};d.prototype.SetObjectTimescale=function(a,b){var c=b;0>c&&(c=0);if(a){var d=a.getCurrentSol().getObjects(),e,f;e=0;for(f=d.length;e<f;e++)d[e].my_timescale=c}};d.prototype.RestoreObjectTimescale=function(a){if(!a)return!1;a=a.getCurrentSol().getObjects();var b,c;b=
0;for(c=a.length;b<c;b++)a[b].my_timescale=-1};var p=[],r=[];d.prototype.Wait=function(a){if(!(0>a)){var b,c,d,e=this.runtime.getCurrentEventStack(),f;f=p.length?p.pop():{sols:{},solModifiers:[]};f.deleteme=!1;f.time=this.runtime.kahanTime.sum+a;f.ev=e.current_event;f.actindex=e.actindex+1;a=0;for(b=this.runtime.types_by_index.length;a<b;a++)d=this.runtime.types_by_index[a],c=d.getCurrentSol(),c.select_all&&-1===e.current_event.solModifiers.indexOf(d)||(f.solModifiers.push(d),d=void 0,d=r.length?
r.pop():{insts:[]},d.sa=!1,d.sa=c.select_all,cr.shallowAssignArray(d.insts,c.instances),f.sols[a.toString()]=d);this.waits.push(f);return!0}};d.prototype.SetLayerScale=function(a,b){a&&a.scale!==b&&(a.scale=b,this.runtime.redraw=!0)};d.prototype.ResetGlobals=function(){var a,b,c;a=0;for(b=this.runtime.all_global_vars.length;a<b;a++)c=this.runtime.all_global_vars[a],c.data=c.initial};d.prototype.SetLayoutAngle=function(a){a=cr.to_radians(a);a=cr.clamp_angle(a);this.runtime.running_layout&&this.runtime.running_layout.angle!==
a&&(this.runtime.running_layout.angle=a,this.runtime.redraw=!0)};d.prototype.SetLayerAngle=function(a,b){a&&(b=cr.to_radians(b),b=cr.clamp_angle(b),a.angle!==b&&(a.angle=b,this.runtime.redraw=!0))};d.prototype.SetLayerParallax=function(a,b,c){a&&!(a.parallaxX===b/100&&a.parallaxY===c/100)&&(a.parallaxX=b/100,a.parallaxY=c/100,this.runtime.redraw=!0)};d.prototype.SetLayerBackground=function(a,b){if(a){var c=cr.GetRValue(b),d=cr.GetGValue(b),e=cr.GetBValue(b);a.background_color[0]===c&&a.background_color[1]===
d&&a.background_color[2]===e||(a.background_color[0]=c,a.background_color[1]=d,a.background_color[2]=e,this.runtime.redraw=!0)}};d.prototype.SetLayerTransparent=function(a,b){a&&!!b!==!!a.transparent&&(a.transparent=!!b,this.runtime.redraw=!0)};d.prototype.StopLoop=function(){0>this.runtime.loop_stack_index||(this.runtime.getCurrentLoop().stopped=!0)};d.prototype.GoToLayoutByName=function(a){if(!this.runtime.isloading&&!this.runtime.changelayout)for(var b in this.runtime.layouts)if(this.runtime.layouts.hasOwnProperty(b)&&
cr.equals_nocase(b,a)){this.runtime.changelayout=this.runtime.layouts[b];break}};d.prototype.RestartLayout=function(a){if(!this.runtime.isloading&&!this.runtime.changelayout&&this.runtime.running_layout){this.runtime.changelayout=this.runtime.running_layout;var b,c;a=0;for(b=this.runtime.allGroups.length;a<b;a++)c=this.runtime.allGroups[a],this.runtime.activeGroups[c.group_name.toLowerCase()]=c.initially_activated}};d.prototype.SnapshotCanvas=function(a,b){this.runtime.snapshotCanvas=[0===a?"image/png":
"image/jpeg",b/100];this.runtime.redraw=!0};d.prototype.SetCanvasSize=function(a,b){0>=a||0>=b||this.runtime.setSize(a,b)};d.prototype.SetLayoutEffectEnabled=function(a,b){if(this.runtime.running_layout&&this.runtime.glwrap){var c=this.runtime.running_layout.getEffectByName(b);if(c){var d=1===a;c.active!=d&&(c.active=d,this.runtime.running_layout.updateActiveEffects(),this.runtime.redraw=!0)}}};d.prototype.SetLayerEffectEnabled=function(a,b,c){if(a&&this.runtime.glwrap&&(c=a.getEffectByName(c)))b=
1===b,c.active!=b&&(c.active=b,a.updateActiveEffects(),this.runtime.redraw=!0)};d.prototype.SetLayoutEffectParam=function(a,b,c){if(this.runtime.running_layout&&this.runtime.glwrap&&(a=this.runtime.running_layout.getEffectByName(a))){var d=this.runtime.running_layout.effect_params[a.index];b=Math.floor(b);0>b||b>=d.length||(1===this.runtime.glwrap.getProgramParameterType(a.shaderindex,b)&&(c/=100),d[b]!==c&&(d[b]=c,a.active&&(this.runtime.redraw=!0)))}};d.prototype.SetLayerEffectParam=function(a,
b,c,d){if(a&&this.runtime.glwrap&&(b=a.getEffectByName(b)))a=a.effect_params[b.index],c=Math.floor(c),0>c||c>=a.length||(1===this.runtime.glwrap.getProgramParameterType(b.shaderindex,c)&&(d/=100),a[c]!==d&&(a[c]=d,b.active&&(this.runtime.redraw=!0)))};d.prototype.SaveState=function(a){this.runtime.saveToSlot=a};d.prototype.LoadState=function(a){this.runtime.loadFromSlot=a};d.prototype.LoadStateJSON=function(a){this.runtime.loadFromJson=a};f.acts=new d;e.prototype["int"]=function(a,b){cr.is_string(b)?
(a.set_int(parseInt(b,10)),isNaN(a.data)&&(a.data=0)):a.set_int(b)};e.prototype["float"]=function(a,b){cr.is_string(b)?(a.set_float(parseFloat(b)),isNaN(a.data)&&(a.data=0)):a.set_float(b)};e.prototype.str=function(a,b){cr.is_string(b)?a.set_string(b):a.set_string(b.toString())};e.prototype.len=function(a,b){a.set_int(b.length||0)};e.prototype.random=function(a,b,c){void 0===c?a.set_float(Math.random()*b):a.set_float(Math.random()*(c-b)+b)};e.prototype.sqrt=function(a,b){a.set_float(Math.sqrt(b))};
e.prototype.abs=function(a,b){a.set_float(Math.abs(b))};e.prototype.round=function(a,b){a.set_int(Math.round(b))};e.prototype.floor=function(a,b){a.set_int(Math.floor(b))};e.prototype.ceil=function(a,b){a.set_int(Math.ceil(b))};e.prototype.sin=function(a,b){a.set_float(Math.sin(cr.to_radians(b)))};e.prototype.cos=function(a,b){a.set_float(Math.cos(cr.to_radians(b)))};e.prototype.tan=function(a,b){a.set_float(Math.tan(cr.to_radians(b)))};e.prototype.asin=function(a,b){a.set_float(cr.to_degrees(Math.asin(b)))};
e.prototype.acos=function(a,b){a.set_float(cr.to_degrees(Math.acos(b)))};e.prototype.atan=function(a,b){a.set_float(cr.to_degrees(Math.atan(b)))};e.prototype.exp=function(a,b){a.set_float(Math.exp(b))};e.prototype.ln=function(a,b){a.set_float(Math.log(b))};e.prototype.log10=function(a,b){a.set_float(Math.log(b)/Math.LN10)};e.prototype.max=function(a){var b=arguments[1],c,d;c=2;for(d=arguments.length;c<d;c++)b<arguments[c]&&(b=arguments[c]);a.set_float(b)};e.prototype.min=function(a){var b=arguments[1],
c,d;c=2;for(d=arguments.length;c<d;c++)b>arguments[c]&&(b=arguments[c]);a.set_float(b)};e.prototype.dt=function(a){a.set_float(this.runtime.dt)};e.prototype.timescale=function(a){a.set_float(this.runtime.timescale)};e.prototype.wallclocktime=function(a){a.set_float((Date.now()-this.runtime.start_time)/1E3)};e.prototype.time=function(a){a.set_float(this.runtime.kahanTime.sum)};e.prototype.tickcount=function(a){a.set_int(this.runtime.tickcount)};e.prototype.objectcount=function(a){a.set_int(this.runtime.objectcount)};
e.prototype.fps=function(a){a.set_int(this.runtime.fps)};e.prototype.loopindex=function(a,b){var c,d,e;if(this.runtime.loop_stack.length)if(b){d=0;for(e=this.runtime.loop_stack.length;d<e;d++)if(c=this.runtime.loop_stack[d],c.name===b){a.set_int(c.index);return}a.set_int(0)}else c=this.runtime.getCurrentLoop(),a.set_int(c?c.index:-1);else a.set_int(0)};e.prototype.distance=function(a,b,c,d,e){a.set_float(cr.distanceTo(b,c,d,e))};e.prototype.angle=function(a,b,c,d,e){a.set_float(cr.to_degrees(cr.angleTo(b,
c,d,e)))};e.prototype.scrollx=function(a){a.set_float(this.runtime.running_layout.scrollX)};e.prototype.scrolly=function(a){a.set_float(this.runtime.running_layout.scrollY)};e.prototype.newline=function(a){a.set_string("\n")};e.prototype.lerp=function(a,b,c,d){a.set_float(cr.lerp(b,c,d))};e.prototype.windowwidth=function(a){a.set_int(this.runtime.width)};e.prototype.windowheight=function(a){a.set_int(this.runtime.height)};e.prototype.uppercase=function(a,b){a.set_string(cr.is_string(b)?b.toUpperCase():
"")};e.prototype.lowercase=function(a,b){a.set_string(cr.is_string(b)?b.toLowerCase():"")};e.prototype.clamp=function(a,b,c,d){b<c?a.set_float(c):b>d?a.set_float(d):a.set_float(b)};e.prototype.layerscale=function(a,b){var c=this.runtime.getLayer(b);c?a.set_float(c.scale):a.set_float(0)};e.prototype.layeropacity=function(a,b){var c=this.runtime.getLayer(b);c?a.set_float(100*c.opacity):a.set_float(0)};e.prototype.layerscalerate=function(a,b){var c=this.runtime.getLayer(b);c?a.set_float(c.zoomRate):
a.set_float(0)};e.prototype.layerparallaxx=function(a,b){var c=this.runtime.getLayer(b);c?a.set_float(100*c.parallaxX):a.set_float(0)};e.prototype.layerparallaxy=function(a,b){var c=this.runtime.getLayer(b);c?a.set_float(100*c.parallaxY):a.set_float(0)};e.prototype.layoutscale=function(a){this.runtime.running_layout?a.set_float(this.runtime.running_layout.scale):a.set_float(0)};e.prototype.layoutangle=function(a){a.set_float(cr.to_degrees(this.runtime.running_layout.angle))};e.prototype.layerangle=
function(a,b){var c=this.runtime.getLayer(b);c?a.set_float(cr.to_degrees(c.angle)):a.set_float(0)};e.prototype.layoutwidth=function(a){a.set_int(this.runtime.running_layout.width)};e.prototype.layoutheight=function(a){a.set_int(this.runtime.running_layout.height)};e.prototype.find=function(a,b,c){cr.is_string(b)&&cr.is_string(c)?a.set_int(b.search(RegExp(cr.regexp_escape(c),"i"))):a.set_int(-1)};e.prototype.left=function(a,b,c){a.set_string(cr.is_string(b)?b.substr(0,c):"")};e.prototype.right=function(a,
b,c){a.set_string(cr.is_string(b)?b.substr(b.length-c):"")};e.prototype.mid=function(a,b,c,d){a.set_string(cr.is_string(b)?b.substr(c,d):"")};e.prototype.tokenat=function(a,b,c,d){cr.is_string(b)&&cr.is_string(d)?(b=b.split(d),c=cr.floor(c),0>c||c>=b.length?a.set_string(""):a.set_string(b[c])):a.set_string("")};e.prototype.tokencount=function(a,b,c){cr.is_string(b)&&b.length?a.set_int(b.split(c).length):a.set_int(0)};e.prototype.replace=function(a,b,c,d){cr.is_string(b)&&cr.is_string(c)&&cr.is_string(d)?
a.set_string(b.replace(RegExp(cr.regexp_escape(c),"gi"),d)):a.set_string(cr.is_string(b)?b:"")};e.prototype.trim=function(a,b){a.set_string(cr.is_string(b)?b.trim():"")};e.prototype.pi=function(a){a.set_float(cr.PI)};e.prototype.layoutname=function(a){this.runtime.running_layout?a.set_string(this.runtime.running_layout.name):a.set_string("")};e.prototype.renderer=function(a){a.set_string(this.runtime.gl?"webgl":"canvas2d")};e.prototype.anglediff=function(a,b,c){a.set_float(cr.to_degrees(cr.angleDiff(cr.to_radians(b),
cr.to_radians(c))))};e.prototype.choose=function(a){var b=cr.floor(Math.random()*(arguments.length-1));a.set_any(arguments[b+1])};e.prototype.rgb=function(a,b,c,d){a.set_int(cr.RGB(b,c,d))};e.prototype.projectversion=function(a){a.set_string(this.runtime.versionstr)};e.prototype.anglelerp=function(a,b,c,d){b=cr.to_radians(b);c=cr.to_radians(c);var e=cr.angleDiff(b,c);cr.angleClockwise(c,b)?a.set_float(cr.to_clamped_degrees(b+e*d)):a.set_float(cr.to_clamped_degrees(b-e*d))};e.prototype.anglerotate=
function(a,b,c,d){b=cr.to_radians(b);c=cr.to_radians(c);d=cr.to_radians(d);a.set_float(cr.to_clamped_degrees(cr.angleRotate(b,c,d)))};e.prototype.zeropad=function(a,b,c){var d=0>b?"-":"";0>b&&(b=-b);c-=b.toString().length;for(var e=0;e<c;e++)d+="0";a.set_string(d+b.toString())};e.prototype.cpuutilisation=function(a){a.set_float(this.runtime.cpuutilisation/1E3)};e.prototype.viewportleft=function(a,b){var c=this.runtime.getLayer(b);a.set_float(c?c.viewLeft:0)};e.prototype.viewporttop=function(a,b){var c=
this.runtime.getLayer(b);a.set_float(c?c.viewTop:0)};e.prototype.viewportright=function(a,b){var c=this.runtime.getLayer(b);a.set_float(c?c.viewRight:0)};e.prototype.viewportbottom=function(a,b){var c=this.runtime.getLayer(b);a.set_float(c?c.viewBottom:0)};e.prototype.loadingprogress=function(a){a.set_float(this.runtime.loadingprogress)};e.prototype.unlerp=function(a,b,c,d){a.set_float((d-b)/(c-b))};e.prototype.canvassnapshot=function(a){a.set_string(this.runtime.snapshotData)};e.prototype.urlencode=
function(a,b){a.set_string(encodeURIComponent(b))};e.prototype.urldecode=function(a,b){a.set_string(decodeURIComponent(b))};e.prototype.canvastolayerx=function(a,b,c,d){b=this.runtime.getLayer(b);a.set_float(b?b.canvasToLayer(c,d,!0):0)};e.prototype.canvastolayery=function(a,b,c,d){b=this.runtime.getLayer(b);a.set_float(b?b.canvasToLayer(c,d,!1):0)};e.prototype.layertocanvasx=function(a,b,c,d){b=this.runtime.getLayer(b);a.set_float(b?b.layerToCanvas(c,d,!0):0)};e.prototype.layertocanvasy=function(a,
b,c,d){b=this.runtime.getLayer(b);a.set_float(b?b.layerToCanvas(c,d,!1):0)};e.prototype.savestatejson=function(a){a.set_string(this.runtime.lastSaveJson)};e.prototype.imagememoryusage=function(a){this.runtime.glwrap?a.set_float(Math.round(100*this.runtime.glwrap.estimateVRAM()/1048576)/100):a.set_float(0)};e.prototype.regexsearch=function(a,b,d,e){d=c(d,e);a.set_int(b?b.search(d):-1)};e.prototype.regexreplace=function(a,b,d,e,f){d=c(d,e);a.set_string(b?b.replace(d,f):"")};var s=[],t="",v="",w="";
e.prototype.regexmatchcount=function(a,b,d,e){c(d,e);g(b,d,e);a.set_int(s?s.length:0)};e.prototype.regexmatchat=function(a,b,d,e,f){f=Math.floor(f);c(d,e);g(b,d,e);!s||0>f||f>=s.length?a.set_string(""):a.set_string(s[f])};e.prototype.infinity=function(a){a.set_float(Infinity)};f.exps=new e;f.runWaits=function(){var a,b,c,d,e,f,m=this.runtime.getCurrentEventStack();a=0;for(c=this.waits.length;a<c;a++)if(d=this.waits[a],!(d.time>this.runtime.kahanTime.sum)){m.current_event=d.ev;m.actindex=d.actindex;
m.cndindex=0;for(b in d.sols)d.sols.hasOwnProperty(b)&&(e=this.runtime.types_by_index[parseInt(b,10)].getCurrentSol(),f=d.sols[b],e.select_all=f.sa,cr.shallowAssignArray(e.instances,f.insts),e=f,e.insts.length=0,r.push(e));d.ev.resume_actions_and_subevents();this.runtime.clearSol(d.solModifiers);d.deleteme=!0}b=a=0;for(c=this.waits.length;a<c;a++)d=this.waits[a],this.waits[b]=d,d.deleteme?(cr.wipe(d.sols),d.solModifiers.length=0,p.push(d)):b++;this.waits.length=b}})();
cr.add_common_aces=function(a){var b=a[0].prototype,c=a[1],d=a[3],e=a[4],g=a[5],f=a[6],l=a[7];a=a[8];b.cnds||(b.cnds={});b.acts||(b.acts={});b.exps||(b.exps={});var k=b.cnds,h=b.acts,b=b.exps;d&&(k.CompareX=function(a,b){return cr.do_cmp(this.x,a,b)},k.CompareY=function(a,b){return cr.do_cmp(this.y,a,b)},k.IsOnScreen=function(){var a=this.layer;this.update_bbox();var b=this.bbox;return!(b.right<a.viewLeft||b.bottom<a.viewTop||b.left>a.viewRight||b.top>a.viewBottom)},k.IsOutsideLayout=function(){this.update_bbox();
var a=this.bbox,b=this.runtime.running_layout;return 0>a.right||0>a.bottom||a.left>b.width||a.top>b.height},k.PickDistance=function(a,b,c){var d=this.getCurrentSol(),e=d.getObjects();if(!e.length)return!1;var f=e[0],h=f,g=cr.distanceTo(f.x,f.y,b,c),k,l,C;k=1;for(l=e.length;k<l;k++)if(f=e[k],C=cr.distanceTo(f.x,f.y,b,c),0===a&&C<g||1===a&&C>g)g=C,h=f;d.pick_one(h);return!0},h.SetX=function(a){this.x!==a&&(this.x=a,this.set_bbox_changed())},h.SetY=function(a){this.y!==a&&(this.y=a,this.set_bbox_changed())},
h.SetPos=function(a,b){if(this.x!==a||this.y!==b)this.x=a,this.y=b,this.set_bbox_changed()},h.SetPosToObject=function(a,b){var c=a.getPairedInstance(this);if(c){var d;c.getImagePoint?(d=c.getImagePoint(b,!0),c=c.getImagePoint(b,!1)):(d=c.x,c=c.y);if(this.x!==d||this.y!==c)this.x=d,this.y=c,this.set_bbox_changed()}},h.MoveForward=function(a){0!==a&&(this.x+=Math.cos(this.angle)*a,this.y+=Math.sin(this.angle)*a,this.set_bbox_changed())},h.MoveAtAngle=function(a,b){0!==b&&(this.x+=Math.cos(cr.to_radians(a))*
b,this.y+=Math.sin(cr.to_radians(a))*b,this.set_bbox_changed())},b.X=function(a){a.set_float(this.x)},b.Y=function(a){a.set_float(this.y)},b.dt=function(a){a.set_float(this.runtime.getDt(this))});e&&(k.CompareWidth=function(a,b){return cr.do_cmp(this.width,a,b)},k.CompareHeight=function(a,b){return cr.do_cmp(this.height,a,b)},h.SetWidth=function(a){this.width!==a&&(this.width=a,this.set_bbox_changed())},h.SetHeight=function(a){this.height!==a&&(this.height=a,this.set_bbox_changed())},h.SetSize=function(a,
b){if(this.width!==a||this.height!==b)this.width=a,this.height=b,this.set_bbox_changed()},b.Width=function(a){a.set_float(this.width)},b.Height=function(a){a.set_float(this.height)},b.BBoxLeft=function(a){this.update_bbox();a.set_float(this.bbox.left)},b.BBoxTop=function(a){this.update_bbox();a.set_float(this.bbox.top)},b.BBoxRight=function(a){this.update_bbox();a.set_float(this.bbox.right)},b.BBoxBottom=function(a){this.update_bbox();a.set_float(this.bbox.bottom)});g&&(k.AngleWithin=function(a,b){return cr.angleDiff(this.angle,
cr.to_radians(b))<=cr.to_radians(a)},k.IsClockwiseFrom=function(a){return cr.angleClockwise(this.angle,cr.to_radians(a))},k.IsBetweenAngles=function(a,b){var c=cr.to_clamped_radians(a),d=cr.to_clamped_radians(b),e=cr.clamp_angle(this.angle);return cr.angleClockwise(d,c)?cr.angleClockwise(e,c)&&!cr.angleClockwise(e,d):!(!cr.angleClockwise(e,c)&&cr.angleClockwise(e,d))},h.SetAngle=function(a){a=cr.to_radians(cr.clamp_angle_degrees(a));!isNaN(a)&&this.angle!==a&&(this.angle=a,this.set_bbox_changed())},
h.RotateClockwise=function(a){0!==a&&!isNaN(a)&&(this.angle+=cr.to_radians(a),this.angle=cr.clamp_angle(this.angle),this.set_bbox_changed())},h.RotateCounterclockwise=function(a){0!==a&&!isNaN(a)&&(this.angle-=cr.to_radians(a),this.angle=cr.clamp_angle(this.angle),this.set_bbox_changed())},h.RotateTowardAngle=function(a,b){var c=cr.angleRotate(this.angle,cr.to_radians(b),cr.to_radians(a));!isNaN(c)&&this.angle!==c&&(this.angle=c,this.set_bbox_changed())},h.RotateTowardPosition=function(a,b,c){b=Math.atan2(c-
this.y,b-this.x);a=cr.angleRotate(this.angle,b,cr.to_radians(a));!isNaN(a)&&this.angle!==a&&(this.angle=a,this.set_bbox_changed())},h.SetTowardPosition=function(a,b){var c=Math.atan2(b-this.y,a-this.x);!isNaN(c)&&this.angle!==c&&(this.angle=c,this.set_bbox_changed())},b.Angle=function(a){a.set_float(cr.to_clamped_degrees(this.angle))});c||(k.CompareInstanceVar=function(a,b,c){return cr.do_cmp(this.instance_vars[a],b,c)},k.IsBoolInstanceVarSet=function(a){return this.instance_vars[a]},k.PickInstVarHiLow=
function(a,b){var c=this.getCurrentSol(),d=c.getObjects();if(!d.length)return!1;var e=d[0],f=e,h=e.instance_vars[b],g,k,l;g=1;for(k=d.length;g<k;g++)if(e=d[g],l=e.instance_vars[b],0===a&&l<h||1===a&&l>h)h=l,f=e;c.pick_one(f);return!0},k.PickByUID=function(a){var b,c,d,e,f;if(this.runtime.getCurrentCondition().inverted){f=this.getCurrentSol();if(f.select_all){f.select_all=!1;f.instances.length=0;f.else_instances.length=0;d=this.instances;b=0;for(c=d.length;b<c;b++)e=d[b],e.uid===a?f.else_instances.push(e):
f.instances.push(e)}else{d=b=0;for(c=f.instances.length;b<c;b++)e=f.instances[b],f.instances[d]=e,e.uid===a?f.else_instances.push(e):d++;f.instances.length=d}return!!f.instances.length}e=this.runtime.getObjectByUID(a);if(!e)return!1;f=this.getCurrentSol();if(!f.select_all&&-1===f.instances.indexOf(e))return!1;if(this.is_family){a=e.type.families;b=0;for(c=a.length;b<c;b++)if(a[b]===this)return f.pick_one(e),!0}else if(e.type===this)return f.pick_one(e),!0;return!1},k.OnCreated=function(){return!0},
k.OnDestroyed=function(){return!0},h.SetInstanceVar=function(a,b){var c=this.instance_vars;cr.is_number(c[a])?cr.is_number(b)?c[a]=b:c[a]=parseFloat(b):cr.is_string(c[a])&&(cr.is_string(b)?c[a]=b:c[a]=b.toString())},h.AddInstanceVar=function(a,b){var c=this.instance_vars;cr.is_number(c[a])?cr.is_number(b)?c[a]+=b:c[a]+=parseFloat(b):cr.is_string(c[a])&&(cr.is_string(b)?c[a]+=b:c[a]+=b.toString())},h.SubInstanceVar=function(a,b){var c=this.instance_vars;cr.is_number(c[a])&&(cr.is_number(b)?c[a]-=b:
c[a]-=parseFloat(b))},h.SetBoolInstanceVar=function(a,b){this.instance_vars[a]=b?1:0},h.ToggleBoolInstanceVar=function(a){this.instance_vars[a]=1-this.instance_vars[a]},h.Destroy=function(){this.runtime.DestroyInstance(this)},b.Count=function(a){var b=a.object_class.instances.length,c,d,e;c=0;for(d=this.runtime.createRow.length;c<d;c++)e=this.runtime.createRow[c],a.object_class.is_family?0<=e.type.families.indexOf(a.object_class)&&b++:e.type===a.object_class&&b++;a.set_int(b)},b.PickedCount=function(a){a.set_int(a.object_class.getCurrentSol().getObjects().length)},
b.UID=function(a){a.set_int(this.uid)},b.IID=function(a){a.set_int(this.get_iid())});f&&(k.IsVisible=function(){return this.visible},h.SetVisible=function(a){!a!==!this.visible&&(this.visible=a,this.runtime.redraw=!0)},k.CompareOpacity=function(a,b){return cr.do_cmp(cr.round6dp(100*this.opacity),a,b)},h.SetOpacity=function(a){a/=100;0>a?a=0:1<a&&(a=1);a!==this.opacity&&(this.opacity=a,this.runtime.redraw=!0)},b.Opacity=function(a){a.set_float(cr.round6dp(100*this.opacity))});l&&(k.IsOnLayer=function(a){return!a?
!1:this.layer===a},k.PickTopBottom=function(a){var b=this.getCurrentSol(),c=b.getObjects();if(!c.length)return!1;var d=c[0],e=d,f,h;f=1;for(h=c.length;f<h;f++)if(d=c[f],0===a){if(d.layer.index>e.layer.index||d.layer.index===e.layer.index&&d.get_zindex()>e.get_zindex())e=d}else if(d.layer.index<e.layer.index||d.layer.index===e.layer.index&&d.get_zindex()<e.get_zindex())e=d;b.pick_one(e);return!0},h.MoveToTop=function(){var a=this.get_zindex();a!==this.layer.instances.length-1&&(cr.arrayRemove(this.layer.instances,
a),this.layer.instances.push(this),this.runtime.redraw=!0,this.layer.zindices_stale=!0)},h.MoveToBottom=function(){var a=this.get_zindex();0!==a&&(cr.arrayRemove(this.layer.instances,a),this.layer.instances.unshift(this),this.runtime.redraw=!0,this.layer.zindices_stale=!0)},h.MoveToLayer=function(a){a&&a!=this.layer&&(cr.arrayRemove(this.layer.instances,this.get_zindex()),this.layer.zindices_stale=!0,this.layer=a,this.zindex=a.instances.length,a.instances.push(this),this.runtime.redraw=!0)},h.ZMoveToObject=
function(a,b){var c=0===a;if(b){var d=b.getFirstPicked(this);if(d&&d.uid!==this.uid){this.layer.index!==d.layer.index&&(cr.arrayRemove(this.layer.instances,this.get_zindex()),this.layer.zindices_stale=!0,this.layer=d.layer,this.zindex=d.layer.instances.length,d.layer.instances.push(this));var e=this.get_zindex(),d=d.get_zindex();cr.arrayRemove(this.layer.instances,e);e<d&&d--;c&&d++;d===this.layer.instances.length?this.layer.instances.push(this):this.layer.instances.splice(d,0,this);this.layer.zindices_stale=
!0;this.runtime.redraw=!0}}},b.LayerNumber=function(a){a.set_int(this.layer.number)},b.LayerName=function(a){a.set_string(this.layer.name)},b.ZIndex=function(a){a.set_int(this.get_zindex())});a&&(h.SetEffectEnabled=function(a,b){if(this.runtime.glwrap){var c=this.type.getEffectIndexByName(b);if(!(0>c)){var d=1===a;this.active_effect_flags[c]!==d&&(this.active_effect_flags[c]=d,this.updateActiveEffects(),this.runtime.redraw=!0)}}},h.SetEffectParam=function(a,b,c){if(this.runtime.glwrap){var d=this.type.getEffectIndexByName(a);
0>d||(a=this.type.effect_types[d],d=this.effect_params[d],b=Math.floor(b),0>b||b>=d.length||(1===this.runtime.glwrap.getProgramParameterType(a.shaderindex,b)&&(c/=100),d[b]!==c&&(d[b]=c,a.active&&(this.runtime.redraw=!0))))}})};cr.set_bbox_changed=function(){this.bbox_changed=!0;this.runtime.redraw=!0;var a,b;a=0;for(b=this.bbox_changed_callbacks.length;a<b;a++)this.bbox_changed_callbacks[a](this)};cr.add_bbox_changed_callback=function(a){a&&this.bbox_changed_callbacks.push(a)};
cr.update_bbox=function(){if(this.bbox_changed){this.bbox.set(this.x,this.y,this.x+this.width,this.y+this.height);this.bbox.offset(-this.hotspotX*this.width,-this.hotspotY*this.height);this.angle?(this.bbox.offset(-this.x,-this.y),this.bquad.set_from_rotated_rect(this.bbox,this.angle),this.bquad.offset(this.x,this.y),this.bquad.bounding_box(this.bbox)):this.bquad.set_from_rect(this.bbox);var a=0;this.bbox.left>this.bbox.right&&(a=this.bbox.left,this.bbox.left=this.bbox.right,this.bbox.right=a);this.bbox.top>
this.bbox.bottom&&(a=this.bbox.top,this.bbox.top=this.bbox.bottom,this.bbox.bottom=a);this.bbox_changed=!1}};cr.inst_contains_pt=function(a,b){return!this.bbox.contains_pt(a,b)||!this.bquad.contains_pt(a,b)?!1:this.collision_poly&&!this.collision_poly.is_empty()?(this.collision_poly.cache_poly(this.width,this.height,this.angle),this.collision_poly.contains_pt(a-this.x,b-this.y)):!0};cr.inst_get_iid=function(){this.type.updateIIDs();return this.iid};
cr.inst_get_zindex=function(){this.layer.updateZIndices();return this.zindex};cr.inst_updateActiveEffects=function(){this.active_effect_types.length=0;var a,b;a=0;for(b=this.active_effect_flags.length;a<b;a++)this.active_effect_flags[a]&&this.active_effect_types.push(this.type.effect_types[a]);this.uses_shaders=!!this.active_effect_types.length};cr.inst_toString=function(){return"Inst"+this.puid};
cr.type_getFirstPicked=function(a){if(a&&a.is_contained&&a.type!=this){var b,c,d;b=0;for(c=a.siblings.length;b<c;b++)if(d=a.siblings[b],d.type==this)return d}a=this.getCurrentSol().getObjects();return a.length?a[0]:null};cr.type_getPairedInstance=function(a){var b=this.getCurrentSol().getObjects();return b.length?b[a.get_iid()%b.length]:null};cr.type_updateIIDs=function(){if(this.stale_iids&&!this.is_family){var a,b;a=0;for(b=this.instances.length;a<b;a++)this.instances[a].iid=a;this.stale_iids=!1}};
cr.type_getCurrentSol=function(){return this.solstack[this.cur_sol]};cr.type_pushCleanSol=function(){this.cur_sol++;this.cur_sol===this.solstack.length?this.solstack.push(new cr.selection(this)):this.solstack[this.cur_sol].select_all=!0};
cr.type_pushCopySol=function(){this.cur_sol++;this.cur_sol===this.solstack.length&&this.solstack.push(new cr.selection(this));var a=this.solstack[this.cur_sol],b=this.solstack[this.cur_sol-1];b.select_all?a.select_all=!0:(a.select_all=!1,cr.shallowAssignArray(a.instances,b.instances))};cr.type_popSol=function(){this.cur_sol--};
cr.type_getBehaviorByName=function(a){var b,c,d,e,g,f=0;if(!this.is_family){b=0;for(c=this.families.length;b<c;b++){g=this.families[b];d=0;for(e=g.behaviors.length;d<e;d++){if(a===g.behaviors[d].name)return this.extra.lastBehIndex=f,g.behaviors[d];f++}}}b=0;for(c=this.behaviors.length;b<c;b++){if(a===this.behaviors[b].name)return this.extra.lastBehIndex=f,this.behaviors[b];f++}return null};cr.type_getBehaviorIndexByName=function(a){return this.getBehaviorByName(a)?this.extra.lastBehIndex:-1};
cr.type_getEffectIndexByName=function(a){var b,c;b=0;for(c=this.effect_types.length;b<c;b++)if(this.effect_types[b].name===a)return b;return-1};
cr.type_applySolToContainer=function(){if(this.is_contained&&!this.is_family){var a,b,c,d,e,g,f;this.updateIIDs();g=this.getCurrentSol();var l=g.select_all,k=(a=this.runtime.getCurrentEventStack())&&a.current_event&&a.current_event.orblock;a=0;for(b=this.container.length;a<b;a++)if(e=this.container[a],e!==this&&(e.updateIIDs(),f=e.getCurrentSol(),f.select_all=l,!l)){f.instances.length=g.instances.length;c=0;for(d=g.instances.length;c<d;c++)f.instances[c]=e.instances[g.instances[c].iid];if(k){f.else_instances.length=
g.else_instances.length;c=0;for(d=g.else_instances.length;c<d;c++)f.else_instances[c]=e.instances[g.else_instances[c].iid]}}}};cr.type_toString=function(){return"Type"+this.sid};cr.do_cmp=function(a,b,c){if("undefined"===typeof a||"undefined"===typeof c)return!1;switch(b){case 0:return a===c;case 1:return a!==c;case 2:return a<c;case 3:return a<=c;case 4:return a>c;case 5:return a>=c;default:return!1}};cr.shaders={};cr.plugins_.CJSAds=function(a){this.runtime=a};
(function(){function a(){}function b(){}function c(){}var d="",e=[],g=0,f=0,l=!1,k=!1,h=!1,m=cr.plugins_.CJSAds.prototype;m.Type=function(a){this.plugin=a;this.runtime=a.runtime};m.Type.prototype.onCreate=function(){};m.Instance=function(a){this.type=a;this.runtime=a.runtime};m.Instance.prototype.onCreate=function(){this.isShowingFullscreen=this.isShowingBanner=!1;this.triggerProduct="";this.socialService=null;this.socialServiceAvailable=!1;this.storeServiceAvailable=this.runtime.isCocoonJs&&"undefined"!==
typeof CocoonJS.Store.nativeExtensionObjectAvailable;this.storeManaged=1!==this.properties[1];this.storeSandboxed=0!==this.properties[2];this.onConsumePurchaseCompleted=this.onConsumePurchaseFailedTransactionId="";var a=this;this.runtime.isCocoonJs&&(CocoonJS.App.onTextDialogFinished.addEventListener(function(b){d=b;a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnKeyboardOK,a)}),CocoonJS.App.onTextDialogCancelled.addEventListener(function(){a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnKeyboardCancelled,
a)}),CocoonJS.Ad.onBannerShown.addEventListener(function(){a.isShowingBanner=!0;a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnBannerShown,a)}),CocoonJS.Ad.onBannerReady.addEventListener(function(){k=!0;l||(CocoonJS.Ad.setBannerLayout(f),CocoonJS.Ad.showBanner())}),CocoonJS.Ad.onFullScreenShown.addEventListener(function(){a.isShowingFullscreen=!0;a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnFullscreenShown,a)}),CocoonJS.Ad.onFullScreenHidden.addEventListener(function(){a.isShowingFullscreen=
!1;a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnFullscreenHidden,a)}),CocoonJS.Ad.onFullScreenReady.addEventListener(function(){h=!0;preloadFullScreen||CocoonJS.Ad.showFullScreen()}),this.storeServiceAvailable&&(CocoonJS.Store.onProductPurchaseCompleted.addEventListener(function(b){a.triggerProduct=b.productId;a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnPurchaseComplete,a);CocoonJS.Store.addPurchase(b);CocoonJS.Store.consumePurchase(b.transactionId,b.productId);CocoonJS.Store.finishPurchase(b.transactionId)}),
CocoonJS.Store.onConsumePurchaseFailed.addEventListener(function(b,c){this.onConsumePurchaseFailedTransactionId=b;a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.onConsumePurchaseFailed,a)}),CocoonJS.Store.onConsumePurchaseCompleted.addEventListener(function(b){this.onConsumePurchaseCompleted=b;a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.onConsumePurchaseCompleted,a)}),CocoonJS.Store.onProductPurchaseFailed.addEventListener(function(b,c){a.triggerProduct=b;a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnPurchaseFail,
a)}),CocoonJS.Store.onProductPurchaseStarted.addEventListener(function(b){a.triggerProduct=b.productId;a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnPurchaseStart,a)}),CocoonJS.Store.onProductsFetchStarted.addEventListener(function(){a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.onProductsFetchStarted,a)}),CocoonJS.Store.onProductsFetchFailed.addEventListener(function(){a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.onProductsFetchFailed,a)}),CocoonJS.Store.onProductsFetchCompleted.addEventListener(function(b){a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.onProductsFetchCompleted,
a)}),CocoonJS.Store.requestInitialization({managed:this.storeManaged,sandbox:this.storeSandboxed}),CocoonJS.Store.start()),this.socialService=CocoonJS.SocialGaming.GameCenter,this.socialServiceAvailable=!!this.socialService.nativeExtensionObjectAvailable,this.socialService.onRequestLoginSucceed.addEventListener(function(){a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnGCLoginSuccess,a)}),this.socialService.onRequestLoginFailed.addEventListener(function(){a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnGCLoginFail,
a)}),this.socialService.onLogout.addEventListener(function(){a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnGCLogout,a)}),this.socialService.onRequestUserScoreSucceed.addEventListener(function(b){g=b.score||0;a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnGCScoreReceived,a)}),this.socialService.onRequestUserScoreFailed.addEventListener(function(){a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnGCScoreUnavailable,a)}),this.socialService.onSubmitUserScoreSucceed.addEventListener(function(){a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnGCScoreSubmitSuccess,
a)}),this.socialService.onSubmitUserScoreFailed.addEventListener(function(){a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnGCScoreSubmitFail,a)}),this.socialService.onLeaderboardViewSucceed.addEventListener(function(){a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnGCLeaderboardOpen,a)}),this.socialService.onLeaderboardViewClosed.addEventListener(function(){a.runtime.trigger(cr.plugins_.CJSAds.prototype.cnds.OnGCLeaderboardClose,a)}))};a.prototype.IsShowingBanner=function(){return this.isShowingBanner};
a.prototype.IsCocoonJS=function(){return this.runtime.isCocoonJs};a.prototype.OnBannerShown=function(){return!0};a.prototype.OnFullscreenShown=function(){return!0};a.prototype.OnFullscreenHidden=function(){return!0};a.prototype.IsShowingFullscreen=function(){return this.isShowingFullscreen};a.prototype.IsStoreAvailable=function(){return this.runtime.isCocoonJs?this.storeServiceAvailable&&CocoonJS.Store.canPurchase():!1};a.prototype.OnPurchaseStart=function(a){return this.triggerProduct===a};a.prototype.OnPurchaseComplete=
function(a){return this.triggerProduct===a};a.prototype.OnPurchaseFail=function(a){return this.triggerProduct===a};a.prototype.onProductsFetchStarted=function(){return!0};a.prototype.onConsumePurchaseFailed=function(){return!0};a.prototype.onProductsFetchCompleted=function(){return!0};a.prototype.onProductsFetchFailed=function(){return!0};a.prototype.IsProductPurchased=function(a){return this.runtime.isCocoonJs?CocoonJS.Store.isProductPurchased(a):!1};a.prototype.OnKeyboardCancelled=function(){return!0};
a.prototype.OnKeyboardOK=function(){return!0};a.prototype.IsGCAvailable=function(){return this.socialServiceAvailable};a.prototype.IsGCLoggedIn=function(){return!this.socialServiceAvailable?!1:this.socialService.isLoggedIn()};a.prototype.OnGCLoginSuccess=function(){return!0};a.prototype.OnGCLoginFail=function(){return!0};a.prototype.OnGCLogout=function(){return!0};a.prototype.OnGCScoreReceived=function(){return!0};a.prototype.OnGCScoreUnavailable=function(){return!0};a.prototype.OnGCScoreSubmitSuccess=
function(){return!0};a.prototype.OnGCScoreSubmitFail=function(){return!0};a.prototype.OnGCLeaderboardOpen=function(){return!0};a.prototype.OnGCLeaderboardClose=function(){return!0};m.cnds=new a;b.prototype.ShowBanner=function(a){this.runtime.isCocoonJs&&(f=0===a?CocoonJS.Ad.BannerLayout.TOP_CENTER:CocoonJS.Ad.BannerLayout.BOTTOM_CENTER,l=!1,k?(CocoonJS.Ad.setBannerLayout(f),CocoonJS.Ad.showBanner()):CocoonJS.Ad.preloadBanner())};b.prototype.ShowFullscreen=function(){this.runtime.isCocoonJs&&(h?CocoonJS.Ad.showFullScreen():
CocoonJS.Ad.preloadFullScreen())};b.prototype.HideBanner=function(){this.runtime.isCocoonJs&&(CocoonJS.Ad.hideBanner(),this.isShowingBanner=!1)};b.prototype.PreloadBanner=function(){this.runtime.isCocoonJs&&(l=!0,CocoonJS.Ad.preloadBanner())};b.prototype.PreloadFullscreen=function(){this.runtime.isCocoonJs&&CocoonJS.Ad.preloadFullScreen()};b.prototype.RefreshBanner=function(){this.runtime.isCocoonJs&&CocoonJS.Ad.refreshBanner()};b.prototype.RefreshFullScreen=function(){this.runtime.isCocoonJs&&CocoonJS.Ad.refreshFullScreen()};
b.prototype.Purchase=function(a){this.runtime.isCocoonJs&&CocoonJS.Store.purchaseProduct(a)};b.prototype.fetchProductsFromStore=function(a){this.runtime.isCocoonJs&&CocoonJS.Store.fetchProductsFromStore(a.split(","))};b.prototype.restorePurchases=function(){if(this.runtime.isCocoonJs)return CocoonJS.Store.restorePurchases()};b.prototype.PurchasePreview=function(a){this.runtime.isCocoonJs&&CocoonJS.Store.purchaseProductModalWithPreview(a)};b.prototype.RestorePurchases=function(){this.runtime.isCocoonJs&&
CocoonJS.Store.restorePurchases()};b.prototype.PromptKeyboard=function(a,b,c,d,e,f){this.runtime.isCocoonJs&&CocoonJS.App.showTextDialog(a,b,c,["text","num","phone","email","url"][d],e,f)};b.prototype.UpdateProductsList=function(){this.runtime.isCocoonJs&&CocoonJS.Store.canPurchase()&&(e=CocoonJS.Store.getProducts())};b.prototype.GCLogin=function(){this.socialServiceAvailable&&!this.socialService.isLoggedIn()&&this.socialService.requestLogin()};b.prototype.GCLogout=function(){this.socialServiceAvailable&&
this.socialService.isLoggedIn()&&this.socialService.requestLogout()};b.prototype.GCSubmitScore=function(a,b){this.socialServiceAvailable&&this.socialService.isLoggedIn()&&this.socialService.submitUserScore(a,b)};b.prototype.GCRequestScore=function(a){this.socialServiceAvailable&&this.socialService.isLoggedIn()&&this.socialService.requestUserScore(a)};b.prototype.GCOpenLeaderboard=function(a){this.socialServiceAvailable&&this.socialService.isLoggedIn()&&this.socialService.showLeaderboardView(a)};m.acts=
new b;c.prototype.InputText=function(a){a.set_string(d)};c.prototype.ProductCount=function(a){a.set_int(e.length)};c.prototype.ProductDescription=function(a,b){b=Math.floor(b);0>b||b>=e.length?a.set_string(""):a.set_string(e[b].description)};c.prototype.ProductLocalizedPrice=function(a,b){b=Math.floor(b);0>b||b>=e.length?a.set_string(""):a.set_string(e[b].localizedPrice)};c.prototype.ProductPrice=function(a,b){b=Math.floor(b);0>b||b>=e.length?a.set_string(""):a.set_string(e[b].price)};c.prototype.ProductAlias=
function(a,b){b=Math.floor(b);0>b||b>=e.length?a.set_string(""):a.set_string(e[b].productAlias)};c.prototype.ProductID=function(a,b){b=Math.floor(b);0>b||b>=e.length?a.set_string(""):a.set_string(e[b].productId)};c.prototype.ProductTitle=function(a,b){b=Math.floor(b);0>b||b>=e.length?a.set_string(""):a.set_string(e[b].title)};c.prototype.GameCenterScore=function(a){a.set_float(g)};m.exps=new c})();cr.plugins_.MagiCam=function(a){this.runtime=a};
(function(){function a(a,b,c,d,e,f){this.type=a;this.duration=b;this.param1=c;this.param2=d;this.param3=e;this.param4=f;this.progress=0}function b(a,b,c,d,e){this.global=e;this.name=a;this.x=b;this.y=c;this.scale=d;this.following=!1;this.followedObjects=[];this.objectWeights=[];this.followLag=1;this.zoomToContain=!1;this.zoomMarginV=this.zoomMarginH=0;this.transitions=[];this.zoomTransFinished=this.moveTransFinished=!1}function c(){}function d(){}function e(){}var g={lerp:function(a,b,c){return a+
(b-a)*c},cubic:function(a,b,c,d,e){return this.lerp(this.lerp(this.lerp(a,b,e),this.lerp(b,c,e),e),this.lerp(this.lerp(b,c,e),this.lerp(c,d,e),e),e)},clamp:function(a,b,c){return a<b?b:a>c?c:a}};b.prototype.GetName=function(){return this.name};b.prototype.GetX=function(){return this.x};b.prototype.SetX=function(a){this.x=a};b.prototype.GetY=function(){return this.y};b.prototype.SetY=function(a){this.y=a};b.prototype.SetFollowedObject=function(a){this.followedObject=a};b.prototype.ProcessTransitions=
function(a){this.zoomTransFinished=this.moveTransFinished=!1;for(var b,c=0;c<this.transitions.length;)b=this.transitions[c],b.progress=g.clamp(b.progress+1/b.duration*a,0,1),"MOVE"==b.type?(this.x=g.cubic(b.param3,b.param3,b.param1,b.param1,b.progress),this.y=g.cubic(b.param4,b.param4,b.param2,b.param2,b.progress)):"SCALE"==b.type&&(this.scale=g.cubic(b.param2,b.param2,b.param1,b.param1,b.progress)),1==b.progress?("MOVE"==b.type?this.moveTransFinished=!0:"SCALE"==b.type&&(this.zoomTransFinished=!0),
this.transitions.splice(c,1)):c++};b.prototype.ProcessFollowing=function(a,b,c,d){var e=this.followedObjects;if(this.following&&0<e.length){var f=0,l=0,s=0;if(this.zoomToContain){for(var t=s=0,v=0,w=0,y=l=!1,C=!1,z=!1,f=0;f<e.length;f++){var x=e[f];x.update_bbox();l?s=Math.min(s,x.bbox.left):(s=x.bbox.left,l=!0);y?t=Math.max(t,x.bbox.right):(t=x.bbox.right,y=!0);C?v=Math.min(v,x.bbox.top):(v=x.bbox.top,C=!0);z?w=Math.max(w,x.bbox.bottom):(w=x.bbox.bottom,z=!0)}e=(b-2*this.zoomMarginH)/(t-s);y=(c-
2*this.zoomMarginV)/(w-v);f=g.lerp(s,t,0.5);l=g.lerp(v,w,0.5);this.x<b/2/e&&(e=(b-this.zoomMarginH)/t,f=b/e/2);this.x>d.width-b/2/e&&(e=(b-this.zoomMarginH)/(d.width-s),f=d.width-b/e/2);this.y<c/2/y&&(y=(c-this.zoomMarginV)/w,l=c/y/2);this.y>d.height-c/2/y&&(y=(c-this.zoomMarginV)/(d.height-v),l=d.height-c/y/2);s=Math.min(e,y)}else{for(f=c=b=d=0;f<e.length;f++)d+=e[f].x*this.objectWeights[f],b+=e[f].y*this.objectWeights[f],c+=this.objectWeights[f];f=d/c;l=b/c}1==this.followLag?(this.x=f,this.y=l,
this.zoomToContain&&(this.scale=s)):(a=4*this.followLag*a*Math.sqrt(1/a),this.x=g.lerp(this.x,f,a),this.y=g.lerp(this.y,l,a),this.zoomToContain&&(this.scale=g.lerp(this.scale,s,a)))}};var f=cr.plugins_.MagiCam.prototype;f.Type=function(a){this.plugin=a;this.runtime=a.runtime};f.Type.prototype.onCreate=function(){};f.Instance=function(a){this.type=a;this.runtime=a.runtime;this.localCameras=[];this.localCameraCountOld=this.localCameraCount=0;this.globalCameras=[];this.activeCamera=null};var l=f.Instance.prototype;
l.onCreate=function(){this.runtime.tickMe(this);this.my_timescale=-1};l.onLayoutChange=function(){for(var a=0;a<this.localCameraCountOld;a++)this.localCameras.shift();this.localCameraCount-=this.localCameraCountOld};l.tick=function(){this.localCameraCountOld=this.localCameraCount;var a=this.runtime.getDt(this);0==a&&(a=0.1);for(var b=0;b<this.globalCameras.length;b++)this.globalCameras[b].ProcessTransitions(a),this.globalCameras[b].ProcessFollowing(a,this.runtime.original_width,this.runtime.original_height,
this.runtime.running_layout);for(b=0;b<this.localCameras.length;b++)this.localCameras[b].ProcessTransitions(a),this.localCameras[b].ProcessFollowing(a,this.runtime.original_width,this.runtime.original_height,this.runtime.running_layout);null!=this.activeCamera&&(this.runtime.running_layout.scrollToX(this.activeCamera.GetX()),this.runtime.running_layout.scrollToY(this.activeCamera.GetY()),this.runtime.running_layout.scale=this.activeCamera.scale,this.runtime.redraw=!0)};l.draw=function(a){};l.drawGL=
function(a){};l.GetCamera=function(a){if(""==a)return this.activeCamera;for(var b=0;b<this.globalCameras.length;b++)if(this.globalCameras[b].GetName()==a)return this.globalCameras[b];for(b=0;b<this.localCameras.length;b++)if(this.localCameras[b].GetName()==a)return this.localCameras[b];return null};c.prototype.TransitionFinished=function(a,b){var c=this.GetCamera(a);if(null!=c){if(0==b)return c.moveTransFinished;if(1==b)return c.zoomTransFinished}return!1};c.prototype.TransitionIsInProgress=function(a,
b){var c=this.GetCamera(a);if(null!=c)for(var d=0;d<c.transitions.length;d++)if("MOVE"==c.transitions[d].type&&0==b||"SCALE"==c.transitions[d].type&&1==b)return!0;return!1};f.cnds=new c;d.prototype.FollowObject=function(a,b,c){if(b&&(a=this.GetCamera(a),null!=a)){var d=b.getFirstPicked();a.global&&!b.global?alert("MagiCam:\n\nObject not global - global cameras must follow global objects."):(a.followedObjects.push(d),a.objectWeights.push(c))}};d.prototype.SetFollowLag=function(a,b){var c=this.GetCamera(a);
null!=c&&(c.followLag=1-b/100)};d.prototype.ZoomToContain=function(a,b,c,d){a=this.GetCamera(a);null!=a&&(0==b?(a.zoomToContain=!0,a.zoomMarginH=c,a.zoomMarginV=d):a.zoomToContain=!1)};d.prototype.EnableFollowing=function(a,b){var c=this.GetCamera(a);null!=c&&(c.following=0==b?!0:!1)};d.prototype.UnfollowObject=function(a,b){if(b){var c=this.GetCamera(a);if(null!=c)for(var d=b.getFirstPicked(),e=0;e<c.followedObjects.length;e++)if(c.followedObjects[e]==d){c.followedObjects.splice(e,1);break}}};d.prototype.CreateLocalCamera=
function(a,c,d,e,f){""==a?alert("Camera name must not be blank."):(this.localCameras.push(new b(a,c,d,e,!1)),this.localCameraCount++,1==f&&(this.activeCamera=this.localCameras[this.localCameras.length-1],this.runtime.running_layout.scale=this.activeCamera.scale))};d.prototype.CreateGlobalCamera=function(a,c,d,e,f){""==a?alert("Camera name must not be blank."):null==this.GetCamera(a)&&(this.globalCameras.push(new b(a,c,d,e,!0)),1==f&&(this.activeCamera=this.globalCameras[this.globalCameras.length-
1],this.runtime.running_layout.scrollToX(this.activeCamera.GetX()),this.runtime.running_layout.scrollToY(this.activeCamera.GetY()),this.runtime.running_layout.scale=this.activeCamera.scale))};d.prototype.SetActiveCamera=function(a){a=this.GetCamera(a);null!=a&&(this.activeCamera=a,this.runtime.running_layout.scrollToX(a.GetX()),this.runtime.running_layout.scrollToY(a.GetY()),this.runtime.running_layout.scale=a.scale)};d.prototype.SetScrollSmoothing=function(a){};d.prototype.SetXPosition=function(a,
b){var c=this.GetCamera(a);null!=c&&c.SetX(b)};d.prototype.SetYPosition=function(a,b){var c=this.GetCamera(a);null!=c&&c.SetY(b)};d.prototype.SetPosition=function(a,b,c){a=this.GetCamera(a);null!=a&&(a.SetX(b),a.SetY(c))};d.prototype.SetZoom=function(a,b){var c=this.GetCamera(a);null!=c&&(c.scale=b)};d.prototype.TransitionToPoint=function(b,c,d,e){b=this.GetCamera(b);if(null!=b){for(var f=0;f<b.transitions.length;f++)if("MOVE"==b.transitions[f].type){b.transitions.splice(f,1);break}b.transitions.push(new a("MOVE",
e,c,d,b.GetX(),b.GetY()));b.following=!1;b.zoomToContain=!1}};d.prototype.TransitionToZoom=function(b,c,d){b=this.GetCamera(b);if(null!=b){for(var e=0;e<b.transitions.length;e++)if("SCALE"==b.transitions[e].type){b.transitions.splice(e,1);break}b.transitions.push(new a("SCALE",d,c,b.scale,null,null));b.zoomToContain=!1}};f.acts=new d;e.prototype.MyExpression=function(a){};f.exps=new e})();cr.plugins_.Mouse=function(a){this.runtime=a};
(function(){function a(){}function b(){}function c(){}var d=cr.plugins_.Mouse.prototype;d.Type=function(a){this.plugin=a;this.runtime=a.runtime};d.Type.prototype.onCreate=function(){};d.Instance=function(a){this.type=a;this.runtime=a.runtime;this.buttonMap=Array(4);this.triggerDir=this.triggerType=this.triggerButton=this.mouseYcanvas=this.mouseXcanvas=0;this.handled=!1};var e=d.Instance.prototype;e.onCreate=function(){var a=this;if(!this.runtime.isDomFree){jQuery(document).mousemove(function(b){a.onMouseMove(b)});
jQuery(document).mousedown(function(b){a.onMouseDown(b)});jQuery(document).mouseup(function(b){a.onMouseUp(b)});jQuery(document).dblclick(function(b){a.onDoubleClick(b)});var b=function(b){a.onWheel(b)};document.addEventListener("mousewheel",b,!1);document.addEventListener("DOMMouseScroll",b,!1)}};var g={left:0,top:0};e.onMouseMove=function(a){var b=this.runtime.isDomFree?g:jQuery(this.runtime.canvas).offset();this.mouseXcanvas=a.pageX-b.left;this.mouseYcanvas=a.pageY-b.top};e.mouseInGame=function(){return 0<
this.runtime.fullscreen_mode?!0:0<=this.mouseXcanvas&&0<=this.mouseYcanvas&&this.mouseXcanvas<this.runtime.width&&this.mouseYcanvas<this.runtime.height};e.onMouseDown=function(a){this.mouseInGame()&&(this.runtime.had_a_click&&a.preventDefault(),this.buttonMap[a.which]=!0,this.runtime.trigger(cr.plugins_.Mouse.prototype.cnds.OnAnyClick,this),this.triggerButton=a.which-1,this.triggerType=0,this.runtime.trigger(cr.plugins_.Mouse.prototype.cnds.OnClick,this),this.runtime.trigger(cr.plugins_.Mouse.prototype.cnds.OnObjectClicked,
this))};e.onMouseUp=function(a){this.buttonMap[a.which]&&(this.runtime.had_a_click&&a.preventDefault(),this.runtime.had_a_click=!0,this.buttonMap[a.which]=!1,this.triggerButton=a.which-1,this.runtime.trigger(cr.plugins_.Mouse.prototype.cnds.OnRelease,this))};e.onDoubleClick=function(a){this.mouseInGame()&&(a.preventDefault(),this.triggerButton=a.which-1,this.triggerType=1,this.runtime.trigger(cr.plugins_.Mouse.prototype.cnds.OnClick,this),this.runtime.trigger(cr.plugins_.Mouse.prototype.cnds.OnObjectClicked,
this))};e.onWheel=function(a){this.triggerDir=0>(a.wheelDelta?a.wheelDelta:a.detail?-a.detail:0)?0:1;this.handled=!1;this.runtime.trigger(cr.plugins_.Mouse.prototype.cnds.OnWheel,this);this.handled&&a.preventDefault()};a.prototype.OnClick=function(a,b){return a===this.triggerButton&&b===this.triggerType};a.prototype.OnAnyClick=function(){return!0};a.prototype.IsButtonDown=function(a){return this.buttonMap[a+1]};a.prototype.OnRelease=function(a){return a===this.triggerButton};a.prototype.IsOverObject=
function(a){var b=this.runtime.getCurrentCondition();cr.is_undefined(b.extra.mouseOverInverted)&&(b.extra.mouseOverInverted=b.inverted,b.inverted=!1);return this.runtime.testAndSelectCanvasPointOverlap(a,this.mouseXcanvas,this.mouseYcanvas,b.extra.mouseOverInverted)};a.prototype.OnObjectClicked=function(a,b,c){return a!==this.triggerButton||b!==this.triggerType?!1:this.runtime.testAndSelectCanvasPointOverlap(c,this.mouseXcanvas,this.mouseYcanvas,!1)};a.prototype.OnWheel=function(a){this.handled=!0;
return a===this.triggerDir};d.cnds=new a;b.prototype.SetCursor=function(a){a="auto pointer text crosshair move help wait none".split(" ")[a];this.runtime.canvas&&this.runtime.canvas.style&&(this.runtime.canvas.style.cursor=a)};b.prototype.SetCursorSprite=function(a){if(!this.runtime.isDomFree&&!this.runtime.isMobile&&a&&(a=a.getFirstPicked())&&a.curFrame)a=a.curFrame,a="url("+a.getDataUri()+") "+Math.round(a.hotspotX*a.width)+" "+Math.round(a.hotspotY*a.height)+", auto",jQuery(this.runtime.canvas).css("cursor",
a)};d.acts=new b;c.prototype.X=function(a,b){var c,d,e,g,q;cr.is_undefined(b)?(c=this.runtime.getLayerByNumber(0),d=c.scale,e=c.zoomRate,g=c.parallaxX,q=c.angle,c.scale=this.runtime.running_layout.scale,c.zoomRate=1,c.parallaxX=1,c.angle=this.runtime.running_layout.angle,a.set_float(c.canvasToLayer(this.mouseXcanvas,this.mouseYcanvas,!0)),c.scale=d,c.zoomRate=e,c.parallaxX=g,c.angle=q):(c=cr.is_number(b)?this.runtime.getLayerByNumber(b):this.runtime.getLayerByName(b))?a.set_float(c.canvasToLayer(this.mouseXcanvas,
this.mouseYcanvas,!0)):a.set_float(0)};c.prototype.Y=function(a,b){var c,d,e,g,q;cr.is_undefined(b)?(c=this.runtime.getLayerByNumber(0),d=c.scale,e=c.zoomRate,g=c.parallaxY,q=c.angle,c.scale=this.runtime.running_layout.scale,c.zoomRate=1,c.parallaxY=1,c.angle=this.runtime.running_layout.angle,a.set_float(c.canvasToLayer(this.mouseXcanvas,this.mouseYcanvas,!1)),c.scale=d,c.zoomRate=e,c.parallaxY=g,c.angle=q):(c=cr.is_number(b)?this.runtime.getLayerByNumber(b):this.runtime.getLayerByName(b))?a.set_float(c.canvasToLayer(this.mouseXcanvas,
this.mouseYcanvas,!1)):a.set_float(0)};c.prototype.AbsoluteX=function(a){a.set_float(this.mouseXcanvas)};c.prototype.AbsoluteY=function(a){a.set_float(this.mouseYcanvas)};d.exps=new c})();cr.plugins_.Sprite=function(a){this.runtime=a};
(function(){function a(){if(0===this.datauri.length){var a=document.createElement("canvas");a.width=this.width;a.height=this.height;var b=a.getContext("2d");this.spritesheeted?b.drawImage(this.texture_img,this.offx,this.offy,this.width,this.height,0,0,this.width,this.height):b.drawImage(this.texture_img,0,0,this.width,this.height);this.datauri=a.toDataURL("image/png")}return this.datauri}function b(){}function c(a,b,c){var d;d=q.length?q.pop():[0,0];d[0]=b.uid;d[1]=c.uid;a.push(d)}function d(a,b,
c){b=b.uid;var d=c.uid,e=0,f,g;c=0;for(f=a.length;c<f;c++)g=a[c],g[0]===b&&g[1]===d||g[0]===d&&g[1]===b||(a[e][0]=a[c][0],a[e][1]=a[c][1],e++);for(c=e;c<f;c++)b=a[c],b[0]=0,b[1]=0,q.push(b);a.length=e}function e(a,b,c){b=b.uid;c=c.uid;var d,e,f;d=0;for(e=a.length;d<e;d++)if(f=a[d],f[0]===b&&f[1]===c||f[0]===c&&f[1]===b)return!0;return!1}function g(a,b,c){if(!a)return!1;var d=0!==b||0!==c,e,f,g=!1,h,m=this.runtime.getCurrentCondition(),k=m.type,m=m.inverted,l=a.getCurrentSol();h=this.runtime.getCurrentEventStack().current_event.orblock;
l=l.select_all?l.type.instances:h?l.else_instances:l.instances;p=a;s=k!==a&&!m;d&&(e=this.x,f=this.y,this.x+=b,this.y+=c,this.set_bbox_changed());b=0;for(c=l.length;b<c;b++)if(h=l[b],this.runtime.testOverlap(this,h)){g=!0;if(m)break;k!==a&&r.add(h)}d&&(this.x=e,this.y=f,this.set_bbox_changed());return g}function f(){}function l(){}var k=cr.plugins_.Sprite.prototype;k.Type=function(a){this.plugin=a;this.runtime=a.runtime};var h=k.Type.prototype;h.onCreate=function(){if(!this.is_family){var b,c,d,e,
f,g,h,m,k;this.all_frames=[];this.has_loaded_textures=!1;b=0;for(c=this.animations.length;b<c;b++){f=this.animations[b];h={};h.name=f[0];h.speed=f[1];h.loop=f[2];h.repeatcount=f[3];h.repeatto=f[4];h.pingpong=f[5];h.sid=f[6];h.frames=[];d=0;for(e=f[7].length;d<e;d++)g=f[7][d],m={},m.texture_file=g[0],m.texture_filesize=g[1],m.offx=g[2],m.offy=g[3],m.width=g[4],m.height=g[5],m.duration=g[6],m.hotspotX=g[7],m.hotspotY=g[8],m.image_points=g[9],m.poly_pts=g[10],m.pixelformat=g[11],m.spritesheeted=0!==
m.width,m.datauri="",m.getDataUri=a,k={left:0,top:0,right:1,bottom:1},m.sheetTex=k,m.webGL_texture=null,(k=this.runtime.findWaitingTexture(g[0]))?m.texture_img=k:(m.texture_img=new Image,m.texture_img.src=g[0],m.texture_img.cr_src=g[0],m.texture_img.cr_filesize=g[1],m.texture_img.c2webGL_texture=null,this.runtime.wait_for_textures.push(m.texture_img)),cr.seal(m),h.frames.push(m),this.all_frames.push(m);cr.seal(h);this.animations[b]=h}}};h.updateAllCurrentTexture=function(){var a,b,c;a=0;for(b=this.instances.length;a<
b;a++)c=this.instances[a],c.curWebGLTexture=c.curFrame.webGL_texture};h.onLostWebGLContext=function(){if(!this.is_family){var a,b,c;a=0;for(b=this.all_frames.length;a<b;++a)c=this.all_frames[a],c.texture_img.c2webGL_texture=null,c.webGL_texture=null}};h.onRestoreWebGLContext=function(){if(!this.is_family&&this.instances.length){var a,b,c;a=0;for(b=this.all_frames.length;a<b;++a)c=this.all_frames[a],c.webGL_texture=this.runtime.glwrap.loadTexture(c.texture_img,!1,this.runtime.linearSampling,c.pixelformat);
this.updateAllCurrentTexture()}};h.loadTextures=function(){if(!this.is_family&&!this.has_loaded_textures&&this.runtime.glwrap){var a,b,c;a=0;for(b=this.all_frames.length;a<b;++a)c=this.all_frames[a],c.webGL_texture=this.runtime.glwrap.loadTexture(c.texture_img,!1,this.runtime.linearSampling,c.pixelformat);this.has_loaded_textures=!0}};h.unloadTextures=function(){if(!this.is_family&&!this.instances.length&&this.has_loaded_textures){var a,b,c;a=0;for(b=this.all_frames.length;a<b;++a)c=this.all_frames[a],
this.runtime.glwrap.deleteTexture(c.webGL_texture);this.has_loaded_textures=!1}};var m=[];h.preloadCanvas2D=function(a){var b,c,d;b=m.length=0;for(c=this.all_frames.length;b<c;++b)d=this.all_frames[b].texture_img,-1===m.indexOf(d)&&(a.drawImage(d,0,0),m.push(d))};k.Instance=function(a){this.type=a;this.runtime=a.runtime;a=this.type.animations[0].frames[0].poly_pts;this.recycled?this.collision_poly.set_pts(a):this.collision_poly=new cr.CollisionPoly(a)};var n=k.Instance.prototype;n.onCreate=function(){this.visible=
0===this.properties[0];this.inAnimTrigger=this.isTicking=!1;this.collisionsEnabled=0!==this.properties[3];!(1===this.type.animations.length&&1===this.type.animations[0].frames.length)&&0!==this.type.animations[0].speed&&(this.runtime.tickMe(this),this.isTicking=!0);this.cur_animation=this.getAnimationByName(this.properties[1])||this.type.animations[0];this.cur_frame=this.properties[2];0>this.cur_frame&&(this.cur_frame=0);this.cur_frame>=this.cur_animation.frames.length&&(this.cur_frame=this.cur_animation.frames.length-
1);var a=this.cur_animation.frames[this.cur_frame];this.collision_poly.set_pts(a.poly_pts);this.hotspotX=a.hotspotX;this.hotspotY=a.hotspotY;this.cur_anim_speed=this.cur_animation.speed;this.recycled?this.animTimer.reset():this.animTimer=new cr.KahanAdder;this.frameStart=this.getNowTime();this.animPlaying=!0;this.animRepeats=0;this.animForwards=!0;this.changeAnimName=this.animTriggerName="";this.changeAnimFrom=0;this.changeAnimFrame=-1;this.type.loadTextures();var b,c,d,e,f,g,h,a=0;for(b=this.type.animations.length;a<
b;a++){e=this.type.animations[a];c=0;for(d=e.frames.length;c<d;c++)f=e.frames[c],0===f.width&&(f.width=f.texture_img.width,f.height=f.texture_img.height),f.spritesheeted&&(h=f.texture_img,g=f.sheetTex,g.left=f.offx/h.width,g.top=f.offy/h.height,g.right=(f.offx+f.width)/h.width,g.bottom=(f.offy+f.height)/h.height,0===f.offx&&(0===f.offy&&f.width===h.width&&f.height===h.height)&&(f.spritesheeted=!1))}this.curFrame=this.cur_animation.frames[this.cur_frame];this.curWebGLTexture=this.curFrame.webGL_texture};
n.saveToJSON=function(){var a={a:this.cur_animation.sid,f:this.cur_frame,cas:this.cur_anim_speed,fs:this.frameStart,ar:this.animRepeats,at:this.animTimer.sum};this.animPlaying||(a.ap=this.animPlaying);this.animForwards||(a.af=this.animForwards);return a};n.loadFromJSON=function(a){var b=this.getAnimationBySid(a.a);b&&(this.cur_animation=b);this.cur_frame=a.f;0>this.cur_frame&&(this.cur_frame=0);this.cur_frame>=this.cur_animation.frames.length&&(this.cur_frame=this.cur_animation.frames.length-1);this.cur_anim_speed=
a.cas;this.frameStart=a.fs;this.animRepeats=a.ar;this.animTimer.reset();this.animTimer.sum=a.at;this.animPlaying=a.hasOwnProperty("ap")?a.ap:!0;this.animForwards=a.hasOwnProperty("af")?a.af:!0;this.curFrame=this.cur_animation.frames[this.cur_frame];this.curWebGLTexture=this.curFrame.webGL_texture;this.collision_poly.set_pts(this.curFrame.poly_pts);this.hotspotX=this.curFrame.hotspotX;this.hotspotY=this.curFrame.hotspotY};n.animationFinish=function(a){this.cur_frame=a?0:this.cur_animation.frames.length-
1;this.animPlaying=!1;this.animTriggerName=this.cur_animation.name;this.inAnimTrigger=!0;this.runtime.trigger(cr.plugins_.Sprite.prototype.cnds.OnAnyAnimFinished,this);this.runtime.trigger(cr.plugins_.Sprite.prototype.cnds.OnAnimFinished,this);this.inAnimTrigger=!1;this.animRepeats=0};n.getNowTime=function(){return this.animTimer.sum};n.tick=function(){this.animTimer.add(this.runtime.getDt(this));this.changeAnimName.length&&this.doChangeAnim();0<=this.changeAnimFrame&&this.doChangeAnimFrame();var a=
this.getNowTime(),b=this.cur_animation,c=b.frames[this.cur_frame],d=c.duration/this.cur_anim_speed;this.animPlaying&&a>=this.frameStart+d&&(this.animForwards?this.cur_frame++:this.cur_frame--,this.frameStart+=d,this.cur_frame>=b.frames.length&&(b.pingpong?(this.animForwards=!1,this.cur_frame=b.frames.length-2):b.loop?this.cur_frame=b.repeatto:(this.animRepeats++,this.animRepeats>=b.repeatcount?this.animationFinish(!1):this.cur_frame=b.repeatto)),0>this.cur_frame&&(b.pingpong?(this.cur_frame=1,this.animForwards=
!0,b.loop||(this.animRepeats++,this.animRepeats>=b.repeatcount&&this.animationFinish(!0))):b.loop?this.cur_frame=b.repeatto:(this.animRepeats++,this.animRepeats>=b.repeatcount?this.animationFinish(!0):this.cur_frame=b.repeatto)),0>this.cur_frame?this.cur_frame=0:this.cur_frame>=b.frames.length&&(this.cur_frame=b.frames.length-1),a>this.frameStart+b.frames[this.cur_frame].duration/this.cur_anim_speed&&(this.frameStart=a),a=b.frames[this.cur_frame],this.OnFrameChanged(c,a),this.runtime.redraw=!0)};
n.getAnimationByName=function(a){var b,c,d;b=0;for(c=this.type.animations.length;b<c;b++)if(d=this.type.animations[b],cr.equals_nocase(d.name,a))return d;return null};n.getAnimationBySid=function(a){var b,c,d;b=0;for(c=this.type.animations.length;b<c;b++)if(d=this.type.animations[b],d.sid===a)return d;return null};n.doChangeAnim=function(){var a=this.cur_animation.frames[this.cur_frame],b=this.getAnimationByName(this.changeAnimName);this.changeAnimName="";if(b&&(!cr.equals_nocase(b.name,this.cur_animation.name)||
!this.animPlaying))this.cur_animation=b,this.cur_anim_speed=b.speed,0>this.cur_frame&&(this.cur_frame=0),this.cur_frame>=this.cur_animation.frames.length&&(this.cur_frame=this.cur_animation.frames.length-1),1===this.changeAnimFrom&&(this.cur_frame=0),this.animPlaying=!0,this.frameStart=this.getNowTime(),this.animForwards=!0,this.OnFrameChanged(a,this.cur_animation.frames[this.cur_frame]),this.runtime.redraw=!0};n.doChangeAnimFrame=function(){var a=this.cur_animation.frames[this.cur_frame],b=this.cur_frame;
this.cur_frame=cr.floor(this.changeAnimFrame);0>this.cur_frame&&(this.cur_frame=0);this.cur_frame>=this.cur_animation.frames.length&&(this.cur_frame=this.cur_animation.frames.length-1);b!==this.cur_frame&&(this.OnFrameChanged(a,this.cur_animation.frames[this.cur_frame]),this.frameStart=this.getNowTime(),this.runtime.redraw=!0);this.changeAnimFrame=-1};n.OnFrameChanged=function(a,b){var c=a.width,d=a.height,e=b.width,f=b.height;c!=e&&(this.width*=e/c);d!=f&&(this.height*=f/d);this.hotspotX=b.hotspotX;
this.hotspotY=b.hotspotY;this.collision_poly.set_pts(b.poly_pts);this.set_bbox_changed();this.curFrame=b;this.curWebGLTexture=b.webGL_texture;c=0;for(d=this.behavior_insts.length;c<d;c++)if(e=this.behavior_insts[c],e.onSpriteFrameChanged)e.onSpriteFrameChanged(a,b);this.runtime.trigger(cr.plugins_.Sprite.prototype.cnds.OnFrameChanged,this)};n.draw=function(a){a.globalAlpha=this.opacity;var b=this.curFrame,c=b.spritesheeted,d=b.texture_img,e=this.x,f=this.y,g=this.width,h=this.height;if(0===this.angle&&
0<=g&&0<=h)e-=this.hotspotX*g,f-=this.hotspotY*h,this.runtime.pixel_rounding&&(e=e+0.5|0,f=f+0.5|0),c?a.drawImage(d,b.offx,b.offy,b.width,b.height,e,f,g,h):a.drawImage(d,e,f,g,h);else{this.runtime.pixel_rounding&&(e=e+0.5|0,f=f+0.5|0);a.save();var m=0<g?1:-1,k=0<h?1:-1;a.translate(e,f);(1!==m||1!==k)&&a.scale(m,k);a.rotate(this.angle*m*k);e=0-this.hotspotX*cr.abs(g);f=0-this.hotspotY*cr.abs(h);c?a.drawImage(d,b.offx,b.offy,b.width,b.height,e,f,cr.abs(g),cr.abs(h)):a.drawImage(d,e,f,cr.abs(g),cr.abs(h));
a.restore()}};n.drawGL=function(a){a.setTexture(this.curWebGLTexture);a.setOpacity(this.opacity);var b=this.curFrame,c=this.bquad;if(this.runtime.pixel_rounding){var d=(this.x+0.5|0)-this.x,e=(this.y+0.5|0)-this.y;b.spritesheeted?a.quadTex(c.tlx+d,c.tly+e,c.trx+d,c.try_+e,c.brx+d,c.bry+e,c.blx+d,c.bly+e,b.sheetTex):a.quad(c.tlx+d,c.tly+e,c.trx+d,c.try_+e,c.brx+d,c.bry+e,c.blx+d,c.bly+e)}else b.spritesheeted?a.quadTex(c.tlx,c.tly,c.trx,c.try_,c.brx,c.bry,c.blx,c.bly,b.sheetTex):a.quad(c.tlx,c.tly,
c.trx,c.try_,c.brx,c.bry,c.blx,c.bly)};n.getImagePointIndexByName=function(a){var b=this.curFrame,c,d;c=0;for(d=b.image_points.length;c<d;c++)if(cr.equals_nocase(a,b.image_points[c][0]))return c;return-1};n.getImagePoint=function(a,b){var c=this.curFrame,d=c.image_points,e;e=cr.is_string(a)?this.getImagePointIndexByName(a):a-1;e=cr.floor(e);if(0>e||e>=d.length)return b?this.x:this.y;var f=(d[e][1]-c.hotspotX)*this.width,d=d[e][2],d=(d-c.hotspotY)*this.height,c=Math.cos(this.angle);e=Math.sin(this.angle);
var g=f*c-d*e,d=d*c+f*e,f=g+this.x,d=d+this.y;return b?f:d};var q=[];b.prototype.OnCollision=function(a){if(!a)return!1;var b=this.runtime,f=b.getCurrentCondition(),g=f.type;f.extra.collmemory||(f.extra.collmemory=[],b.addDestroyCallback(function(a){return function(b){var c=0,d,e,f=b.uid;b=0;for(d=a.length;b<d;b++)e=a[b],e[0]!==f&&e[1]!==f&&(a[c][0]=a[b][0],a[c][1]=a[b][1],c++);for(b=c;b<d;b++)e=a[b],e[0]=0,e[1]=0,q.push(e);a.length=c}}(f.extra.collmemory)));var h=g.getCurrentSol(),m=a.getCurrentSol(),
h=h.getObjects(),m=m.getObjects(),k,p,l,n,r,s,B=b.getCurrentEventStack().current_event;for(k=0;k<h.length;k++){p=h[k];for(l=0;l<m.length;l++)n=m[l],b.testOverlap(p,n)||b.checkRegisteredCollision(p,n)?e(f.extra.collmemory,p,n)||(c(f.extra.collmemory,p,n),b.pushCopySol(B.solModifiers),r=g.getCurrentSol(),s=a.getCurrentSol(),r.select_all=!1,s.select_all=!1,g===a?(r.instances.length=2,r.instances[0]=p,r.instances[1]=n,g.applySolToContainer()):(r.instances.length=1,s.instances.length=1,r.instances[0]=
p,s.instances[0]=n,g.applySolToContainer(),a.applySolToContainer()),B.retrigger(),b.popSol(B.solModifiers)):d(f.extra.collmemory,p,n)}return!1};var p=null,r=new cr.ObjectSet,s=!1;h.finish=function(a){if(s){if(a){var b=this.runtime.getCurrentEventStack().current_event.orblock;a=p.getCurrentSol();var c=r.valuesRef(),d,e;if(a.select_all){a.select_all=!1;a.instances.length=c.length;d=0;for(e=c.length;d<e;d++)a.instances[d]=c[d];if(b){d=a.else_instances.length=0;for(e=p.instances.length;d<e;d++)b=p.instances[d],
r.contains(b)||a.else_instances.push(b)}}else{var f=a.instances.length;a.instances.length=f+c.length;d=0;for(e=c.length;d<e;d++)a.instances[f+d]=c[d],b&&cr.arrayFindRemove(a.else_instances,c[d])}p.applySolToContainer()}r.clear();s=!1}};b.prototype.IsOverlapping=function(a){return g.call(this,a,0,0)};b.prototype.IsOverlappingOffset=function(a,b,c){return g.call(this,a,b,c)};b.prototype.IsAnimPlaying=function(a){return this.changeAnimName.length?cr.equals_nocase(this.changeAnimName,a):cr.equals_nocase(this.cur_animation.name,
a)};b.prototype.CompareFrame=function(a,b){return cr.do_cmp(this.cur_frame,a,b)};b.prototype.OnAnimFinished=function(a){return cr.equals_nocase(this.animTriggerName,a)};b.prototype.OnAnyAnimFinished=function(){return!0};b.prototype.OnFrameChanged=function(){return!0};b.prototype.IsMirrored=function(){return 0>this.width};b.prototype.IsFlipped=function(){return 0>this.height};b.prototype.OnURLLoaded=function(){return!0};b.prototype.IsCollisionEnabled=function(){return this.collisionsEnabled};k.cnds=
new b;f.prototype.Spawn=function(a,b,c){if(a&&b&&(b=this.runtime.createInstance(a,b,this.getImagePoint(c,!0),this.getImagePoint(c,!1)))){"undefined"!==typeof b.angle&&(b.angle=this.angle,b.set_bbox_changed());this.runtime.isInOnDestroy++;var d,e,f;this.runtime.trigger(Object.getPrototypeOf(a.plugin).cnds.OnCreated,b);if(b.is_contained){d=0;for(e=b.siblings.length;d<e;d++)f=b.siblings[d],this.runtime.trigger(Object.getPrototypeOf(f.type.plugin).cnds.OnCreated,f)}this.runtime.isInOnDestroy--;d=this.runtime.getCurrentAction();
c=!1;if(cr.is_undefined(d.extra.Spawn_LastExec)||d.extra.Spawn_LastExec<this.runtime.execcount)c=!0,d.extra.Spawn_LastExec=this.runtime.execcount;if(a!=this.type&&(a=a.getCurrentSol(),a.select_all=!1,c?(a.instances.length=1,a.instances[0]=b):a.instances.push(b),b.is_contained)){d=0;for(e=b.siblings.length;d<e;d++)f=b.siblings[d],a=f.type.getCurrentSol(),a.select_all=!1,c?(a.instances.length=1,a.instances[0]=f):a.instances.push(f)}}};f.prototype.SetEffect=function(a){this.compositeOp=cr.effectToCompositeOp(a);
cr.setGLBlend(this,a,this.runtime.gl);this.runtime.redraw=!0};f.prototype.StopAnim=function(){this.animPlaying=!1};f.prototype.StartAnim=function(a){this.animPlaying=!0;this.frameStart=this.getNowTime();1===a&&0!==this.cur_frame&&(this.changeAnimFrame=0,this.inAnimTrigger||this.doChangeAnimFrame());this.isTicking||(this.runtime.tickMe(this),this.isTicking=!0)};f.prototype.SetAnim=function(a,b){this.changeAnimName=a;this.changeAnimFrom=b;this.isTicking||(this.runtime.tickMe(this),this.isTicking=!0);
this.inAnimTrigger||this.doChangeAnim()};f.prototype.SetAnimFrame=function(a){this.changeAnimFrame=a;this.isTicking||(this.runtime.tickMe(this),this.isTicking=!0);this.inAnimTrigger||this.doChangeAnimFrame()};f.prototype.SetAnimSpeed=function(a){this.cur_anim_speed=cr.abs(a);this.animForwards=0<=a;this.isTicking||(this.runtime.tickMe(this),this.isTicking=!0)};f.prototype.SetMirrored=function(a){a=cr.abs(this.width)*(0===a?-1:1);this.width!==a&&(this.width=a,this.set_bbox_changed())};f.prototype.SetFlipped=
function(a){a=cr.abs(this.height)*(0===a?-1:1);this.height!==a&&(this.height=a,this.set_bbox_changed())};f.prototype.SetScale=function(a){var b=this.curFrame,c=b.width*a*(0>this.width?-1:1);a=b.height*a*(0>this.height?-1:1);if(this.width!==c||this.height!==a)this.width=c,this.height=a,this.set_bbox_changed()};f.prototype.LoadURL=function(a,b){var c=new Image,d=this,e=this.curFrame;c.onload=function(){e.texture_img.src===c.src?d.runtime.glwrap&&d.curFrame===e&&(d.curWebGLTexture=e.webGL_texture):(e.texture_img=
c,e.offx=0,e.offy=0,e.width=c.width,e.height=c.height,e.spritesheeted=!1,e.datauri="",d.runtime.glwrap&&(e.webGL_texture&&d.runtime.glwrap.deleteTexture(e.webGL_texture),e.webGL_texture=d.runtime.glwrap.loadTexture(c,!1,d.runtime.linearSampling),d.curFrame===e&&(d.curWebGLTexture=e.webGL_texture),d.type.updateAllCurrentTexture()),0===b&&(d.width=c.width,d.height=c.height,d.set_bbox_changed()));d.runtime.redraw=!0;d.runtime.trigger(cr.plugins_.Sprite.prototype.cnds.OnURLLoaded,d)};"data:"!==a.substr(0,
5)&&(c.crossOrigin="anonymous");c.src=a};f.prototype.SetCollisions=function(a){this.collisionsEnabled=0!==a};k.acts=new f;l.prototype.AnimationFrame=function(a){a.set_int(this.cur_frame)};l.prototype.AnimationFrameCount=function(a){a.set_int(this.cur_animation.frames.length)};l.prototype.AnimationName=function(a){a.set_string(this.cur_animation.name)};l.prototype.AnimationSpeed=function(a){a.set_float(this.cur_anim_speed)};l.prototype.ImagePointX=function(a,b){a.set_float(this.getImagePoint(b,!0))};
l.prototype.ImagePointY=function(a,b){a.set_float(this.getImagePoint(b,!1))};l.prototype.ImagePointCount=function(a){a.set_int(this.curFrame.image_points.length)};l.prototype.ImageWidth=function(a){a.set_float(this.curFrame.width)};l.prototype.ImageHeight=function(a){a.set_float(this.curFrame.height)};k.exps=new l})();cr.plugins_.Text=function(a){this.runtime=a};
(function(){function a(){return h.length?h.pop():{}}function b(a){var b,c;b=0;for(c=a.length;b<c;b++)h.push(a[b]);a.length=0}function c(){}function d(){}function e(){}var g=cr.plugins_.Text.prototype;g.onCreate=function(){g.acts.SetWidth=function(a){this.width!==a&&(this.width=a,this.text_changed=!0,this.set_bbox_changed())}};g.Type=function(a){this.plugin=a;this.runtime=a.runtime};var f=g.Type.prototype;f.onCreate=function(){};f.onLostWebGLContext=function(){if(!this.is_family){var a,b,c;a=0;for(b=
this.instances.length;a<b;a++)c=this.instances[a],c.mycanvas=null,c.myctx=null,c.mytex=null}};g.Instance=function(a){this.type=a;this.runtime=a.runtime;this.recycled?this.lines.length=0:this.lines=[];this.text_changed=!0};var f=g.Instance.prototype,l={};f.onCreate=function(){this.text=this.properties[0];this.visible=0===this.properties[1];this.font=this.properties[2];this.color=this.properties[3];this.halign=this.properties[4];this.valign=this.properties[5];this.wrapbyword=0===this.properties[7];
this.lastwrapwidth=this.lastwidth=this.width;this.lastheight=this.height;this.line_height_offset=this.properties[8];this.fontstyle=this.facename="";this.textHeight=this.textWidth=this.ptSize=0;this.parseFont();this.mytex=this.myctx=this.mycanvas=null;this.need_text_redraw=!1;this.last_render_tick=this.runtime.tickcount;this.recycled?this.rcTex.set(0,0,1,1):this.rcTex=new cr.rect(0,0,1,1);this.runtime.glwrap&&this.runtime.tickMe(this)};f.parseFont=function(){var a=this.font.split(" "),b;for(b=0;b<
a.length;b++)if("pt"===a[b].substr(a[b].length-2,2)){this.ptSize=parseInt(a[b].substr(0,a[b].length-2));this.pxHeight=Math.ceil(96*(this.ptSize/72))+4;0<b&&(this.fontstyle=a[b-1]);this.facename=a[b+1];for(b+=2;b<a.length;b++)this.facename+=" "+a[b];break}};f.saveToJSON=function(){return{t:this.text,f:this.font,c:this.color,ha:this.halign,va:this.valign,wr:this.wrapbyword,lho:this.line_height_offset,fn:this.facename,fs:this.fontstyle,ps:this.ptSize,pxh:this.pxHeight,tw:this.textWidth,th:this.textHeight,
lrt:this.last_render_tick}};f.loadFromJSON=function(a){this.text=a.t;this.font=a.f;this.color=a.c;this.halign=a.ha;this.valign=a.va;this.wrapbyword=a.wr;this.line_height_offset=a.lho;this.facename=a.fn;this.fontstyle=a.fs;this.ptSize=a.ps;this.pxHeight=a.pxh;this.textWidth=a.tw;this.textHeight=a.th;this.last_render_tick=a.lrt;this.text_changed=!0;this.lastwrapwidth=this.lastwidth=this.width;this.lastheight=this.height};f.tick=function(){if(this.runtime.glwrap&&this.mytex&&300<=this.runtime.tickcount-
this.last_render_tick){var a=this.layer;this.update_bbox();var b=this.bbox;if(b.right<a.viewLeft||b.bottom<a.viewTop||b.left>a.viewRight||b.top>a.viewBottom)this.runtime.glwrap.deleteTexture(this.mytex),this.mycanvas=this.myctx=this.mytex=null}};f.onDestroy=function(){this.mycanvas=this.myctx=null;this.runtime.glwrap&&this.mytex&&this.runtime.glwrap.deleteTexture(this.mytex);this.mytex=null};f.updateFont=function(){this.font=this.fontstyle+" "+this.ptSize.toString()+"pt "+this.facename;this.text_changed=
!0;this.runtime.redraw=!0};f.draw=function(a,b){a.font=this.font;a.textBaseline="top";a.fillStyle=this.color;a.globalAlpha=b?1:this.opacity;var c=1;b&&(c=this.layer.getScale(),a.save(),a.scale(c,c));if(this.text_changed||this.width!==this.lastwrapwidth)this.type.plugin.WordWrap(this.text,this.lines,a,this.width,this.wrapbyword),this.text_changed=!1,this.lastwrapwidth=this.width;this.update_bbox();var c=b?0:this.bquad.tlx,d=b?0:this.bquad.tly;this.runtime.pixel_rounding&&(c=c+0.5|0,d=d+0.5|0);0!==
this.angle&&!b&&(a.save(),a.translate(c,d),a.rotate(this.angle),d=c=0);var e=d+this.height,f=this.pxHeight,f=f+this.line_height_offset*this.runtime.devicePixelRatio,g,h;1===this.valign?d+=Math.max(this.height/2-this.lines.length*f/2,0):2===this.valign&&(d+=Math.max(this.height-this.lines.length*f-2,0));for(h=0;h<this.lines.length&&!(g=c,1===this.halign?g=c+(this.width-this.lines[h].width)/2:2===this.halign&&(g=c+(this.width-this.lines[h].width)),a.fillText(this.lines[h].text,g,d),d+=f,d>=e-f);h++);
(0!==this.angle||b)&&a.restore();this.last_render_tick=this.runtime.tickcount};f.drawGL=function(a){if(!(1>this.width||1>this.height)){var b=this.text_changed||this.need_text_redraw;this.need_text_redraw=!1;var c=this.layer.getScale(),d=this.layer.getAngle(),e=this.rcTex,f=c*this.width,g=c*this.height,h=Math.ceil(f),k=Math.ceil(g),l=this.runtime.width/2,C=this.runtime.height/2;this.myctx||(this.mycanvas=document.createElement("canvas"),this.mycanvas.width=h,this.mycanvas.height=k,this.lastwidth=h,
this.lastheight=k,b=!0,this.myctx=this.mycanvas.getContext("2d"));if(h!==this.lastwidth||k!==this.lastheight)this.mycanvas.width=h,this.mycanvas.height=k,this.mytex&&(a.deleteTexture(this.mytex),this.mytex=null),b=!0;b&&(this.myctx.clearRect(0,0,h,k),this.draw(this.myctx,!0),this.mytex||(this.mytex=a.createEmptyTexture(h,k,this.runtime.linearSampling,this.runtime.isMobile)),a.videoToTexture(this.mycanvas,this.mytex,this.runtime.isMobile));this.lastwidth=h;this.lastheight=k;a.setTexture(this.mytex);
a.setOpacity(this.opacity);a.resetModelView();a.translate(-l,-C);a.updateModelView();var z=this.bquad,b=this.layer.layerToCanvas(z.tlx,z.tly,!0),l=this.layer.layerToCanvas(z.tlx,z.tly,!1),C=this.layer.layerToCanvas(z.trx,z.try_,!0),x=this.layer.layerToCanvas(z.trx,z.try_,!1),A=this.layer.layerToCanvas(z.brx,z.bry,!0),D=this.layer.layerToCanvas(z.brx,z.bry,!1),G=this.layer.layerToCanvas(z.blx,z.bly,!0),z=this.layer.layerToCanvas(z.blx,z.bly,!1);if(this.runtime.pixel_rounding||0===this.angle&&0===d)var F=
(b+0.5|0)-b,u=(l+0.5|0)-l,b=b+F,l=l+u,C=C+F,x=x+u,A=A+F,D=D+u,G=G+F,z=z+u;0===this.angle&&0===d?(C=b+h,x=l,A=C,D=l+k,G=b,z=D,e.right=1,e.bottom=1):(e.right=f/h,e.bottom=g/k);a.quadTex(b,l,C,x,A,D,G,z,e);a.resetModelView();a.scale(c,c);a.rotateZ(-this.layer.getAngle());a.translate((this.layer.viewLeft+this.layer.viewRight)/-2,(this.layer.viewTop+this.layer.viewBottom)/-2);a.updateModelView();this.last_render_tick=this.runtime.tickcount}};var k=[];g.TokeniseWords=function(a){k.length=0;for(var b="",
c,d=0;d<a.length;)if(c=a.charAt(d),"\n"===c)b.length&&(k.push(b),b=""),k.push("\n"),++d;else if(" "===c||"\t"===c||"-"===c){do b+=a.charAt(d),d++;while(d<a.length&&(" "===a.charAt(d)||"\t"===a.charAt(d)));k.push(b);b=""}else d<a.length&&(b+=c,d++);b.length&&k.push(b)};var h=[];g.WordWrap=function(c,d,e,f,g){if(!c||!c.length)b(d);else if(2>=f)b(d);else{if(100>=c.length&&-1===c.indexOf("\n")){var h=e.measureText(c).width;if(h<=f){b(d);d.push(a());d[0].text=c;d[0].width=h;return}}this.WrapText(c,d,e,
f,g)}};g.WrapText=function(b,c,d,e,f){f&&(this.TokeniseWords(b),b=k);var g="",l,v,w,y=0;for(w=0;w<b.length;w++)"\n"===b[w]?(y>=c.length&&c.push(a()),v=c[y],v.text=g,v.width=d.measureText(g).width,y++,g=""):(l=g,g+=b[w],v=d.measureText(g).width,v>=e&&(y>=c.length&&c.push(a()),v=c[y],v.text=l,v.width=d.measureText(l).width,y++,g=b[w],!f&&" "===g&&(g="")));g.length&&(y>=c.length&&c.push(a()),v=c[y],v.text=g,v.width=d.measureText(g).width,y++);for(w=y;w<c.length;w++)h.push(c[w]);c.length=y};c.prototype.CompareText=
function(a,b){return b?this.text==a:cr.equals_nocase(this.text,a)};g.cnds=new c;d.prototype.SetText=function(a){cr.is_number(a)&&1E9>a&&(a=Math.round(1E10*a)/1E10);a=a.toString();this.text!==a&&(this.text=a,this.text_changed=!0,this.runtime.redraw=!0)};d.prototype.AppendText=function(a){cr.is_number(a)&&(a=Math.round(1E10*a)/1E10);if(a=a.toString())this.text+=a,this.text_changed=!0,this.runtime.redraw=!0};d.prototype.SetFontFace=function(a,b){var c="";switch(b){case 1:c="bold";break;case 2:c="italic";
break;case 3:c="bold italic"}a===this.facename&&c===this.fontstyle||(this.facename=a,this.fontstyle=c,this.updateFont())};d.prototype.SetFontSize=function(a){this.ptSize!==a&&(this.ptSize=a,this.pxHeight=Math.ceil(96*(this.ptSize/72))+4,this.updateFont())};d.prototype.SetFontColor=function(a){a="rgb("+cr.GetRValue(a).toString()+","+cr.GetGValue(a).toString()+","+cr.GetBValue(a).toString()+")";a!==this.color&&(this.color=a,this.need_text_redraw=!0,this.runtime.redraw=!0)};d.prototype.SetWebFont=function(a,
b){if(this.runtime.isDomFree)cr.logexport("[Construct 2] Text plugin: 'Set web font' not supported on this platform - the action has been ignored");else{var c=this,d=function(){c.runtime.redraw=!0;c.text_changed=!0};if(l.hasOwnProperty(b)){var e="'"+a+"'";if(this.facename!==e){this.facename=e;this.updateFont();for(e=1;10>e;e++)setTimeout(d,100*e),setTimeout(d,1E3*e)}}else{e=document.createElement("link");e.href=b;e.rel="stylesheet";e.type="text/css";e.onload=d;document.getElementsByTagName("head")[0].appendChild(e);
l[b]=!0;this.facename="'"+a+"'";this.updateFont();for(e=1;10>e;e++)setTimeout(d,100*e),setTimeout(d,1E3*e)}}};d.prototype.SetEffect=function(a){this.compositeOp=cr.effectToCompositeOp(a);cr.setGLBlend(this,a,this.runtime.gl);this.runtime.redraw=!0};g.acts=new d;e.prototype.Text=function(a){a.set_string(this.text)};e.prototype.FaceName=function(a){a.set_string(this.facename)};e.prototype.FaceSize=function(a){a.set_int(this.ptSize)};e.prototype.TextWidth=function(a){var b=0,c,d,e;c=0;for(d=this.lines.length;c<
d;c++)e=this.lines[c].width,b<e&&(b=e);a.set_int(b)};e.prototype.TextHeight=function(a){a.set_int(this.lines.length*this.pxHeight)};g.exps=new e})();cr.plugins_.TiledBg=function(a){this.runtime=a};
(function(){function a(){}function b(){}var c=cr.plugins_.TiledBg.prototype;c.Type=function(a){this.plugin=a;this.runtime=a.runtime};var d=c.Type.prototype;d.onCreate=function(){this.is_family||(this.texture_img=new Image,this.texture_img.src=this.texture_file,this.texture_img.cr_filesize=this.texture_filesize,this.runtime.wait_for_textures.push(this.texture_img),this.webGL_texture=this.pattern=null)};d.onLostWebGLContext=function(){this.is_family||(this.webGL_texture=null)};d.onRestoreWebGLContext=
function(){if(!this.is_family&&this.instances.length){this.webGL_texture||(this.webGL_texture=this.runtime.glwrap.loadTexture(this.texture_img,!0,this.runtime.linearSampling,this.texture_pixelformat));var a,b;a=0;for(b=this.instances.length;a<b;a++)this.instances[a].webGL_texture=this.webGL_texture}};d.loadTextures=function(){!this.is_family&&(!this.webGL_texture&&this.runtime.glwrap)&&(this.webGL_texture=this.runtime.glwrap.loadTexture(this.texture_img,!0,this.runtime.linearSampling,this.texture_pixelformat))};
d.unloadTextures=function(){!this.is_family&&(!this.instances.length&&this.webGL_texture)&&(this.runtime.glwrap.deleteTexture(this.webGL_texture),this.webGL_texture=null)};d.preloadCanvas2D=function(a){a.drawImage(this.texture_img,0,0)};c.Instance=function(a){this.type=a;this.runtime=a.runtime};d=c.Instance.prototype;d.onCreate=function(){this.visible=0===this.properties[0];this.rcTex=new cr.rect(0,0,0,0);this.has_own_texture=!1;this.texture_img=this.type.texture_img;this.runtime.glwrap?(this.type.loadTextures(),
this.webGL_texture=this.type.webGL_texture):(this.type.pattern||(this.type.pattern=this.runtime.ctx.createPattern(this.type.texture_img,"repeat")),this.pattern=this.type.pattern)};d.afterLoad=function(){this.has_own_texture=!1;this.texture_img=this.type.texture_img};d.onDestroy=function(){this.runtime.glwrap&&(this.has_own_texture&&this.webGL_texture)&&(this.runtime.glwrap.deleteTexture(this.webGL_texture),this.webGL_texture=null)};d.draw=function(a){a.globalAlpha=this.opacity;a.save();a.fillStyle=
this.pattern;var b=this.x,c=this.y;this.runtime.pixel_rounding&&(b=b+0.5|0,c=c+0.5|0);var d=-(this.hotspotX*this.width),k=-(this.hotspotY*this.height),h=d%this.texture_img.width,m=k%this.texture_img.height;0>h&&(h+=this.texture_img.width);0>m&&(m+=this.texture_img.height);a.translate(b,c);a.rotate(this.angle);a.translate(h,m);a.fillRect(d-h,k-m,this.width,this.height);a.restore()};d.drawGL=function(a){a.setTexture(this.webGL_texture);a.setOpacity(this.opacity);var b=this.rcTex;b.right=this.width/
this.texture_img.width;b.bottom=this.height/this.texture_img.height;var c=this.bquad;if(this.runtime.pixel_rounding){var d=(this.x+0.5|0)-this.x,k=(this.y+0.5|0)-this.y;a.quadTex(c.tlx+d,c.tly+k,c.trx+d,c.try_+k,c.brx+d,c.bry+k,c.blx+d,c.bly+k,b)}else a.quadTex(c.tlx,c.tly,c.trx,c.try_,c.brx,c.bry,c.blx,c.bly,b)};a.prototype.OnURLLoaded=function(){return!0};c.cnds=new a;b.prototype.SetEffect=function(a){this.compositeOp=cr.effectToCompositeOp(a);cr.setGLBlend(this,a,this.runtime.gl);this.runtime.redraw=
!0};b.prototype.LoadURL=function(a){var b=new Image,c=this;b.onload=function(){c.texture_img=b;c.runtime.glwrap?(c.has_own_texture&&c.webGL_texture&&c.runtime.glwrap.deleteTexture(c.webGL_texture),c.webGL_texture=c.runtime.glwrap.loadTexture(b,!0,c.runtime.linearSampling)):c.pattern=c.runtime.ctx.createPattern(b,"repeat");c.has_own_texture=!0;c.runtime.redraw=!0;c.runtime.trigger(cr.plugins_.TiledBg.prototype.cnds.OnURLLoaded,c)};"data:"!==a.substr(0,5)&&(b.crossOrigin="anonymous");b.src=a};c.acts=
new b;c.exps=new function(){}})();cr.plugins_.Touch=function(a){this.runtime=a};
(function(){function a(a){l=a.x;k=a.y;h=a.z}function b(a){m=a.x;n=a.y;q=a.z}function c(){}function d(){}var e=cr.plugins_.Touch.prototype;e.Type=function(a){this.plugin=a;this.runtime=a.runtime};e.Type.prototype.onCreate=function(){};e.Instance=function(a){this.type=a;this.runtime=a.runtime;this.touches=[];this.mouseDown=!1};var g=e.Instance.prototype,f={left:0,top:0};g.findTouch=function(a){var b,c;b=0;for(c=this.touches.length;b<c;b++)if(this.touches[b].id===a)return b;return-1};var l=0,k=0,h=0,
m=0,n=0,q=0;g.onCreate=function(){this.isWindows8=!!("undefined"!==typeof window.c2isWindows8&&window.c2isWindows8);this.trigger_id=this.trigger_index=this.curTouchY=this.curTouchX=this.acc_z=this.acc_y=this.acc_x=this.acc_g_z=this.acc_g_y=this.acc_g_x=this.orient_gamma=this.orient_beta=this.orient_alpha=0;this.useMouseInput=0!==this.properties[0];var c=0<this.runtime.fullscreen_mode?document:this.runtime.canvas,d=document;this.runtime.isDirectCanvas?d=c=window.Canvas:this.runtime.isCocoonJs&&(d=
c=window);var e=this;window.navigator.msPointerEnabled?(c.addEventListener("MSPointerDown",function(a){e.onPointerStart(a)},!1),c.addEventListener("MSPointerMove",function(a){e.onPointerMove(a)},!1),d.addEventListener("MSPointerUp",function(a){e.onPointerEnd(a)},!1),d.addEventListener("MSPointerCancel",function(a){e.onPointerEnd(a)},!1),this.runtime.canvas&&(this.runtime.canvas.addEventListener("MSGestureHold",function(a){a.preventDefault()},!1),document.addEventListener("MSGestureHold",function(a){a.preventDefault()},
!1))):(c.addEventListener("touchstart",function(a){e.onTouchStart(a)},!1),c.addEventListener("touchmove",function(a){e.onTouchMove(a)},!1),d.addEventListener("touchend",function(a){e.onTouchEnd(a)},!1),d.addEventListener("touchcancel",function(a){e.onTouchEnd(a)},!1));if(this.isWindows8){var f=function(a){a=a.reading;e.acc_x=a.accelerationX;e.acc_y=a.accelerationY;e.acc_z=a.accelerationZ},g=function(a){a=a.reading;e.orient_alpha=a.yawDegrees;e.orient_beta=a.pitchDegrees;e.orient_gamma=a.rollDegrees},
h=Windows.Devices.Sensors.Accelerometer.getDefault();h&&(h.reportInterval=Math.max(h.minimumReportInterval,16),h.addEventListener("readingchanged",f));var m=Windows.Devices.Sensors.Inclinometer.getDefault();m&&(m.reportInterval=Math.max(m.minimumReportInterval,16),m.addEventListener("readingchanged",g));document.addEventListener("visibilitychange",function(a){document.hidden||document.msHidden?(h&&h.removeEventListener("readingchanged",f),m&&m.removeEventListener("readingchanged",g)):(h&&h.addEventListener("readingchanged",
f),m&&m.addEventListener("readingchanged",g))},!1)}else window.addEventListener("deviceorientation",function(a){e.orient_alpha=a.alpha||0;e.orient_beta=a.beta||0;e.orient_gamma=a.gamma||0},!1),window.addEventListener("devicemotion",function(a){a.accelerationIncludingGravity&&(e.acc_g_x=a.accelerationIncludingGravity.x,e.acc_g_y=a.accelerationIncludingGravity.y,e.acc_g_z=a.accelerationIncludingGravity.z);a.acceleration&&(e.acc_x=a.acceleration.x,e.acc_y=a.acceleration.y,e.acc_z=a.acceleration.z)},
!1);this.useMouseInput&&!this.runtime.isDomFree&&(jQuery(document).mousemove(function(a){e.onMouseMove(a)}),jQuery(document).mousedown(function(a){e.onMouseDown(a)}),jQuery(document).mouseup(function(a){e.onMouseUp(a)}));this.runtime.isAppMobi&&!this.runtime.isDirectCanvas&&AppMobi.accelerometer.watchAcceleration(a,{frequency:40,adjustForRotation:!0});this.runtime.isPhoneGap&&navigator.accelerometer.watchAcceleration(b,null,{frequency:40});this.runtime.tick2Me(this)};g.onPointerMove=function(a){if(a.pointerType!==
a.MSPOINTER_TYPE_MOUSE){a.preventDefault&&a.preventDefault();var b=this.findTouch(a.pointerId),c=cr.performance_now();if(0<=b){var d=this.runtime.isDomFree?f:jQuery(this.runtime.canvas).offset(),b=this.touches[b];2>c-b.time||(b.lasttime=b.time,b.lastx=b.x,b.lasty=b.y,b.time=c,b.x=a.pageX-d.left,b.y=a.pageY-d.top)}}};g.onPointerStart=function(a){if(a.pointerType!==a.MSPOINTER_TYPE_MOUSE){a.preventDefault&&a.preventDefault();var b=this.runtime.isDomFree?f:jQuery(this.runtime.canvas).offset(),c=a.pageX-
b.left,b=a.pageY-b.top,d=cr.performance_now();this.trigger_index=this.touches.length;this.trigger_id=a.pointerId;this.touches.push({time:d,x:c,y:b,lasttime:d,lastx:c,lasty:b,id:a.pointerId,startindex:this.trigger_index});this.runtime.trigger(cr.plugins_.Touch.prototype.cnds.OnNthTouchStart,this);this.runtime.trigger(cr.plugins_.Touch.prototype.cnds.OnTouchStart,this);this.curTouchX=c;this.curTouchY=b;this.runtime.trigger(cr.plugins_.Touch.prototype.cnds.OnTouchObject,this)}};g.onPointerEnd=function(a){a.pointerType!==
a.MSPOINTER_TYPE_MOUSE&&(a.preventDefault&&a.preventDefault(),a=this.findTouch(a.pointerId),this.trigger_index=0<=a?this.touches[a].startindex:-1,this.trigger_id=0<=a?this.touches[a].id:-1,this.runtime.trigger(cr.plugins_.Touch.prototype.cnds.OnNthTouchEnd,this),this.runtime.trigger(cr.plugins_.Touch.prototype.cnds.OnTouchEnd,this),0<=a&&this.touches.splice(a,1))};g.onTouchMove=function(a){a.preventDefault&&a.preventDefault();var b=cr.performance_now(),c,d,e,g;c=0;for(d=a.changedTouches.length;c<
d;c++)if(e=a.changedTouches[c],g=this.findTouch(e.identifier),0<=g){var h=this.runtime.isDomFree?f:jQuery(this.runtime.canvas).offset();g=this.touches[g];2>b-g.time||(g.lasttime=g.time,g.lastx=g.x,g.lasty=g.y,g.time=b,g.x=e.pageX-h.left,g.y=e.pageY-h.top)}};g.onTouchStart=function(a){a.preventDefault&&a.preventDefault();var b=this.runtime.isDomFree?f:jQuery(this.runtime.canvas).offset(),c=cr.performance_now(),d,e,g,h;d=0;for(e=a.changedTouches.length;d<e;d++)if(g=a.changedTouches[d],h=this.findTouch(g.identifier),
-1===h){h=g.pageX-b.left;var m=g.pageY-b.top;this.trigger_index=this.touches.length;this.trigger_id=g.identifier;this.touches.push({time:c,x:h,y:m,lasttime:c,lastx:h,lasty:m,id:g.identifier,startindex:this.trigger_index});this.runtime.trigger(cr.plugins_.Touch.prototype.cnds.OnNthTouchStart,this);this.runtime.trigger(cr.plugins_.Touch.prototype.cnds.OnTouchStart,this);this.curTouchX=h;this.curTouchY=m;this.runtime.trigger(cr.plugins_.Touch.prototype.cnds.OnTouchObject,this)}};g.onTouchEnd=function(a){a.preventDefault&&
a.preventDefault();var b,c,d;b=0;for(c=a.changedTouches.length;b<c;b++)d=a.changedTouches[b],d=this.findTouch(d.identifier),0<=d&&(this.trigger_index=this.touches[d].startindex,this.trigger_id=this.touches[d].id,this.runtime.trigger(cr.plugins_.Touch.prototype.cnds.OnNthTouchEnd,this),this.runtime.trigger(cr.plugins_.Touch.prototype.cnds.OnTouchEnd,this),this.touches.splice(d,1))};g.getAlpha=function(){return this.runtime.isAppMobi&&0===this.orient_alpha&&0!==h?90*h:this.runtime.isPhoneGap&&0===this.orient_alpha&&
0!==q?90*q:this.orient_alpha};g.getBeta=function(){return this.runtime.isAppMobi&&0===this.orient_beta&&0!==k?-90*k:this.runtime.isPhoneGap&&0===this.orient_beta&&0!==n?-90*n:this.orient_beta};g.getGamma=function(){return this.runtime.isAppMobi&&0===this.orient_gamma&&0!==l?90*l:this.runtime.isPhoneGap&&0===this.orient_gamma&&0!==m?90*m:this.orient_gamma};g.onMouseDown=function(a){a.preventDefault&&this.runtime.had_a_click&&a.preventDefault();this.onTouchStart({changedTouches:[{pageX:a.pageX,pageY:a.pageY,
identifier:0}]});this.mouseDown=!0};g.onMouseMove=function(a){a.preventDefault&&this.runtime.had_a_click&&a.preventDefault();if(this.mouseDown)this.onTouchMove({changedTouches:[{pageX:a.pageX,pageY:a.pageY,identifier:0}]})};g.onMouseUp=function(a){a.preventDefault&&this.runtime.had_a_click&&a.preventDefault();this.runtime.had_a_click=!0;this.onTouchEnd({changedTouches:[{pageX:a.pageX,pageY:a.pageY,identifier:0}]});this.mouseDown=!1};g.tick2=function(){var a,b,c,d=cr.performance_now();a=0;for(b=this.touches.length;a<
b;a++)c=this.touches[a],c.time<=d-50&&(c.lasttime=d)};c.prototype.OnTouchStart=function(){return!0};c.prototype.OnTouchEnd=function(){return!0};c.prototype.IsInTouch=function(){return this.touches.length};c.prototype.OnTouchObject=function(a){return!a?!1:this.runtime.testAndSelectCanvasPointOverlap(a,this.curTouchX,this.curTouchY,!1)};c.prototype.IsTouchingObject=function(a){if(!a)return!1;a=a.getCurrentSol();var b=a.getObjects(),c,d,e=[],f,g,h,m;f=0;for(g=b.length;f<g;f++){var k=b[f];k.update_bbox();
h=0;for(m=this.touches.length;h<m;h++)if(d=this.touches[h],c=k.layer.canvasToLayer(d.x,d.y,!0),d=k.layer.canvasToLayer(d.x,d.y,!1),k.contains_pt(c,d)){e.push(k);break}}return e.length?(a.select_all=!1,a.instances=e,!0):!1};c.prototype.CompareTouchSpeed=function(a,b,c){a=Math.floor(a);if(0>a||a>=this.touches.length)return!1;var d=this.touches[a];a=cr.distanceTo(d.x,d.y,d.lastx,d.lasty);var d=(d.time-d.lasttime)/1E3,e=0;0<d&&(e=a/d);return cr.do_cmp(e,b,c)};c.prototype.OrientationSupported=function(){return"undefined"!==
typeof window.DeviceOrientationEvent};c.prototype.MotionSupported=function(){return"undefined"!==typeof window.DeviceMotionEvent};c.prototype.CompareOrientation=function(a,b,c){var d=0,d=0===a?this.getAlpha():1===a?this.getBeta():this.getGamma();return cr.do_cmp(d,b,c)};c.prototype.CompareAcceleration=function(a,b,c){var d=0;0===a?d=this.acc_g_x:1===a?d=this.acc_g_y:2===a?d=this.acc_g_z:3===a?d=this.acc_x:4===a?d=this.acc_y:5===a&&(d=this.acc_z);return cr.do_cmp(d,b,c)};c.prototype.OnNthTouchStart=
function(a){a=Math.floor(a);return a===this.trigger_index};c.prototype.OnNthTouchEnd=function(a){a=Math.floor(a);return a===this.trigger_index};c.prototype.HasNthTouch=function(a){a=Math.floor(a);return this.touches.length>=a+1};e.cnds=new c;d.prototype.TouchCount=function(a){a.set_int(this.touches.length)};d.prototype.X=function(a,b){if(this.touches.length){var c,d,e,f,g;cr.is_undefined(b)?(c=this.runtime.getLayerByNumber(0),d=c.scale,e=c.zoomRate,f=c.parallaxX,g=c.angle,c.scale=this.runtime.running_layout.scale,
c.zoomRate=1,c.parallaxX=1,c.angle=this.runtime.running_layout.angle,a.set_float(c.canvasToLayer(this.touches[0].x,this.touches[0].y,!0)),c.scale=d,c.zoomRate=e,c.parallaxX=f,c.angle=g):(c=cr.is_number(b)?this.runtime.getLayerByNumber(b):this.runtime.getLayerByName(b))?a.set_float(c.canvasToLayer(this.touches[0].x,this.touches[0].y,!0)):a.set_float(0)}else a.set_float(0)};d.prototype.XAt=function(a,b,c){b=Math.floor(b);if(0>b||b>=this.touches.length)a.set_float(0);else{var d,e,f,g;cr.is_undefined(c)?
(c=this.runtime.getLayerByNumber(0),d=c.scale,e=c.zoomRate,f=c.parallaxX,g=c.angle,c.scale=this.runtime.running_layout.scale,c.zoomRate=1,c.parallaxX=1,c.angle=this.runtime.running_layout.angle,a.set_float(c.canvasToLayer(this.touches[b].x,this.touches[b].y,!0)),c.scale=d,c.zoomRate=e,c.parallaxX=f,c.angle=g):(c=cr.is_number(c)?this.runtime.getLayerByNumber(c):this.runtime.getLayerByName(c))?a.set_float(c.canvasToLayer(this.touches[b].x,this.touches[b].y,!0)):a.set_float(0)}};d.prototype.XForID=function(a,
b,c){b=this.findTouch(b);if(0>b)a.set_float(0);else{b=this.touches[b];var d,e,f,g;cr.is_undefined(c)?(c=this.runtime.getLayerByNumber(0),d=c.scale,e=c.zoomRate,f=c.parallaxX,g=c.angle,c.scale=this.runtime.running_layout.scale,c.zoomRate=1,c.parallaxX=1,c.angle=this.runtime.running_layout.angle,a.set_float(c.canvasToLayer(b.x,b.y,!0)),c.scale=d,c.zoomRate=e,c.parallaxX=f,c.angle=g):(c=cr.is_number(c)?this.runtime.getLayerByNumber(c):this.runtime.getLayerByName(c))?a.set_float(c.canvasToLayer(b.x,b.y,
!0)):a.set_float(0)}};d.prototype.Y=function(a,b){if(this.touches.length){var c,d,e,f,g;cr.is_undefined(b)?(c=this.runtime.getLayerByNumber(0),d=c.scale,e=c.zoomRate,f=c.parallaxY,g=c.angle,c.scale=this.runtime.running_layout.scale,c.zoomRate=1,c.parallaxY=1,c.angle=this.runtime.running_layout.angle,a.set_float(c.canvasToLayer(this.touches[0].x,this.touches[0].y,!1)),c.scale=d,c.zoomRate=e,c.parallaxY=f,c.angle=g):(c=cr.is_number(b)?this.runtime.getLayerByNumber(b):this.runtime.getLayerByName(b))?
a.set_float(c.canvasToLayer(this.touches[0].x,this.touches[0].y,!1)):a.set_float(0)}else a.set_float(0)};d.prototype.YAt=function(a,b,c){b=Math.floor(b);if(0>b||b>=this.touches.length)a.set_float(0);else{var d,e,f,g;cr.is_undefined(c)?(c=this.runtime.getLayerByNumber(0),d=c.scale,e=c.zoomRate,f=c.parallaxY,g=c.angle,c.scale=this.runtime.running_layout.scale,c.zoomRate=1,c.parallaxY=1,c.angle=this.runtime.running_layout.angle,a.set_float(c.canvasToLayer(this.touches[b].x,this.touches[b].y,!1)),c.scale=
d,c.zoomRate=e,c.parallaxY=f,c.angle=g):(c=cr.is_number(c)?this.runtime.getLayerByNumber(c):this.runtime.getLayerByName(c))?a.set_float(c.canvasToLayer(this.touches[b].x,this.touches[b].y,!1)):a.set_float(0)}};d.prototype.YForID=function(a,b,c){b=this.findTouch(b);if(0>b)a.set_float(0);else{b=this.touches[b];var d,e,f,g;cr.is_undefined(c)?(c=this.runtime.getLayerByNumber(0),d=c.scale,e=c.zoomRate,f=c.parallaxY,g=c.angle,c.scale=this.runtime.running_layout.scale,c.zoomRate=1,c.parallaxY=1,c.angle=
this.runtime.running_layout.angle,a.set_float(c.canvasToLayer(b.x,b.y,!1)),c.scale=d,c.zoomRate=e,c.parallaxY=f,c.angle=g):(c=cr.is_number(c)?this.runtime.getLayerByNumber(c):this.runtime.getLayerByName(c))?a.set_float(c.canvasToLayer(b.x,b.y,!1)):a.set_float(0)}};d.prototype.AbsoluteX=function(a){this.touches.length?a.set_float(this.touches[0].x):a.set_float(0)};d.prototype.AbsoluteXAt=function(a,b){b=Math.floor(b);0>b||b>=this.touches.length?a.set_float(0):a.set_float(this.touches[b].x)};d.prototype.AbsoluteXForID=
function(a,b){var c=this.findTouch(b);0>c?a.set_float(0):a.set_float(this.touches[c].x)};d.prototype.AbsoluteY=function(a){this.touches.length?a.set_float(this.touches[0].y):a.set_float(0)};d.prototype.AbsoluteYAt=function(a,b){b=Math.floor(b);0>b||b>=this.touches.length?a.set_float(0):a.set_float(this.touches[b].y)};d.prototype.AbsoluteYForID=function(a,b){var c=this.findTouch(b);0>c?a.set_float(0):a.set_float(this.touches[c].y)};d.prototype.SpeedAt=function(a,b){b=Math.floor(b);if(0>b||b>=this.touches.length)a.set_float(0);
else{var c=this.touches[b],d=cr.distanceTo(c.x,c.y,c.lastx,c.lasty),c=(c.time-c.lasttime)/1E3;0===c?a.set_float(0):a.set_float(d/c)}};d.prototype.SpeedForID=function(a,b){var c=this.findTouch(b);if(0>c)a.set_float(0);else{var d=this.touches[c],c=cr.distanceTo(d.x,d.y,d.lastx,d.lasty),d=(d.time-d.lasttime)/1E3;0===d?a.set_float(0):a.set_float(c/d)}};d.prototype.AngleAt=function(a,b){b=Math.floor(b);if(0>b||b>=this.touches.length)a.set_float(0);else{var c=this.touches[b];a.set_float(cr.to_degrees(cr.angleTo(c.lastx,
c.lasty,c.x,c.y)))}};d.prototype.AngleForID=function(a,b){var c=this.findTouch(b);0>c?a.set_float(0):(c=this.touches[c],a.set_float(cr.to_degrees(cr.angleTo(c.lastx,c.lasty,c.x,c.y))))};d.prototype.Alpha=function(a){a.set_float(this.getAlpha())};d.prototype.Beta=function(a){a.set_float(this.getBeta())};d.prototype.Gamma=function(a){a.set_float(this.getGamma())};d.prototype.AccelerationXWithG=function(a){a.set_float(this.acc_g_x)};d.prototype.AccelerationYWithG=function(a){a.set_float(this.acc_g_y)};
d.prototype.AccelerationZWithG=function(a){a.set_float(this.acc_g_z)};d.prototype.AccelerationX=function(a){a.set_float(this.acc_x)};d.prototype.AccelerationY=function(a){a.set_float(this.acc_y)};d.prototype.AccelerationZ=function(a){a.set_float(this.acc_z)};d.prototype.TouchIndex=function(a){a.set_int(this.trigger_index)};d.prototype.TouchID=function(a){a.set_float(this.trigger_id)};e.exps=new d})();cr.plugins_.win8=function(a){this.runtime=a};
(function(){function a(){}function b(){}function c(a){var b,c,d,e,f=0,g=[];do b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(a.charAt(f++)),c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(a.charAt(f++)),d="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(a.charAt(f++)),e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(a.charAt(f++)),d=b<<18|c<<12|d<<6|e,b=d>>16&255,c=d>>8&255,d&=255,
g.push(b),g.push(c),g.push(d);while(f<a.length);return g}function d(a,b){if("data:"!==a.substr(0,5))return!1;var d=a.substring(5).split(",");if(2!==d.length)return!1;var e;if(-1<d[0].indexOf("image/png"))e="png";else if(-1<d[0].indexOf("image/jpeg"))e="jpg";else return!1;e="shareimage."+e;if(-1===d[0].indexOf(";base64"))return!1;var f=c(d[1]);Windows.Storage.ApplicationData.current.localFolder.createFileAsync(e,Windows.Storage.CreationCollisionOption.replaceExisting).then(function(a){Windows.Storage.FileIO.writeBytesAsync(a,
f).then(function(){b&&b(a)})})}function e(){}var g=cr.plugins_.win8.prototype;g.Type=function(a){this.plugin=a;this.runtime=a.runtime};g.Type.prototype.onCreate=function(){};g.Instance=function(a){this.type=a;this.runtime=a.runtime};var f=g.Instance.prototype,l=null,k=!1;f.onCreate=function(){this.isWindows8=this.runtime.isWindows8App;this.triggerViewState=0;this.isTestMode=0!==this.properties[0];this.showAbout=0!==this.properties[1];this.showSupport=0!==this.properties[2];this.showPrivacy=0!==this.properties[3];
this.appFormattedPrice="";this.currentApp=this.lastProductListings=null;var a=this;if(this.isWindows8){var b=Windows.ApplicationModel.Store;this.currentApp=this.isTestMode?b.CurrentAppSimulator:b.CurrentApp;this.isTestMode&&(new Windows.UI.Popups.MessageDialog("Note: this Windows 8 app is in Test Mode, designed for testing purchases. Before publishing, be sure to set Test Mode to 'No' in the Windows 8 object's properties.")).showAsync();window.addEventListener("resize",function(){a.triggerViewState=
Windows.UI.ViewManagement.ApplicationView.value;a.runtime.trigger(cr.plugins_.win8.prototype.cnds.OnViewStateChange,a)});Windows.Storage.ApplicationData.current.addEventListener("datachanged",function(){a.runtime.trigger(cr.plugins_.win8.prototype.cnds.OnDataChanged,a)});Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView().addEventListener("datarequested",function(b){l=b;k=!1;a.runtime.trigger(cr.plugins_.win8.prototype.cnds.OnShare,a);l=null;k||b.request.failWithDisplayText("Try selecting a different option before sharing.")});
this.currentApp.licenseInformation.addEventListener("licensechanged",function(){a.runtime.trigger(cr.plugins_.win8.prototype.cnds.OnLicenseChanged,a)});(this.showAbout||this.showSupport||this.showPrivacy)&&WinJS.Application.addEventListener("settings",function(b){var c={};a.showAbout&&(c.about={title:"About",href:"/about.html"});a.showSupport&&(c.support={title:"Support",href:"/support.html"});a.showPrivacy&&(c.privacy={title:"Privacy Policy",href:"/privacy.html"});b.detail.applicationcommands=c;
WinJS.UI.SettingsFlyout.populateSettings(b)});this.isTestMode&&Windows.ApplicationModel.Package.current.installedLocation.getFileAsync("WindowsStoreProxy.xml").done(function(a){Windows.ApplicationModel.Store.CurrentAppSimulator.reloadSimulatorAsync(a).done(function(){console.log("[Construct 2] Test mode; loaded WindowsStoreProxy.xml")},function(a){console.log("[Construct 2] Error loading WindowsStoreProxy.xml: "+a)})},function(a){console.log("[Construct 2] Error loading WindowsStoreProxy.xml: "+a)})}};
f.roamingValues=function(){return this.isWindows8?Windows.Storage.ApplicationData.current.roamingSettings.values:null};a.prototype.IsWindows8=function(){return this.isWindows8};a.prototype.OnViewStateChange=function(a){return this.isWindows8?a===this.triggerViewState:!1};a.prototype.CompareViewState=function(a){return this.isWindows8?Windows.UI.ViewManagement.ApplicationView.value===a:!1};a.prototype.OnDataChanged=function(){return!0};a.prototype.RoamingKeyExists=function(a){return this.isWindows8?
this.roamingValues().hasKey(a):!1};a.prototype.OnShare=function(){return!0};a.prototype.OnLicenseChanged=function(){return!0};a.prototype.OnPurchaseSuccess=function(){return!0};a.prototype.OnPurchaseFail=function(){return!0};a.prototype.OnStoreListing=function(){return!0};a.prototype.IsTrial=function(){return this.isWindows8&&this.currentApp.licenseInformation.isTrial&&this.currentApp.licenseInformation.isActive};a.prototype.IsLicensed=function(){return this.isWindows8&&!this.currentApp.licenseInformation.isTrial&&
this.currentApp.licenseInformation.isActive};a.prototype.IsExpiredTrial=function(){return this.isWindows8&&this.currentApp.licenseInformation.isTrial&&!this.currentApp.licenseInformation.isActive};a.prototype.HasProduct=function(a){if(!this.isWindows8)return!1;var b=this.currentApp.licenseInformation.productLicenses;return!b.hasKey(a)?!1:b.lookup(a).isActive};g.cnds=new a;b.prototype.TryUnsnap=function(){this.isWindows8&&Windows.UI.ViewManagement.ApplicationView.tryUnsnap()};b.prototype.SetRoamingValue=
function(a,b){this.isWindows8&&(this.roamingValues()[a]=b.toString())};b.prototype.RemoveRoamingValue=function(a){this.isWindows8&&this.roamingValues().remove(a)};b.prototype.ClearRoamingData=function(){this.isWindows8&&this.roamingValues().clear()};b.prototype.ShowShareUI=function(){this.isWindows8&&Windows.ApplicationModel.DataTransfer.DataTransferManager.showShareUI()};b.prototype.ShareText=function(a,b,c){if(this.isWindows8&&l){var d=l.request;d.data.properties.title=a;d.data.properties.description=
b;d.data.setText(c);k=!0}};b.prototype.ShareLink=function(a,b,c){if(this.isWindows8&&l){var d=l.request;d.data.properties.title=a;d.data.properties.description=b;d.data.setUri(new Windows.Foundation.Uri(c));k=!0}};b.prototype.ShareHTML=function(a,b,c){if(this.isWindows8&&l){var d=l.request;d.data.properties.title=a;d.data.properties.description=b;a=Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.createHtmlFormat(c);d.data.setHtmlFormat(a);k=!0}};b.prototype.ShareSpriteImage=function(a,b,c){if(this.isWindows8&&
l&&c&&(c=c.getFirstPicked())&&c.curFrame){c=c.curFrame.getDataUri();var e=l.request;e.data.properties.title=a;e.data.properties.description=b;var f=e.getDeferral();d(c,function(a){e.data.setBitmap(Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(a));f.complete()});k=!0}};b.prototype.ShareDataUri=function(a,b,c){if(this.isWindows8&&l){var e=l.request;e.data.properties.title=a;e.data.properties.description=b;var f=e.getDeferral();d(c,function(a){e.data.setBitmap(Windows.Storage.Streams.RandomAccessStreamReference.createFromFile(a));
f.complete()});k=!0}};b.prototype.FailShare=function(a){this.isWindows8&&l&&(l.request.failWithDisplayText(a),k=!0)};var h="tileSquareBlock tileSquareText02 tileSquareText04 tileWideText03 tileWideText04 tileWideText09".split(" ");b.prototype.SetLiveTileText=function(a,b,c){a=Math.floor(a);if(this.isWindows8&&0<=a&&a<h.length){var d=Windows.UI.Notifications;a=d.TileUpdateManager.getTemplateContent(d.TileTemplateType[h[a]]);var e=a.getElementsByTagName("text");e[0].appendChild(a.createTextNode(b));
2<=e.length&&e[1].appendChild(a.createTextNode(c));b=new d.TileNotification(a);d.TileUpdateManager.createTileUpdaterForApplication().update(b)}};b.prototype.PurchaseApp=function(){if(this.isWindows8){var a=this;this.currentApp.requestAppPurchaseAsync(!1).then(function(){console.log("[Construct 2] App purchased OK");a.runtime.trigger(cr.plugins_.win8.prototype.cnds.OnPurchaseSuccess,a)},function(b){console.log("[Construct 2] App purchase failed: "+b);a.runtime.trigger(cr.plugins_.win8.prototype.cnds.OnPurchaseFail,
a)})}};b.prototype.PurchaseProduct=function(a){if(this.isWindows8){var b=this;this.currentApp.requestProductPurchaseAsync(a,!1).then(function(){console.log("[Construct 2] Product '"+a+"' purchased OK");b.runtime.trigger(cr.plugins_.win8.prototype.cnds.OnPurchaseSuccess,b)},function(c){console.log("[Construct 2] Product '"+a+"' purchase failed: "+c);b.runtime.trigger(cr.plugins_.win8.prototype.cnds.OnPurchaseFail,b)})}};b.prototype.RequestStoreListing=function(){if(this.isWindows8){var a=this;this.currentApp.loadListingInformationAsync().then(function(b){console.log("[Construct 2] Listing information loaded");
a.appFormattedPrice=b.formattedPrice;a.lastProductListings=b.productListings;a.runtime.trigger(cr.plugins_.win8.prototype.cnds.OnStoreListing,a)})}};g.acts=new b;e.prototype.RoamingValue=function(a,b){if(this.isWindows8){var c=this.roamingValues()[b];a.set_string(c?c.toString():"")}else a.set_string("")};e.prototype.TrialTimeLeft=function(a){this.isWindows8?a.set_float((this.currentApp.licenseInformation.expirationDate.getTime()-Date.now())/1E3):a.set_float(0)};e.prototype.AppFormattedPrice=function(a){a.set_string(this.appFormattedPrice)};
e.prototype.ProductName=function(a,b){var c="";this.isWindows8&&(this.lastProductListings&&this.lastProductListings.hasKey(b))&&(c=this.lastProductListings.lookup(b).name);a.set_string(c)};e.prototype.ProductFormattedPrice=function(a,b){var c="";this.isWindows8&&(this.lastProductListings&&this.lastProductListings.hasKey(b))&&(c=this.lastProductListings.lookup(b).formattedPrice);a.set_string(c)};g.exps=new e})();
cr.behaviors.DragnDrop=function(a){this.runtime=a;var b=this;this.runtime.isDomFree||(jQuery(document).mousemove(function(a){b.onMouseMove(a)}),jQuery(document).mousedown(function(a){b.onMouseDown(a)}),jQuery(document).mouseup(function(a){b.onMouseUp(a)}));a=0<this.runtime.fullscreen_mode?document:this.runtime.canvas;this.runtime.isDirectCanvas?a=window.Canvas:this.runtime.isCocoonJs&&(a=window);a.addEventListener("touchstart",function(a){b.onTouchStart(a)},!1);a.addEventListener("touchmove",function(a){b.onTouchMove(a)},
!1);a.addEventListener("touchend",function(a){b.onTouchEnd(a)},!1);a.addEventListener("touchcancel",function(a){b.onTouchEnd(a)},!1);window.navigator.msPointerEnabled&&(a.addEventListener("MSPointerDown",function(a){b.onPointerStart(a)},!1),a.addEventListener("MSPointerMove",function(a){b.onPointerMove(a)},!1),a.addEventListener("MSPointerUp",function(a){b.onPointerEnd(a)},!1),a.addEventListener("MSPointerCancel",function(a){b.onPointerEnd(a)},!1))};
(function(){function a(a){var b,c;b=0;for(c=a.behavior_insts.length;b<c;b++)if(a.behavior_insts[b]instanceof d.Instance)return a.behavior_insts[b];return null}function b(){}function c(){}var d=cr.behaviors.DragnDrop.prototype,e={left:0,top:0};d.onMouseDown=function(a){if(1===a.which)this.onInputDown("leftmouse",a.pageX,a.pageY)};d.onMouseMove=function(a){if(1===a.which)this.onInputMove("leftmouse",a.pageX,a.pageY)};d.onMouseUp=function(a){if(1===a.which)this.onInputUp("leftmouse")};d.onTouchStart=
function(a){a.preventDefault&&a.preventDefault();var b,c,d,e;b=0;for(c=a.changedTouches.length;b<c;b++)d=a.changedTouches[b],e=d.identifier,this.onInputDown(e?e.toString():"<none>",d.pageX,d.pageY)};d.onTouchMove=function(a){a.preventDefault&&a.preventDefault();var b,c,d,e;b=0;for(c=a.changedTouches.length;b<c;b++)d=a.changedTouches[b],e=d.identifier,this.onInputMove(e?e.toString():"<none>",d.pageX,d.pageY)};d.onTouchEnd=function(a){a.preventDefault&&a.preventDefault();var b,c,d;b=0;for(c=a.changedTouches.length;b<
c;b++)d=a.changedTouches[b],d=d.identifier,this.onInputUp(d?d.toString():"<none>")};d.onPointerStart=function(a){a.pointerType!==a.MSPOINTER_TYPE_MOUSE&&(a.preventDefault&&a.preventDefault(),this.onInputDown(a.pointerId.toString(),a.pageX,a.pageY))};d.onPointerMove=function(a){a.pointerType!==a.MSPOINTER_TYPE_MOUSE&&(a.preventDefault&&a.preventDefault(),this.onInputMove(a.pointerId.toString(),a.pageX,a.pageY))};d.onPointerEnd=function(a){a.pointerType!==a.MSPOINTER_TYPE_MOUSE&&(a.preventDefault&&
a.preventDefault(),this.onInputUp(a.pointerId.toString()))};d.onInputDown=function(b,c,d){var g=this.runtime.isDomFree?e:jQuery(this.runtime.canvas).offset();c-=g.left;d-=g.top;var m,n,q,p,g=this.my_instances.valuesRef(),r,s,t,v=null;r=0;for(s=g.length;r<s;r++)t=g[r],m=a(t),m.enabled&&!m.dragging&&(m=t.layer.canvasToLayer(c,d,!0),n=t.layer.canvasToLayer(c,d,!1),t.update_bbox(),t.contains_pt(m,n)&&(v?t.layer.index>v.layer.index?(v=t,q=m,p=n):t.layer.index===v.layer.index&&t.get_zindex()>v.get_zindex()&&
(v=t,q=m,p=n):(v=t,q=m,p=n)));if(v)a(v).onDown(b,q,p)};d.onInputMove=function(b,c,d){var g=this.runtime.isDomFree?e:jQuery(this.runtime.canvas).offset();c-=g.left;d-=g.top;var m,n=this.my_instances.valuesRef(),q,p,r;q=0;for(p=n.length;q<p;q++)m=n[q],r=a(m),r.enabled&&(r.dragging&&!(r.dragging&&r.dragsource!==b))&&(g=m.layer.canvasToLayer(c,d,!0),m=m.layer.canvasToLayer(c,d,!1),r.onMove(g,m))};d.onInputUp=function(b){var c=this.my_instances.valuesRef(),d,e,g;d=0;for(e=c.length;d<e;d++)if(g=c[d],g=
a(g),g.dragging&&g.dragsource===b)g.onUp()};d.Type=function(a,b){this.behavior=a;this.objtype=b;this.runtime=a.runtime};d.Type.prototype.onCreate=function(){};d.Instance=function(a,b){this.type=a;this.behavior=a.behavior;this.inst=b;this.runtime=a.runtime};var g=d.Instance.prototype;g.onCreate=function(){this.dragging=!1;this.dy=this.dx=0;this.dragsource="<none>";this.axes=this.properties[0];this.enabled=0!==this.properties[1]};g.saveToJSON=function(){return{enabled:this.enabled}};g.loadFromJSON=
function(a){this.enabled=a.enabled;this.dragging=!1};g.onDown=function(a,b,c){this.dx=b-this.inst.x;this.dy=c-this.inst.y;this.dragging=!0;this.dragsource=a;this.runtime.trigger(cr.behaviors.DragnDrop.prototype.cnds.OnDragStart,this.inst)};g.onMove=function(a,b){var c=a-this.dx,d=b-this.dy;if(0===this.axes){if(this.inst.x!==c||this.inst.y!==d)this.inst.x=c,this.inst.y=d,this.inst.set_bbox_changed()}else 1===this.axes?this.inst.x!==c&&(this.inst.x=c,this.inst.set_bbox_changed()):2===this.axes&&this.inst.y!==
d&&(this.inst.y=d,this.inst.set_bbox_changed())};g.onUp=function(){this.dragging=!1;this.runtime.trigger(cr.behaviors.DragnDrop.prototype.cnds.OnDrop,this.inst)};g.tick=function(){};b.prototype.IsDragging=function(){return this.dragging};b.prototype.OnDragStart=function(){return!0};b.prototype.OnDrop=function(){return!0};b.prototype.IsEnabled=function(){return!!this.enabled};d.cnds=new b;c.prototype.SetEnabled=function(a){this.enabled=0!==a;this.enabled||(this.dragging=!1)};c.prototype.Drop=function(){if(this.dragging)this.onUp()};
d.acts=new c;d.exps=new function(){}})();var Box2D={Dynamics:{}};Box2D.Dynamics.Joints={};Box2D.Common={};Box2D.Common.Math={};Box2D.Collision={};Box2D.Collision.Shapes={};function c2inherit(a,b){for(var c in b.prototype)b.prototype.hasOwnProperty(c)&&(a.prototype[c]=b.prototype[c])}
if(navigator.isCocoonJS&&"undefined"!==typeof window.cr_cjs_accelerated_physics)cr.logexport("Using CocoonJS native physics"),!window.ext||"undefined"===typeof window.ext.IDTK_SRV_BOX2D?console.log("The CocoonJS binding for Box2D has been ignored because ext.IDTK_SRV_BOX2D is not available"):function(){var a=function(a,b){void 0===a&&(a=0);void 0===b&&(b=0);this.x=a;this.y=b};Box2D.Common.Math.b2Vec2=a;a._freeCache=[];a.Get=function(a,b){if(0<Box2D.Common.Math.b2Vec2._freeCache.length){var c=Box2D.Common.Math.b2Vec2._freeCache.pop();
c.Set(a,b);return c}return new Box2D.Common.Math.b2Vec2(a,b)};a.Free=function(a){1E4>Box2D.Common.Math.b2Vec2._freeCache.length&&Box2D.Common.Math.b2Vec2._freeCache.push(a)};a.prototype.SetZero=function(){this.y=this.x=0};a.prototype.Set=function(a,b){void 0===a&&(a=0);void 0===b&&(b=0);this.x=a;this.y=b};a.prototype.SetV=function(a){this.x=a.x;this.y=a.y};a.Make=function(b,c){void 0===b&&(b=0);void 0===c&&(c=0);return a.Get(b,c)};a.prototype.Copy=function(){return a.Get(this.x,this.y)};a.prototype.Add=
function(a){this.x+=a.x;this.y+=a.y};a.prototype.Subtract=function(a){this.x-=a.x;this.y-=a.y};a.prototype.Multiply=function(a){void 0===a&&(a=0);this.x*=a;this.y*=a};a.prototype.Length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)};a.prototype.LengthSquared=function(){return this.x*this.x+this.y*this.y};a.prototype.Normalize=function(){var a=Math.sqrt(this.x*this.x+this.y*this.y);if(a<Number.MIN_VALUE)return 0;var b=1/a;this.x*=b;this.y*=b;return a};var b=function(){this.col1=a.Get(0,
0);this.col2=a.Get(0,0);this.SetIdentity()};Box2D.Common.Math.b2Mat22=b;b.FromAngle=function(a){void 0===a&&(a=0);var c=new b;c.Set(a);return c};b.FromVV=function(a,c){var d=new b;d.SetVV(a,c);return d};b.prototype.Set=function(a){void 0===a&&(a=0);var b=Math.cos(a);a=Math.sin(a);this.col1.x=b;this.col2.x=-a;this.col1.y=a;this.col2.y=b};b.prototype.SetVV=function(a,b){this.col1.SetV(a);this.col2.SetV(b)};b.prototype.Copy=function(){var a=new b;a.SetM(this);return a};b.prototype.SetM=function(a){this.col1.SetV(a.col1);
this.col2.SetV(a.col2)};b.prototype.AddM=function(a){this.col1.x+=a.col1.x;this.col1.y+=a.col1.y;this.col2.x+=a.col2.x;this.col2.y+=a.col2.y};b.prototype.SetIdentity=function(){this.col1.x=1;this.col2.x=0;this.col1.y=0;this.col2.y=1};b.prototype.SetZero=function(){this.col1.x=0;this.col2.x=0;this.col1.y=0;this.col2.y=0};b.prototype.GetAngle=function(){return Math.atan2(this.col1.y,this.col1.x)};b.prototype.GetInverse=function(a){var b=this.col1.x,c=this.col2.x,d=this.col1.y,e=this.col2.y,f=b*e-c*
d;0!==f&&(f=1/f);a.col1.x=f*e;a.col2.x=-f*c;a.col1.y=-f*d;a.col2.y=f*b;return a};b.prototype.Solve=function(a,b,c){void 0===b&&(b=0);void 0===c&&(c=0);var d=this.col1.x,e=this.col2.x,f=this.col1.y,g=this.col2.y,k=d*g-e*f;0!==k&&(k=1/k);a.x=k*(g*b-e*c);a.y=k*(d*c-f*b);return a};b.prototype.Abs=function(){this.col1.Abs();this.col2.Abs()};var c=function(c,d){this.position=a.Get(0,0);this.R=new b;void 0===c&&(c=null);void 0===d&&(d=null);c&&(this.position.SetV(c),this.R.SetM(d))};Box2D.Common.Math.b2Transform=
c;c.prototype.Initialize=function(a,b){this.position.SetV(a);this.R.SetM(b)};c.prototype.SetIdentity=function(){this.position.SetZero();this.R.SetIdentity()};c.prototype.Set=function(a){this.position.SetV(a.position);this.R.SetM(a.R)};c.prototype.SetAngle=function(){return Math.atan2(this.R.col1.y,this.R.col1.x)};var d=function(){};Box2D.Common.Math.b2Math=d;d.IsValid=function(a){void 0===a&&(a=0);return isFinite(a)};d.Dot=function(a,b){return a.x*b.x+a.y*b.y};d.CrossVV=function(a,b){return a.x*b.y-
a.y*b.x};d.CrossVF=function(b,c){void 0===c&&(c=0);return a.Get(c*b.y,-c*b.x)};d.CrossFV=function(b,c){void 0===b&&(b=0);return a.Get(-b*c.y,b*c.x)};d.MulMV=function(b,c){return a.Get(b.col1.x*c.x+b.col2.x*c.y,b.col1.y*c.x+b.col2.y*c.y)};d.MulTMV=function(b,c){return a.Get(d.Dot(c,b.col1),d.Dot(c,b.col2))};d.MulX=function(a,b){var c=d.MulMV(a.R,b);c.x+=a.position.x;c.y+=a.position.y;return c};d.MulXT=function(a,b){var c=d.SubtractVV(b,a.position),e=c.x*a.R.col1.x+c.y*a.R.col1.y;c.y=c.x*a.R.col2.x+
c.y*a.R.col2.y;c.x=e;return c};d.AddVV=function(b,c){return a.Get(b.x+c.x,b.y+c.y)};d.SubtractVV=function(b,c){return a.Get(b.x-c.x,b.y-c.y)};d.Distance=function(a,b){var c=a.x-b.x,d=a.y-b.y;return Math.sqrt(c*c+d*d)};d.DistanceSquared=function(a,b){var c=a.x-b.x,d=a.y-b.y;return c*c+d*d};d.MulFV=function(b,c){void 0===b&&(b=0);return a.Get(b*c.x,b*c.y)};d.AddMM=function(a,c){return b.FromVV(d.AddVV(a.col1,c.col1),d.AddVV(a.col2,c.col2))};d.MulMM=function(a,c){return b.FromVV(d.MulMV(a,c.col1),d.MulMV(a,
c.col2))};d.MulTMM=function(c,e){var f=a.Get(d.Dot(c.col1,e.col1),d.Dot(c.col2,e.col1)),g=a.Get(d.Dot(c.col1,e.col2),d.Dot(c.col2,e.col2));return b.FromVV(f,g)};d.Abs=function(a){void 0===a&&(a=0);return 0<a?a:-a};d.AbsV=function(b){return a.Get(d.Abs(b.x),d.Abs(b.y))};d.AbsM=function(a){return b.FromVV(d.AbsV(a.col1),d.AbsV(a.col2))};d.Min=function(a,b){void 0===a&&(a=0);void 0===b&&(b=0);return a<b?a:b};d.MinV=function(b,c){return a.Get(d.Min(b.x,c.x),d.Min(b.y,c.y))};d.Max=function(a,b){void 0===
a&&(a=0);void 0===b&&(b=0);return a>b?a:b};d.MaxV=function(b,c){return a.Get(d.Max(b.x,c.x),d.Max(b.y,c.y))};d.Clamp=function(a,b,c){void 0===a&&(a=0);void 0===b&&(b=0);void 0===c&&(c=0);return a<b?b:a>c?c:a};d.ClampV=function(a,b,c){return d.MaxV(b,d.MinV(a,c))};d.Swap=function(a,b){var c=a[0];a[0]=b[0];b[0]=c};d.Random=function(){return 2*Math.random()-1};d.RandomRange=function(a,b){void 0===a&&(a=0);void 0===b&&(b=0);var c=Math.random();return(b-a)*c+a};d.NextPowerOfTwo=function(a){void 0===a&&
(a=0);a|=a>>1&2147483647;a|=a>>2&1073741823;a|=a>>4&268435455;a|=a>>8&16777215;return(a|a>>16&65535)+1};d.IsPowerOfTwo=function(a){void 0===a&&(a=0);return 0<a&&0===(a&a-1)};d.b2Vec2_zero=new a(0,0);d.b2Mat22_identity=b.FromVV(new a(1,0),new a(0,1));d.b2Transform_identity=new c(d.b2Vec2_zero,d.b2Mat22_identity);var e=function(){this.e_aabbBit=4;this.e_centerOfMassBit=16;this.e_controllerBit=32;this.e_jointBit=2;this.e_pairBit=8;this.e_shapeBit=0};Box2D.Dynamics.b2DebugDraw=e;e.prototype.AppendFlags=
function(){};e.prototype.ClearFlags=function(){};e.prototype.DrawCircle=function(){};e.prototype.DrawPolygon=function(){};e.prototype.DrawSegment=function(){};e.prototype.DrawSolidCircle=function(){};e.prototype.DrawSolidPolygon=function(){};e.prototype.DrawTransform=function(){};e.prototype.GetAlpha=function(){};e.prototype.GetDrawScale=function(){};e.prototype.GetFillAlpha=function(){};e.prototype.GetFlags=function(){};e.prototype.GetLineThickness=function(){};e.prototype.GetSprite=function(){};
e.prototype.GetXFormScale=function(){};e.prototype.SetAlpha=function(){};e.prototype.SetDrawScale=function(){};e.prototype.SetFillAlpha=function(){};e.prototype.SetFlags=function(){};e.prototype.SetLineThickness=function(){};e.prototype.SetSprite=function(){};e.prototype.SetXFormScale=function(){};Box2D.Dynamics.b2BodyDef=function(){this.position=a.Get(0,0);this.linearVelocity=a.Get(0,0);this.userData=null;this.angle=0;this.linearVelocity.Set(0,0);this.angularDamping=this.linearDamping=this.angularVelocity=
0;this.awake=this.allowSleep=!0;this.bullet=this.fixedRotation=!1;this.type=f.b2_staticBody;this.active=!0;this.inertiaScale=1};var g=function(b,c,d,e){this.m_body=b;this.m_userData=c;this.m_fixtureID=d;this.m_shape={};this.m_shape.m_centroid=a.Get(0,0);this.m_isSensor=!1;this.m_density=e.density;this.m_friction=e.friction;this.m_restitution=e.restitution;this.m_isSensor=e.isSensor};Box2D.Dynamics.b2Fixture=g;g.prototype.GetBody=function(){return this.m_body};g.prototype.GetShape=function(){console.log("fixture.GetShape not yet supported in CocoonJS Box2D binding");
return null};g.prototype.GetUserData=function(){return this.m_userData};g.prototype.SetSensor=function(a){this.m_isSensor=a;window.ext.IDTK_SRV_BOX2D.makeCall("setSensor",this.m_body.m_world.m_worldID,this.m_fixtureID,this.m_isSensor)};g.prototype.IsSensor=function(){return this.m_isSensor};g.prototype.SetDensity=function(a){window.ext.IDTK_SRV_BOX2D.makeCall("setDensity",this.m_body.m_world.m_worldID,this.m_fixtureID,a);this.m_density=a};g.prototype.SetFriction=function(a){window.ext.IDTK_SRV_BOX2D.makeCall("setFriction",
this.m_body.m_world.m_worldID,this.m_fixtureID,a);this.m_friction=a};g.prototype.SetRestitution=function(a){window.ext.IDTK_SRV_BOX2D.makeCall("setRestitution",this.m_body.m_world.m_worldID,this.m_fixtureID,a);this.m_restitution=a};g.prototype.GetDensity=function(){return this.m_density};g.prototype.GetFriction=function(){return this.m_friction};g.prototype.GetRestitution=function(){return this.m_restitution};var f=function(a,d){var e=a.userData;a.userData=null;this.m_world=d;this.m_xf=new c(a.position,
b.FromAngle(a.angle));this.m_fixtures=[];this.m_active=a.active;a.type===f.b2_staticBody&&(a.density=0);this.m_bodyID=window.ext.IDTK_SRV_BOX2D.makeCall("createBody",d.m_worldID,a);this.m_userData=e;a.userData=e};Box2D.Dynamics.b2Body=f;f.prototype.CreateFixture=function(a){var b=a.userData;a.userData=null;var c=window.ext.IDTK_SRV_BOX2D.makeCall("createFixture",this.m_world.m_worldID,this.m_bodyID,a);a.userData=b;a=new g(this,b,c,a);this.m_world.m_fixturesList[c]=a;this.m_fixtures.push(a);return a};
f.prototype.GetFixtureList=function(){return 0===this.m_fixtures.length?null:this.m_fixtures[0]};f.prototype.DestroyFixture=function(a){window.ext.IDTK_SRV_BOX2D.makeCall("deleteFixture",this.m_world.m_worldID,a.m_fixtureID);delete this.m_world.m_fixturesList[a.m_fixtureID]};f.prototype.SetPositionAndAngle=function(a,b){window.ext.IDTK_SRV_BOX2D.makeCall("setBodyTransform",this.m_world.m_worldID,this.m_bodyID,a.x,a.y,b);this.m_xf.R.Set(b);this.m_xf.position.SetV(a)};f.prototype.GetPosition=function(){return this.m_xf.position};
f.prototype.SetPosition=function(a){this.SetPositionAndAngle(a,this.GetAngle())};f.prototype.GetLinearVelocity=function(){var b=window.ext.IDTK_SRV_BOX2D.makeCall("getLinearVelocity",this.m_world.m_worldID,this.m_bodyID);return a.Get(b[0],b[1])};f.prototype.GetWorldCenter=function(){var b=window.ext.IDTK_SRV_BOX2D.makeCall("getWorldCenter",this.m_world.m_worldID,this.m_bodyID);return a.Get(b[0],b[1])};f.prototype.GetLocalCenter=function(){var b=window.ext.IDTK_SRV_BOX2D.makeCall("getLocalCenter",
this.m_world.m_worldID,this.m_bodyID);return a.Get(b[0],b[1])};f.prototype.ApplyImpulse=function(a,b,c){window.ext.IDTK_SRV_BOX2D.makeCall("applyImpulse",this.m_world.m_worldID,this.m_bodyID,a.x,a.y,b.x,b.y,c)};f.prototype.IsAwake=function(){return window.ext.IDTK_SRV_BOX2D.makeCall("isAwake",this.m_world.m_worldID,this.m_bodyID)};f.prototype.GetAngularVelocity=function(){return window.ext.IDTK_SRV_BOX2D.makeCall("getAngularVelocity",this.m_world.m_worldID,this.m_bodyID)};f.prototype.SetAwake=function(a){window.ext.IDTK_SRV_BOX2D.makeCall("setAwake",
this.m_world.m_worldID,this.m_bodyID,a)};f.prototype.SetLinearVelocity=function(a){window.ext.IDTK_SRV_BOX2D.makeCall("setLinearVelocity",this.m_world.m_worldID,this.m_bodyID,a.x,a.y)};f.prototype.ApplyForceToCenter=function(a,b){window.ext.IDTK_SRV_BOX2D.makeCall("applyForceToCenter",this.m_world.m_worldID,this.m_bodyID,a.x,a.y,b)};f.prototype.ApplyForce=function(a,b,c){window.ext.IDTK_SRV_BOX2D.makeCall("applyForce",this.m_world.m_worldID,this.m_bodyID,a.x,a.y,b.x,b.y,c)};f.prototype.ApplyTorque=
function(a,b){window.ext.IDTK_SRV_BOX2D.makeCall("applyTorque",this.m_world.m_worldID,this.m_bodyID,a,b)};f.prototype.SetLinearDamping=function(a){window.ext.IDTK_SRV_BOX2D.makeCall("setLinearDamping",this.m_world.m_worldID,this.m_bodyID,a)};f.prototype.SetAngularVelocity=function(a){window.ext.IDTK_SRV_BOX2D.makeCall("setAngularVelocity",this.m_world.m_worldID,this.m_bodyID,a)};f.prototype.SetType=function(a){window.ext.IDTK_SRV_BOX2D.makeCall("setType",this.m_world.m_worldID,this.m_bodyID,a)};f.prototype.SetActive=
function(a){window.ext.IDTK_SRV_BOX2D.makeCall("setActive",this.m_world.m_worldID,this.m_bodyID,a);this.m_active=a};f.prototype.IsActive=function(){return this.m_active};f.prototype.GetAngle=function(){return this.m_xf.R.GetAngle()};f.prototype.SetAngle=function(a){void 0===a&&(a=0);this.SetPositionAndAngle(this.GetPosition(),a)};f.prototype.GetContactList=function(){for(var a=window.ext.IDTK_SRV_BOX2D.makeCall("getObjectContacts",this.m_world.m_worldID,this.m_bodyID),b=[],c=0;c<a.length;c++)b.push(this.m_world.m_bodyList[a[c]]);
return b};f.prototype.SetUserData=function(a){this.m_userData=a};f.prototype.GetUserData=function(){return this.m_userData};f.prototype.GetWorld=function(){return this.m_world};Box2D.Dynamics.b2Body.b2_staticBody=0;Box2D.Dynamics.b2Body.b2_kinematicBody=1;Box2D.Dynamics.b2Body.b2_dynamicBody=2;var l=function(a,b,c){this.m_fixtureA=a;this.m_fixtureB=b;this.m_touching=c};Box2D.Dynamics.b2Contact=l;l.prototype.GetFixtureA=function(){return this.m_fixtureA};l.prototype.GetFixtureB=function(){return this.m_fixtureB};
l.prototype.IsTouching=function(){return this.m_touching};e=function(){};Box2D.Dynamics.b2ContactListener=e;e.prototype.BeginContact=function(){};e.prototype.EndContact=function(){};e.prototype.PreSolve=function(){};e.prototype.PostSolve=function(){};Box2D.Dynamics.b2ContactListener.b2_defaultListener=new e;window.Box2D.Dynamics.b2ContactFilter=function(){};e=function(a,b){this.m_bodyList=[];this.m_jointList=[];this.m_fixturesList=[];this.m_contactListener=null;this.m_jointsList=[];this.m_worldID=
window.ext.IDTK_SRV_BOX2D.makeCall("createWorld",a.x,a.y,b)};Box2D.Dynamics.b2World=e;e.prototype.SetContactListener=function(a){this.m_contactListener=a};e.prototype.SetContactFilter=function(a){var b=this;window.ext.IDTK_SRV_BOX2D.makeCall("setContactFilter",function(c,d){return a.ShouldCollide(b.m_fixturesList[c],b.m_fixturesList[d])})};e.prototype.CreateBody=function(a){a=new f(a,this);return this.m_bodyList[a.m_bodyID]=a};e.prototype.DestroyBody=function(a){window.ext.IDTK_SRV_BOX2D.makeCall("deleteBody",
this.m_worldID,a.m_bodyID);delete this.m_bodyList[a.m_bodyID];for(var b=0;b<a.m_fixtures.length;++b)delete this.m_fixturesList[a.m_fixtures[b].m_fixtureID]};e.prototype.CreateJoint=function(a){if(a.bodyA.m_bodyID!==a.bodyB.m_bodyID){var b=a.bodyA,c=a.bodyB;a.bodyA=b.m_bodyID;a.bodyB=c.m_bodyID;window.ext.IDTK_SRV_BOX2D.makeCall("createDistanceJoint",this.m_worldID,a);a.bodyA=b;a.bodyB=c;a=new k(a);this.m_jointsList.push(a);return a}};e.prototype.GetJointList=function(){if(0===this.m_jointsList.length)return null;
for(var a=0;a<this.m_jointsList.length-1;++a)this.m_jointsList[a].next=this.m_jointsList[a+1];this.m_jointsList[this.m_jointsList.length-1].next=null;return this.m_jointsList[0]};e.prototype.SetContinuousPhysics=function(a){window.ext.IDTK_SRV_BOX2D.makeCall("setContinuous",this.m_worldID,a)};e.prototype.SetGravity=function(a){window.ext.IDTK_SRV_BOX2D.makeCall("setGravity",this.m_worldID,a.x,a.y)};e.prototype.Step=function(a,b,c){c=window.ext.IDTK_SRV_BOX2D.makeCall("step",this.m_worldID,a,b,c);
b=c[0];for(a=1;a<=4*b;a+=4){var d=this.m_bodyList[c[a+0]];if(null===d)break;d.m_xf.position.Set(c[a+1],c[a+2]);d.m_xf.R.Set(c[a+3])}if(null!==this.m_contactListener){c=window.ext.IDTK_SRV_BOX2D.makeCall("getLastContacts",this.m_worldID);b=c[0];for(a=1;a<=3*b;a+=3){var d=c[a+2],e=this.m_fixturesList[c[a+0]],f=this.m_fixturesList[c[a+1]];"undefined"===typeof e||"undefined"===typeof f?console.log("One of the fixtures in a contact DOESN'T EXIST!!"):this.m_contactListener.BeginContact(new l(e,f,d))}}};
e.prototype.ClearForces=function(){window.ext.IDTK_SRV_BOX2D.makeCall("clearForces",this.m_worldID)};e.prototype.SetDebugDraw=function(){};e.prototype.DrawDebugData=function(){};Box2D.Collision.Shapes.b2CircleShape=function(a){this.radius=a;this.type="circle"};Box2D.Collision.Shapes.b2PolygonShape=function(){};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsBox=function(a,b){this.type="box";this.width=a;this.height=b};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsEdge=function(a,b){this.type=
"edge";this.p1x=a.x;this.p1y=a.y;this.p2x=b.x;this.p2y=b.y};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsArray=function(a,b){this.type="polygon";this.vertices=[];for(var c=0;c<b;c++)this.vertices.push(a[c].x),this.vertices.push(a[c].y)};Box2D.Dynamics.b2FixtureDef=function(){this.userData=this.shape=null;this.friction=0.2;this.density=this.restitution=0;this.isSensor=!1;this.filter={categoryBits:1,maskBits:65535,groupIndex:0}};var k=function(a){this.bodyA=a.bodyA;this.bodyB=a.bodyB;this.userData=
a.userData;this.type=a.type;this.next=null};Box2D.Dynamics.Joints.b2Joint=k;k.prototype.GetBodyA=function(){return this.bodyA};k.prototype.GetBodyB=function(){return this.bodyB};k.prototype.GetUserData=function(){return this.userData};k.prototype.GetType=function(){return this.type};k.prototype.GetNext=function(){return this.next};k.e_distanceJoint=0;Box2D.Dynamics.Joints.b2DistanceJointDef=function(b,c,d,e){this.type=k.e_distanceJoint;this.localAnchorA=a.Get(0,0);this.localAnchorB=a.Get(0,0);this.userData=
null;void 0!==b&&(this.bodyA=b);void 0!==c&&(this.bodyB=c);void 0!==d&&this.localAnchorA.SetV(d);void 0!==e&&this.localAnchorB.SetV(e);void 0!==d&&void 0!==e&&(b=e.x-d.x,d=e.y-d.y,this.length=Math.sqrt(b*b+d*d));this.dampingRatio=this.frequencyHz=0}}();else{Box2D.Collision.b2Collision={};Box2D.Collision.b2Distance={};Box2D.Common.b2Settings={};Box2D.Common.Math.b2Math={};Box2D.Consts={};Box2D.Dynamics.Contacts={};Box2D.Dynamics.Controllers={};Box2D.generateCallback=function(a,b){return function(){b.apply(a,
arguments)}};Box2D.Consts.MIN_VALUE_SQUARED=Number.MIN_VALUE*Number.MIN_VALUE;Box2D.Common.b2Settings.b2MixFriction=function(a,b){return Math.sqrt(a*b)};Box2D.Common.b2Settings.b2MixRestitution=function(a,b){return a>b?a:b};Box2D.Common.b2Settings.VERSION="2.1alpha-illandril";Box2D.Common.b2Settings.USHRT_MAX=65535;Box2D.Common.b2Settings.b2_maxManifoldPoints=2;Box2D.Common.b2Settings.b2_aabbExtension=0.1;Box2D.Common.b2Settings.b2_aabbMultiplier=2;Box2D.Common.b2Settings.b2_polygonRadius=2*Box2D.Common.b2Settings.b2_linearSlop;
Box2D.Common.b2Settings.b2_linearSlop=0.005;Box2D.Common.b2Settings.b2_angularSlop=2/180*Math.PI;Box2D.Common.b2Settings.b2_toiSlop=8*Box2D.Common.b2Settings.b2_linearSlop;Box2D.Common.b2Settings.b2_maxTOIContactsPerIsland=32;Box2D.Common.b2Settings.b2_maxTOIJointsPerIsland=32;Box2D.Common.b2Settings.b2_velocityThreshold=1;Box2D.Common.b2Settings.b2_maxLinearCorrection=0.2;Box2D.Common.b2Settings.b2_maxAngularCorrection=8/180*Math.PI;Box2D.Common.b2Settings.b2_maxTranslation=2;Box2D.Common.b2Settings.b2_maxTranslationSquared=
Box2D.Common.b2Settings.b2_maxTranslation*Box2D.Common.b2Settings.b2_maxTranslation;Box2D.Common.b2Settings.b2_maxRotation=0.5*Math.PI;Box2D.Common.b2Settings.b2_maxRotationSquared=Box2D.Common.b2Settings.b2_maxRotation*Box2D.Common.b2Settings.b2_maxRotation;Box2D.Common.b2Settings.b2_contactBaumgarte=0.2;Box2D.Common.b2Settings.b2_timeToSleep=0.5;Box2D.Common.b2Settings.b2_linearSleepTolerance=0.01;Box2D.Common.b2Settings.b2_linearSleepToleranceSquared=Box2D.Common.b2Settings.b2_linearSleepTolerance*
Box2D.Common.b2Settings.b2_linearSleepTolerance;Box2D.Common.b2Settings.b2_angularSleepTolerance=2/180*Math.PI;Box2D.Common.b2Settings.b2_angularSleepToleranceSquared=Box2D.Common.b2Settings.b2_angularSleepTolerance*Box2D.Common.b2Settings.b2_angularSleepTolerance;Box2D.Common.b2Settings.MIN_VALUE_SQUARED=Number.MIN_VALUE*Number.MIN_VALUE;Box2D.Common.Math.b2Math.Dot=function(a,b){return a.x*b.x+a.y*b.y};Box2D.Common.Math.b2Math.CrossVV=function(a,b){return a.x*b.y-a.y*b.x};Box2D.Common.Math.b2Math.CrossVF=
function(a,b){return Box2D.Common.Math.b2Vec2.Get(b*a.y,-b*a.x)};Box2D.Common.Math.b2Math.CrossFV=function(a,b){return Box2D.Common.Math.b2Vec2.Get(-a*b.y,a*b.x)};Box2D.Common.Math.b2Math.MulMV=function(a,b){return Box2D.Common.Math.b2Vec2.Get(a.col1.x*b.x+a.col2.x*b.y,a.col1.y*b.x+a.col2.y*b.y)};Box2D.Common.Math.b2Math.MulTMV=function(a,b){return Box2D.Common.Math.b2Vec2.Get(Box2D.Common.Math.b2Math.Dot(b,a.col1),Box2D.Common.Math.b2Math.Dot(b,a.col2))};Box2D.Common.Math.b2Math.MulX=function(a,
b){var c=Box2D.Common.Math.b2Math.MulMV(a.R,b);c.x+=a.position.x;c.y+=a.position.y;return c};Box2D.Common.Math.b2Math.MulXT=function(a,b){var c=Box2D.Common.Math.b2Math.SubtractVV(b,a.position),d=c.x*a.R.col1.x+c.y*a.R.col1.y;c.y=c.x*a.R.col2.x+c.y*a.R.col2.y;c.x=d;return c};Box2D.Common.Math.b2Math.AddVV=function(a,b){return Box2D.Common.Math.b2Vec2.Get(a.x+b.x,a.y+b.y)};Box2D.Common.Math.b2Math.SubtractVV=function(a,b){return Box2D.Common.Math.b2Vec2.Get(a.x-b.x,a.y-b.y)};Box2D.Common.Math.b2Math.Distance=
function(a,b){return Math.sqrt(Box2D.Common.Math.b2Math.DistanceSquared(a,b))};Box2D.Common.Math.b2Math.DistanceSquared=function(a,b){var c=a.x-b.x,d=a.y-b.y;return c*c+d*d};Box2D.Common.Math.b2Math.MulFV=function(a,b){return Box2D.Common.Math.b2Vec2.Get(a*b.x,a*b.y)};Box2D.Common.Math.b2Math.AddMM=function(a,b){return Box2D.Common.Math.b2Mat22.FromVV(Box2D.Common.Math.b2Math.AddVV(a.col1,b.col1),Box2D.Common.Math.b2Math.AddVV(a.col2,b.col2))};Box2D.Common.Math.b2Math.MulMM=function(a,b){return Box2D.Common.Math.b2Mat22.FromVV(Box2D.Common.Math.b2Math.MulMV(a,
b.col1),Box2D.Common.Math.b2Math.MulMV(a,b.col2))};Box2D.Common.Math.b2Math.MulTMM=function(a,b){var c=Box2D.Common.Math.b2Vec2.Get(Box2D.Common.Math.b2Math.Dot(a.col1,b.col1),Box2D.Common.Math.b2Math.Dot(a.col2,b.col1)),d=Box2D.Common.Math.b2Vec2.Get(Box2D.Common.Math.b2Math.Dot(a.col1,b.col2),Box2D.Common.Math.b2Math.Dot(a.col2,b.col2));return Box2D.Common.Math.b2Mat22.FromVV(c,d)};Box2D.Common.Math.b2Math.AbsV=function(a){return Box2D.Common.Math.b2Vec2.Get(Math.abs(a.x),Math.abs(a.y))};Box2D.Common.Math.b2Math.AbsM=
function(a){return Box2D.Common.Math.b2Mat22.FromVV(Box2D.Common.Math.b2Math.AbsV(a.col1),Box2D.Common.Math.b2Math.AbsV(a.col2))};Box2D.Common.Math.b2Math.Clamp=function(a,b,c){return a<b?b:a>c?c:a};Box2D.Common.Math.b2Math.ClampV=function(a,b,c){var d=Box2D.Common.Math.b2Math.Clamp(a.x,b.x,c.x);a=Box2D.Common.Math.b2Math.Clamp(a.y,b.y,c.y);return Box2D.Common.Math.b2Vec2.Get(d,a)};Box2D.Common.Math.b2Mat22=function(){this.col1=Box2D.Common.Math.b2Vec2.Get(0,0);this.col2=Box2D.Common.Math.b2Vec2.Get(0,
0);this.SetIdentity()};Box2D.Common.Math.b2Mat22.FromAngle=function(a){var b=new Box2D.Common.Math.b2Mat22;b.Set(a);return b};Box2D.Common.Math.b2Mat22.FromVV=function(a,b){var c=new Box2D.Common.Math.b2Mat22;c.SetVV(a,b);return c};Box2D.Common.Math.b2Mat22.prototype.Set=function(a){var b=Math.cos(a);a=Math.sin(a);this.col1.Set(b,a);this.col2.Set(-a,b)};Box2D.Common.Math.b2Mat22.prototype.SetVV=function(a,b){this.col1.SetV(a);this.col2.SetV(b)};Box2D.Common.Math.b2Mat22.prototype.Copy=function(){var a=
new Box2D.Common.Math.b2Mat22;a.SetM(this);return a};Box2D.Common.Math.b2Mat22.prototype.SetM=function(a){this.col1.SetV(a.col1);this.col2.SetV(a.col2)};Box2D.Common.Math.b2Mat22.prototype.AddM=function(a){this.col1.Add(a.col1);this.col2.Add(a.col2)};Box2D.Common.Math.b2Mat22.prototype.SetIdentity=function(){this.col1.Set(1,0);this.col2.Set(0,1)};Box2D.Common.Math.b2Mat22.prototype.SetZero=function(){this.col1.Set(0,0);this.col2.Set(0,0)};Box2D.Common.Math.b2Mat22.prototype.GetAngle=function(){return Math.atan2(this.col1.y,
this.col1.x)};Box2D.Common.Math.b2Mat22.prototype.GetInverse=function(a){var b=this.col1.x*this.col2.y-this.col2.x*this.col1.y;0!==b&&(b=1/b);a.col1.x=b*this.col2.y;a.col2.x=-b*this.col2.x;a.col1.y=-b*this.col1.y;a.col2.y=b*this.col1.x;return a};Box2D.Common.Math.b2Mat22.prototype.Solve=function(a,b,c){var d=this.col1.x*this.col2.y-this.col2.x*this.col1.y;0!==d&&(d=1/d);a.x=d*(this.col2.y*b-this.col2.x*c);a.y=d*(this.col1.x*c-this.col1.y*b);return a};Box2D.Common.Math.b2Mat22.prototype.Abs=function(){this.col1.Abs();
this.col2.Abs()};Box2D.Common.Math.b2Mat33=function(a,b,c){this.col1=new Box2D.Common.Math.b2Vec3(0,0,0);this.col2=new Box2D.Common.Math.b2Vec3(0,0,0);this.col3=new Box2D.Common.Math.b2Vec3(0,0,0);a&&this.col1.SetV(a);b&&this.col2.SetV(b);c&&this.col3.SetV(c)};Box2D.Common.Math.b2Mat33.prototype.SetVVV=function(a,b,c){this.col1.SetV(a);this.col2.SetV(b);this.col3.SetV(c)};Box2D.Common.Math.b2Mat33.prototype.Copy=function(){return new Box2D.Common.Math.b2Mat33(this.col1,this.col2,this.col3)};Box2D.Common.Math.b2Mat33.prototype.SetM=
function(a){this.col1.SetV(a.col1);this.col2.SetV(a.col2);this.col3.SetV(a.col3)};Box2D.Common.Math.b2Mat33.prototype.AddM=function(a){this.col1.x+=a.col1.x;this.col1.y+=a.col1.y;this.col1.z+=a.col1.z;this.col2.x+=a.col2.x;this.col2.y+=a.col2.y;this.col2.z+=a.col2.z;this.col3.x+=a.col3.x;this.col3.y+=a.col3.y;this.col3.z+=a.col3.z};Box2D.Common.Math.b2Mat33.prototype.SetIdentity=function(){this.col1.Set(1,0,0);this.col2.Set(0,1,0);this.col3.Set(0,0,1)};Box2D.Common.Math.b2Mat33.prototype.SetZero=
function(){this.col1.Set(0,0,0);this.col2.Set(0,0,0);this.col3.Set(0,0,0)};Box2D.Common.Math.b2Mat33.prototype.Solve22=function(a,b,c){var d=this.col1.x,e=this.col2.x,g=this.col1.y,f=this.col2.y,l=d*f-e*g;0!=l&&(l=1/l);a.x=l*(f*b-e*c);a.y=l*(d*c-g*b);return a};Box2D.Common.Math.b2Mat33.prototype.Solve33=function(a,b,c,d){var e=this.col1.x,g=this.col1.y,f=this.col1.z,l=this.col2.x,k=this.col2.y,h=this.col2.z,m=this.col3.x,n=this.col3.y,q=this.col3.z,p=e*(k*q-h*n)+g*(h*m-l*q)+f*(l*n-k*m);0!=p&&(p=1/
p);a.x=p*(b*(k*q-h*n)+c*(h*m-l*q)+d*(l*n-k*m));a.y=p*(e*(c*q-d*n)+g*(d*m-b*q)+f*(b*n-c*m));a.z=p*(e*(k*d-h*c)+g*(h*b-l*d)+f*(l*c-k*b));return a};Box2D.Common.Math.b2Sweep=function(){this.localCenter=Box2D.Common.Math.b2Vec2.Get(0,0);this.c0=Box2D.Common.Math.b2Vec2.Get(0,0);this.c=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Common.Math.b2Sweep.prototype.Set=function(a){this.localCenter.SetV(a.localCenter);this.c0.SetV(a.c0);this.c.SetV(a.c);this.a0=a.a0;this.a=a.a;this.t0=a.t0};Box2D.Common.Math.b2Sweep.prototype.Copy=
function(){var a=new Box2D.Common.Math.b2Sweep;a.localCenter.SetV(this.localCenter);a.c0.SetV(this.c0);a.c.SetV(this.c);a.a0=this.a0;a.a=this.a;a.t0=this.t0;return a};Box2D.Common.Math.b2Sweep.prototype.GetTransform=function(a,b){void 0===b&&(b=0);a.position.x=(1-b)*this.c0.x+b*this.c.x;a.position.y=(1-b)*this.c0.y+b*this.c.y;a.R.Set((1-b)*this.a0+b*this.a);var c=a.R;a.position.x-=c.col1.x*this.localCenter.x+c.col2.x*this.localCenter.y;a.position.y-=c.col1.y*this.localCenter.x+c.col2.y*this.localCenter.y};
Box2D.Common.Math.b2Sweep.prototype.Advance=function(a){void 0===a&&(a=0);if(this.t0<a&&1-this.t0>Number.MIN_VALUE){var b=(a-this.t0)/(1-this.t0);this.c0.x=(1-b)*this.c0.x+b*this.c.x;this.c0.y=(1-b)*this.c0.y+b*this.c.y;this.a0=(1-b)*this.a0+b*this.a;this.t0=a}};Box2D.Common.Math.b2Transform=function(a,b){this.position=Box2D.Common.Math.b2Vec2.Get(0,0);this.R=new Box2D.Common.Math.b2Mat22;a&&this.position.SetV(a);b&&this.R.SetM(b)};Box2D.Common.Math.b2Transform.prototype.Initialize=function(a,b){this.position.SetV(a);
this.R.SetM(b)};Box2D.Common.Math.b2Transform.prototype.SetIdentity=function(){this.position.SetZero();this.R.SetIdentity()};Box2D.Common.Math.b2Transform.prototype.Set=function(a){this.position.SetV(a.position);this.R.SetM(a.R)};Box2D.Common.Math.b2Transform.prototype.GetAngle=function(){return Math.atan2(this.R.col1.y,this.R.col1.x)};Box2D.Common.Math.b2Vec2=function(a,b){this.x=a;this.y=b};Box2D.Common.Math.b2Vec2._freeCache=[];Box2D.Common.Math.b2Vec2.Get=function(a,b){if(0<Box2D.Common.Math.b2Vec2._freeCache.length){var c=
Box2D.Common.Math.b2Vec2._freeCache.pop();c.Set(a,b);return c}return new Box2D.Common.Math.b2Vec2(a,b)};Box2D.Common.Math.b2Vec2.Free=function(a){Box2D.Common.Math.b2Vec2._freeCache.push(a)};Box2D.Common.Math.b2Vec2.prototype.SetZero=function(){this.y=this.x=0};Box2D.Common.Math.b2Vec2.prototype.Set=function(a,b){this.x=a;this.y=b};Box2D.Common.Math.b2Vec2.prototype.SetV=function(a){this.x=a.x;this.y=a.y};Box2D.Common.Math.b2Vec2.prototype.GetNegative=function(){return Box2D.Common.Math.b2Vec2.Get(-this.x,
-this.y)};Box2D.Common.Math.b2Vec2.prototype.NegativeSelf=function(){this.x=-this.x;this.y=-this.y};Box2D.Common.Math.b2Vec2.prototype.Copy=function(){return Box2D.Common.Math.b2Vec2.Get(this.x,this.y)};Box2D.Common.Math.b2Vec2.prototype.Add=function(a){this.x+=a.x;this.y+=a.y};Box2D.Common.Math.b2Vec2.prototype.Subtract=function(a){this.x-=a.x;this.y-=a.y};Box2D.Common.Math.b2Vec2.prototype.Multiply=function(a){this.x*=a;this.y*=a};Box2D.Common.Math.b2Vec2.prototype.MulM=function(a){var b=this.x;
this.x=a.col1.x*b+a.col2.x*this.y;this.y=a.col1.y*b+a.col2.y*this.y};Box2D.Common.Math.b2Vec2.prototype.MulTM=function(a){var b=this.x*a.col1.x+this.y*a.col1.y;this.y=this.x*a.col2.x+this.y*a.col2.y;this.x=b};Box2D.Common.Math.b2Vec2.prototype.CrossVF=function(a){var b=this.x;this.x=a*this.y;this.y=-a*b};Box2D.Common.Math.b2Vec2.prototype.CrossFV=function(a){var b=this.x;this.x=-a*this.y;this.y=a*b};Box2D.Common.Math.b2Vec2.prototype.MinV=function(a){this.x=Math.min(this.x,a.x);this.y=Math.min(this.y,
a.y)};Box2D.Common.Math.b2Vec2.prototype.MaxV=function(a){this.x=Math.max(this.x,a.x);this.y=Math.max(this.y,a.y)};Box2D.Common.Math.b2Vec2.prototype.Abs=function(){this.x=Math.abs(this.x);this.y=Math.abs(this.y)};Box2D.Common.Math.b2Vec2.prototype.Length=function(){return Math.sqrt(this.LengthSquared())};Box2D.Common.Math.b2Vec2.prototype.LengthSquared=function(){return this.x*this.x+this.y*this.y};Box2D.Common.Math.b2Vec2.prototype.Normalize=function(){var a=this.Length();if(a<Number.MIN_VALUE)return 0;
var b=1/a;this.x*=b;this.y*=b;return a};Box2D.Common.Math.b2Vec2.prototype.IsValid=function(){return isFinite(this.x)&&isFinite(this.y)};Box2D.Common.Math.b2Vec3=function(a,b,c){this.x=a;this.y=b;this.z=c};Box2D.Common.Math.b2Vec3.prototype.SetZero=function(){this.z=this.y=this.x=0};Box2D.Common.Math.b2Vec3.prototype.Set=function(a,b,c){this.x=a;this.y=b;this.z=c};Box2D.Common.Math.b2Vec3.prototype.SetV=function(a){this.x=a.x;this.y=a.y;this.z=a.z};Box2D.Common.Math.b2Vec3.prototype.GetNegative=function(){return new Box2D.Common.Math.b2Vec3(-this.x,
-this.y,-this.z)};Box2D.Common.Math.b2Vec3.prototype.NegativeSelf=function(){this.x=-this.x;this.y=-this.y;this.z=-this.z};Box2D.Common.Math.b2Vec3.prototype.Copy=function(){return new Box2D.Common.Math.b2Vec3(this.x,this.y,this.z)};Box2D.Common.Math.b2Vec3.prototype.Add=function(a){this.x+=a.x;this.y+=a.y;this.z+=a.z};Box2D.Common.Math.b2Vec3.prototype.Subtract=function(a){this.x-=a.x;this.y-=a.y;this.z-=a.z};Box2D.Common.Math.b2Vec3.prototype.Multiply=function(a){this.x*=a;this.y*=a;this.z*=a};
Box2D.Collision.Shapes.b2Shape=function(){this.m_radius=Box2D.Common.b2Settings.b2_linearSlop};Box2D.Collision.Shapes.b2Shape.prototype.GetTypeName=function(){};Box2D.Collision.Shapes.b2Shape.prototype.Copy=function(){};Box2D.Collision.Shapes.b2Shape.prototype.Set=function(a){this.m_radius=a.m_radius};Box2D.Collision.Shapes.b2Shape.prototype.TestPoint=function(){};Box2D.Collision.Shapes.b2Shape.prototype.RayCast=function(){};Box2D.Collision.Shapes.b2Shape.prototype.ComputeAABB=function(){};Box2D.Collision.Shapes.b2Shape.prototype.ComputeMass=
function(){};Box2D.Collision.Shapes.b2Shape.prototype.ComputeSubmergedArea=function(){};Box2D.Collision.Shapes.b2Shape.prototype.SetDistanceProxy=function(){};Box2D.Collision.Shapes.b2Shape.TestOverlap=function(a,b,c,d){var e=new Box2D.Collision.b2DistanceInput;e.proxyA=new Box2D.Collision.b2DistanceProxy;e.proxyA.Set(a);e.proxyB=new Box2D.Collision.b2DistanceProxy;e.proxyB.Set(c);e.transformA=b;e.transformB=d;e.useRadii=!0;a=new Box2D.Collision.b2SimplexCache;a.count=0;b=new Box2D.Collision.b2DistanceOutput;
Box2D.Collision.b2Distance.Distance(b,a,e);return b.distance<10*Number.MIN_VALUE};Box2D.Collision.Shapes.b2Shape.e_startsInsideCollide=-1;Box2D.Collision.Shapes.b2Shape.e_missCollide=0;Box2D.Collision.Shapes.b2Shape.e_hitCollide=1;Box2D.Collision.Shapes.b2CircleShape=function(a){Box2D.Collision.Shapes.b2Shape.call(this);this.m_radius=a;this.m_radiusSquared=a*a;this.m_p=Box2D.Common.Math.b2Vec2.Get(0,0)};c2inherit(Box2D.Collision.Shapes.b2CircleShape,Box2D.Collision.Shapes.b2Shape);Box2D.Collision.Shapes.b2CircleShape.prototype.GetTypeName=
function(){return Box2D.Collision.Shapes.b2CircleShape.NAME};Box2D.Collision.Shapes.b2CircleShape.prototype.Copy=function(){var a=new Box2D.Collision.Shapes.b2CircleShape(this.m_radius);a.Set(this);return a};Box2D.Collision.Shapes.b2CircleShape.prototype.Set=function(a){Box2D.Collision.Shapes.b2Shape.prototype.Set.call(this,a);a instanceof Box2D.Collision.Shapes.b2CircleShape&&this.m_p.SetV(a.m_p)};Box2D.Collision.Shapes.b2CircleShape.prototype.TestPoint=function(a,b){var c=b.x-(a.position.x+(a.R.col1.x*
this.m_p.x+a.R.col2.x*this.m_p.y)),d=b.y-(a.position.y+(a.R.col1.y*this.m_p.x+a.R.col2.y*this.m_p.y));return c*c+d*d<=this.m_radiusSquared};Box2D.Collision.Shapes.b2CircleShape.prototype.RayCast=function(a,b,c){var d=c.R,e=b.p1.x-(c.position.x+(d.col1.x*this.m_p.x+d.col2.x*this.m_p.y));c=b.p1.y-(c.position.y+(d.col1.y*this.m_p.x+d.col2.y*this.m_p.y));var d=b.p2.x-b.p1.x,g=b.p2.y-b.p1.y,f=e*d+c*g,l=d*d+g*g,k=f*f-l*(e*e+c*c-this.m_radiusSquared);if(0>k||l<Number.MIN_VALUE)return!1;f=-(f+Math.sqrt(k));
return 0<=f&&f<=b.maxFraction*l?(f/=l,a.fraction=f,a.normal.x=e+f*d,a.normal.y=c+f*g,a.normal.Normalize(),!0):!1};Box2D.Collision.Shapes.b2CircleShape.prototype.ComputeAABB=function(a,b){var c=b.R,d=b.position.x+(c.col1.x*this.m_p.x+c.col2.x*this.m_p.y),c=b.position.y+(c.col1.y*this.m_p.x+c.col2.y*this.m_p.y);a.lowerBound_.Set(d-this.m_radius,c-this.m_radius);a.upperBound_.Set(d+this.m_radius,c+this.m_radius)};Box2D.Collision.Shapes.b2CircleShape.prototype.ComputeMass=function(a,b){a.mass=b*Math.PI*
this.m_radiusSquared;a.center.SetV(this.m_p);a.I=a.mass*(0.5*this.m_radiusSquared+(this.m_p.x*this.m_p.x+this.m_p.y*this.m_p.y))};Box2D.Collision.Shapes.b2CircleShape.prototype.ComputeSubmergedArea=function(a,b,c,d){c=Box2D.Common.Math.b2Math.MulX(c,this.m_p);var e=-(Box2D.Common.Math.b2Math.Dot(a,c)-b);if(e<-this.m_radius+Number.MIN_VALUE)return 0;if(e>this.m_radius)return d.SetV(c),Math.PI*this.m_radiusSquared;b=e*e;e=this.m_radiusSquared*(Math.asin(e/this.m_radius)+Math.PI/2)+e*Math.sqrt(this.m_radiusSquared-
b);b=-2/3*Math.pow(this.m_radiusSquared-b,1.5)/e;d.x=c.x+a.x*b;d.y=c.y+a.y*b;return e};Box2D.Collision.Shapes.b2CircleShape.prototype.SetDistanceProxy=function(a){a.m_vertices=[this.m_p];a.m_count=1;a.m_radius=this.m_radius};Box2D.Collision.Shapes.b2CircleShape.prototype.GetLocalPosition=function(){return this.m_p};Box2D.Collision.Shapes.b2CircleShape.prototype.SetLocalPosition=function(a){this.m_p.SetV(a)};Box2D.Collision.Shapes.b2CircleShape.prototype.GetRadius=function(){return this.m_radius};
Box2D.Collision.Shapes.b2CircleShape.prototype.SetRadius=function(a){this.m_radius=a;this.m_radiusSquared=a*a};Box2D.Collision.Shapes.b2CircleShape.NAME="b2CircleShape";Box2D.Collision.Shapes.b2EdgeChainDef=function(){this.vertexCount=0;this.isALoop=!0;this.vertices=[]};Box2D.Collision.Shapes.b2EdgeShape=function(a,b){Box2D.Collision.Shapes.b2Shape.call(this);this.m_nextEdge=this.m_prevEdge=null;this.m_v1=a;this.m_v2=b;this.m_direction=Box2D.Common.Math.b2Vec2.Get(this.m_v2.x-this.m_v1.x,this.m_v2.y-
this.m_v1.y);this.m_length=this.m_direction.Normalize();this.m_normal=Box2D.Common.Math.b2Vec2.Get(this.m_direction.y,-this.m_direction.x);this.m_coreV1=Box2D.Common.Math.b2Vec2.Get(-Box2D.Common.b2Settings.b2_toiSlop*(this.m_normal.x-this.m_direction.x)+this.m_v1.x,-Box2D.Common.b2Settings.b2_toiSlop*(this.m_normal.y-this.m_direction.y)+this.m_v1.y);this.m_coreV2=Box2D.Common.Math.b2Vec2.Get(-Box2D.Common.b2Settings.b2_toiSlop*(this.m_normal.x+this.m_direction.x)+this.m_v2.x,-Box2D.Common.b2Settings.b2_toiSlop*
(this.m_normal.y+this.m_direction.y)+this.m_v2.y);this.m_cornerDir1=this.m_normal;this.m_cornerDir2=Box2D.Common.Math.b2Vec2.Get(-this.m_normal.x,-this.m_normal.y);this.m_cornerConvex2=this.m_cornerConvex1=!1};c2inherit(Box2D.Collision.Shapes.b2EdgeShape,Box2D.Collision.Shapes.b2Shape);Box2D.Collision.Shapes.b2EdgeShape.prototype.GetTypeName=function(){return Box2D.Collision.Shapes.b2EdgeShape.NAME};Box2D.Collision.Shapes.b2EdgeShape.prototype.TestPoint=function(a,b){return!1};Box2D.Collision.Shapes.b2EdgeShape.prototype.RayCast=
function(a,b,c){var d=b.p2.x-b.p1.x,e=b.p2.y-b.p1.y,g=c.R,f=c.position.x+(g.col1.x*this.m_v1.x+g.col2.x*this.m_v1.y),l=c.position.y+(g.col1.y*this.m_v1.x+g.col2.y*this.m_v1.y),k=c.position.y+(g.col1.y*this.m_v2.x+g.col2.y*this.m_v2.y)-l;c=-(c.position.x+(g.col1.x*this.m_v2.x+g.col2.x*this.m_v2.y)-f);var g=100*Number.MIN_VALUE,h=-(d*k+e*c);if(h>g){var f=b.p1.x-f,m=b.p1.y-l,l=f*k+m*c;if(0<=l&&l<=b.maxFraction*h&&(b=-d*m+e*f,-g*h<=b&&b<=h*(1+g)))return a.fraction=l/h,b=Math.sqrt(k*k+c*c),a.normal.x=
k/b,a.normal.y=c/b,!0}return!1};Box2D.Collision.Shapes.b2EdgeShape.prototype.ComputeAABB=function(a,b){var c=b.R,d=b.position.x+(c.col1.x*this.m_v1.x+c.col2.x*this.m_v1.y),e=b.position.y+(c.col1.y*this.m_v1.x+c.col2.y*this.m_v1.y),g=b.position.x+(c.col1.x*this.m_v2.x+c.col2.x*this.m_v2.y),c=b.position.y+(c.col1.y*this.m_v2.x+c.col2.y*this.m_v2.y);d<g?(a.lowerBound_.x=d,a.upperBound_.x=g):(a.lowerBound_.x=g,a.upperBound_.x=d);e<c?(a.lowerBound_.y=e,a.upperBound_.y=c):(a.lowerBound_.y=c,a.upperBound_.y=
e)};Box2D.Collision.Shapes.b2EdgeShape.prototype.ComputeMass=function(a,b){a.mass=0;a.center.SetV(this.m_v1);a.I=0};Box2D.Collision.Shapes.b2EdgeShape.prototype.ComputeSubmergedArea=function(a,b,c,d){void 0===b&&(b=0);var e=Box2D.Common.Math.b2Vec2.Get(a.x*b,a.y*b),g=Box2D.Common.Math.b2Math.MulX(c,this.m_v1);c=Box2D.Common.Math.b2Math.MulX(c,this.m_v2);var f=Box2D.Common.Math.b2Math.Dot(a,g)-b;a=Box2D.Common.Math.b2Math.Dot(a,c)-b;if(0<f){if(0<a)return 0;g.x=-a/(f-a)*g.x+f/(f-a)*c.x;g.y=-a/(f-a)*
g.y+f/(f-a)*c.y}else 0<a&&(c.x=-a/(f-a)*g.x+f/(f-a)*c.x,c.y=-a/(f-a)*g.y+f/(f-a)*c.y);d.x=(e.x+g.x+c.x)/3;d.y=(e.y+g.y+c.y)/3;return 0.5*((g.x-e.x)*(c.y-e.y)-(g.y-e.y)*(c.x-e.x))};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetLength=function(){return this.m_length};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetVertex1=function(){return this.m_v1};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetVertex2=function(){return this.m_v2};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetCoreVertex1=function(){return this.m_coreV1};
Box2D.Collision.Shapes.b2EdgeShape.prototype.GetCoreVertex2=function(){return this.m_coreV2};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetNormalVector=function(){return this.m_normal};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetDirectionVector=function(){return this.m_direction};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetCorner1Vector=function(){return this.m_cornerDir1};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetCorner2Vector=function(){return this.m_cornerDir2};Box2D.Collision.Shapes.b2EdgeShape.prototype.Corner1IsConvex=
function(){return this.m_cornerConvex1};Box2D.Collision.Shapes.b2EdgeShape.prototype.Corner2IsConvex=function(){return this.m_cornerConvex2};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetFirstVertex=function(a){var b=a.R;return Box2D.Common.Math.b2Vec2.Get(a.position.x+(b.col1.x*this.m_coreV1.x+b.col2.x*this.m_coreV1.y),a.position.y+(b.col1.y*this.m_coreV1.x+b.col2.y*this.m_coreV1.y))};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetNextEdge=function(){return this.m_nextEdge};Box2D.Collision.Shapes.b2EdgeShape.prototype.GetPrevEdge=
function(){return this.m_prevEdge};Box2D.Collision.Shapes.b2EdgeShape.prototype.Support=function(a,b,c){var d=a.R,e=a.position.x+(d.col1.x*this.m_coreV1.x+d.col2.x*this.m_coreV1.y),g=a.position.y+(d.col1.y*this.m_coreV1.x+d.col2.y*this.m_coreV1.y),f=a.position.x+(d.col1.x*this.m_coreV2.x+d.col2.x*this.m_coreV2.y);a=a.position.y+(d.col1.y*this.m_coreV2.x+d.col2.y*this.m_coreV2.y);return e*b+g*c>f*b+a*c?Box2D.Common.Math.b2Vec2.Get(e,g):Box2D.Common.Math.b2Vec2.Get(f,a)};Box2D.Collision.Shapes.b2EdgeShape.prototype.SetPrevEdge=
function(a,b,c,d){this.m_prevEdge=a;this.m_coreV1=b;this.m_cornerDir1=c;this.m_cornerConvex1=d};Box2D.Collision.Shapes.b2EdgeShape.prototype.SetNextEdge=function(a,b,c,d){this.m_nextEdge=a;this.m_coreV2=b;this.m_cornerDir2=c;this.m_cornerConvex2=d};Box2D.Collision.Shapes.b2EdgeShape.NAME="b2EdgeShape";Box2D.Collision.Shapes.b2MassData=function(){this.mass=0;this.center=Box2D.Common.Math.b2Vec2.Get(0,0);this.I=0};Box2D.Collision.Shapes.b2PolygonShape=function(){Box2D.Collision.Shapes.b2Shape.call(this);
this.m_centroid=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_vertices=[];this.m_normals=[]};c2inherit(Box2D.Collision.Shapes.b2PolygonShape,Box2D.Collision.Shapes.b2Shape);Box2D.Collision.Shapes.b2PolygonShape.prototype.GetTypeName=function(){return Box2D.Collision.Shapes.b2PolygonShape.NAME};Box2D.Collision.Shapes.b2PolygonShape.prototype.Copy=function(){var a=new Box2D.Collision.Shapes.b2PolygonShape;a.Set(this);return a};Box2D.Collision.Shapes.b2PolygonShape.prototype.Set=function(a){Box2D.Collision.Shapes.b2Shape.prototype.Set.call(this,
a);if(a instanceof Box2D.Collision.Shapes.b2PolygonShape){this.m_centroid.SetV(a.m_centroid);this.m_vertexCount=a.m_vertexCount;this.Reserve(this.m_vertexCount);for(var b=0;b<this.m_vertexCount;b++)this.m_vertices[b].SetV(a.m_vertices[b]),this.m_normals[b].SetV(a.m_normals[b])}};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsArray=function(a){this.SetAsVector(a)};Box2D.Collision.Shapes.b2PolygonShape.AsArray=function(a){var b=new Box2D.Collision.Shapes.b2PolygonShape;b.SetAsArray(a);return b};
Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsVector=function(a){var b=a.length;this.m_vertexCount=b;this.Reserve(b);for(b=b=0;b<this.m_vertexCount;b++)this.m_vertices[b].SetV(a[b]);for(b=0;b<this.m_vertexCount;++b)a=Box2D.Common.Math.b2Math.SubtractVV(this.m_vertices[b+1<this.m_vertexCount?b+1:0],this.m_vertices[b]),this.m_normals[b].SetV(Box2D.Common.Math.b2Math.CrossVF(a,1)),this.m_normals[b].Normalize();this.m_centroid=Box2D.Collision.Shapes.b2PolygonShape.ComputeCentroid(this.m_vertices,
this.m_vertexCount)};Box2D.Collision.Shapes.b2PolygonShape.AsVector=function(a){var b=new Box2D.Collision.Shapes.b2PolygonShape;b.SetAsVector(a);return b};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsBox=function(a,b){this.m_vertexCount=4;this.Reserve(4);this.m_vertices[0].Set(-a,-b);this.m_vertices[1].Set(a,-b);this.m_vertices[2].Set(a,b);this.m_vertices[3].Set(-a,b);this.m_normals[0].Set(0,-1);this.m_normals[1].Set(1,0);this.m_normals[2].Set(0,1);this.m_normals[3].Set(-1,0);this.m_centroid.SetZero()};
Box2D.Collision.Shapes.b2PolygonShape.AsBox=function(a,b){var c=new Box2D.Collision.Shapes.b2PolygonShape;c.SetAsBox(a,b);return c};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsOrientedBox=function(a,b,c,d){this.m_vertexCount=4;this.Reserve(4);this.m_vertices[0].Set(-a,-b);this.m_vertices[1].Set(a,-b);this.m_vertices[2].Set(a,b);this.m_vertices[3].Set(-a,b);this.m_normals[0].Set(0,-1);this.m_normals[1].Set(1,0);this.m_normals[2].Set(0,1);this.m_normals[3].Set(-1,0);this.m_centroid=c;a=new Box2D.Common.Math.b2Mat22;
a.Set(d);c=new Box2D.Common.Math.b2Transform(c,a);for(d=0;d<this.m_vertexCount;++d)this.m_vertices[d]=Box2D.Common.Math.b2Math.MulX(c,this.m_vertices[d]),this.m_normals[d]=Box2D.Common.Math.b2Math.MulMV(c.R,this.m_normals[d])};Box2D.Collision.Shapes.b2PolygonShape.AsOrientedBox=function(a,b,c,d){var e=new Box2D.Collision.Shapes.b2PolygonShape;e.SetAsOrientedBox(a,b,c,d);return e};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetAsEdge=function(a,b){this.m_vertexCount=2;this.Reserve(2);this.m_vertices[0].SetV(a);
this.m_vertices[1].SetV(b);this.m_centroid.x=0.5*(a.x+b.x);this.m_centroid.y=0.5*(a.y+b.y);this.m_normals[0]=Box2D.Common.Math.b2Math.CrossVF(Box2D.Common.Math.b2Math.SubtractVV(b,a),1);this.m_normals[0].Normalize();this.m_normals[1].x=-this.m_normals[0].x;this.m_normals[1].y=-this.m_normals[0].y};Box2D.Collision.Shapes.b2PolygonShape.AsEdge=function(a,b){var c=new Box2D.Collision.Shapes.b2PolygonShape;c.SetAsEdge(a,b);return c};Box2D.Collision.Shapes.b2PolygonShape.prototype.TestPoint=function(a,
b){var c;c=a.R;for(var d=b.x-a.position.x,e=b.y-a.position.y,g=d*c.col1.x+e*c.col1.y,f=d*c.col2.x+e*c.col2.y,l=0;l<this.m_vertexCount;++l)if(c=this.m_vertices[l],d=g-c.x,e=f-c.y,c=this.m_normals[l],0<c.x*d+c.y*e)return!1;return!0};Box2D.Collision.Shapes.b2PolygonShape.prototype.RayCast=function(a,b,c){var d=0,e=b.maxFraction,g=0,f=0,l,k,g=b.p1.x-c.position.x,f=b.p1.y-c.position.y;l=c.R;var h=g*l.col1.x+f*l.col1.y,m=g*l.col2.x+f*l.col2.y,g=b.p2.x-c.position.x,f=b.p2.y-c.position.y;l=c.R;b=g*l.col1.x+
f*l.col1.y-h;l=g*l.col2.x+f*l.col2.y-m;for(var n=-1,q=0;q<this.m_vertexCount;++q){k=this.m_vertices[q];g=k.x-h;f=k.y-m;k=this.m_normals[q];g=k.x*g+k.y*f;f=k.x*b+k.y*l;if(0==f){if(0>g)return!1}else 0>f&&g<d*f?(d=g/f,n=q):0<f&&g<e*f&&(e=g/f);if(e<d-Number.MIN_VALUE)return!1}return 0<=n?(a.fraction=d,l=c.R,k=this.m_normals[n],a.normal.x=l.col1.x*k.x+l.col2.x*k.y,a.normal.y=l.col1.y*k.x+l.col2.y*k.y,!0):!1};Box2D.Collision.Shapes.b2PolygonShape.prototype.ComputeAABB=function(a,b){for(var c=b.R,d=this.m_vertices[0],
e=b.position.x+(c.col1.x*d.x+c.col2.x*d.y),g=b.position.y+(c.col1.y*d.x+c.col2.y*d.y),f=e,l=g,k=1;k<this.m_vertexCount;++k)var d=this.m_vertices[k],h=b.position.x+(c.col1.x*d.x+c.col2.x*d.y),d=b.position.y+(c.col1.y*d.x+c.col2.y*d.y),e=e<h?e:h,g=g<d?g:d,f=f>h?f:h,l=l>d?l:d;a.lowerBound_.x=e-this.m_radius;a.lowerBound_.y=g-this.m_radius;a.upperBound_.x=f+this.m_radius;a.upperBound_.y=l+this.m_radius};Box2D.Collision.Shapes.b2PolygonShape.prototype.ComputeMass=function(a,b){if(2==this.m_vertexCount)a.center.x=
0.5*(this.m_vertices[0].x+this.m_vertices[1].x),a.center.y=0.5*(this.m_vertices[0].y+this.m_vertices[1].y),a.mass=0,a.I=0;else{for(var c=0,d=0,e=0,g=0,f=1/3,l=0;l<this.m_vertexCount;++l)var k=this.m_vertices[l],h=l+1<this.m_vertexCount?this.m_vertices[l+1]:this.m_vertices[0],m=k.x-0,n=k.y-0,q=h.x-0,p=h.y-0,r=m*p-n*q,s=0.5*r,e=e+s,c=c+s*f*(0+k.x+h.x),d=d+s*f*(0+k.y+h.y),k=m,g=g+r*(f*(0.25*(k*k+q*k+q*q)+(0*k+0*q))+0+(f*(0.25*(n*n+p*n+p*p)+(0*n+0*p))+0));a.mass=b*e;a.center.Set(c*(1/e),d*(1/e));a.I=
b*g}};Box2D.Collision.Shapes.b2PolygonShape.prototype.ComputeSubmergedArea=function(a,b,c,d){var e=Box2D.Common.Math.b2Math.MulTMV(c.R,a),g=b-Box2D.Common.Math.b2Math.Dot(a,c.position),f=[],l=0,k=-1;b=-1;var h=!1;for(a=a=0;a<this.m_vertexCount;++a){f[a]=Box2D.Common.Math.b2Math.Dot(e,this.m_vertices[a])-g;var m=f[a]<-Number.MIN_VALUE;0<a&&(m?h||(k=a-1,l++):h&&(b=a-1,l++));h=m}switch(l){case 0:return h?(a=new Box2D.Collision.Shapes.b2MassData,this.ComputeMass(a,1),d.SetV(Box2D.Common.Math.b2Math.MulX(c,
a.center)),a.mass):0;case 1:-1==k?k=this.m_vertexCount-1:b=this.m_vertexCount-1}a=(k+1)%this.m_vertexCount;e=(b+1)%this.m_vertexCount;g=(0-f[k])/(f[a]-f[k]);f=(0-f[b])/(f[e]-f[b]);k=Box2D.Common.Math.b2Vec2.Get(this.m_vertices[k].x*(1-g)+this.m_vertices[a].x*g,this.m_vertices[k].y*(1-g)+this.m_vertices[a].y*g);b=Box2D.Common.Math.b2Vec2.Get(this.m_vertices[b].x*(1-f)+this.m_vertices[e].x*f,this.m_vertices[b].y*(1-f)+this.m_vertices[e].y*f);f=0;g=Box2D.Common.Math.b2Vec2.Get(0,0);for(l=this.m_vertices[a];a!=
e;)a=(a+1)%this.m_vertexCount,h=a==e?b:this.m_vertices[a],m=0.5*((l.x-k.x)*(h.y-k.y)-(l.y-k.y)*(h.x-k.x)),f+=m,g.x+=m*(k.x+l.x+h.x)/3,g.y+=m*(k.y+l.y+h.y)/3,l=h;g.Multiply(1/f);d.SetV(Box2D.Common.Math.b2Math.MulX(c,g));return f};Box2D.Collision.Shapes.b2PolygonShape.prototype.SetDistanceProxy=function(a){a.m_vertices=this.m_vertices;a.m_count=this.m_vertexCount;a.m_radius=this.m_radius};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetVertexCount=function(){return this.m_vertexCount};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetVertices=
function(){return this.m_vertices};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetNormals=function(){return this.m_normals};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetSupport=function(a){for(var b=0,c=this.m_vertices[0].x*a.x+this.m_vertices[0].y*a.y,d=1;d<this.m_vertexCount;++d){var e=this.m_vertices[d].x*a.x+this.m_vertices[d].y*a.y;e>c&&(b=d,c=e)}return b};Box2D.Collision.Shapes.b2PolygonShape.prototype.GetSupportVertex=function(a){for(var b=0,c=this.m_vertices[0].x*a.x+this.m_vertices[0].y*
a.y,d=1;d<this.m_vertexCount;++d){var e=this.m_vertices[d].x*a.x+this.m_vertices[d].y*a.y;e>c&&(b=d,c=e)}return this.m_vertices[b]};Box2D.Collision.Shapes.b2PolygonShape.prototype.Reserve=function(a){this.m_vertices=[];this.m_normals=[];for(var b=this.m_vertices.length;b<a;b++)this.m_vertices[b]=Box2D.Common.Math.b2Vec2.Get(0,0),this.m_normals[b]=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Collision.Shapes.b2PolygonShape.ComputeCentroid=function(a,b){for(var c=Box2D.Common.Math.b2Vec2.Get(0,0),d=0,e=
1/3,g=0;g<b;++g){var f=a[g],l=g+1<b?a[g+1]:a[0],k=0.5*((f.x-0)*(l.y-0)-(f.y-0)*(l.x-0)),d=d+k;c.x+=k*e*(0+f.x+l.x);c.y+=k*e*(0+f.y+l.y)}c.x*=1/d;c.y*=1/d;return c};Box2D.Collision.Shapes.b2PolygonShape.s_mat=new Box2D.Common.Math.b2Mat22;Box2D.Collision.Shapes.b2PolygonShape.NAME="b2PolygonShape";Box2D.Collision.b2ContactID=function(){this._incidentVertex=this._incidentEdge=this._referenceEdge=this._key=0};Box2D.Collision.b2ContactID.prototype.GetKey=function(){return this._key};Box2D.Collision.b2ContactID.prototype.SetKey=
function(a){this._key=a;this._referenceEdge=this._key&255;this._incidentEdge=(this._key&65280)>>8&255;this._incidentVertex=(this._key&16711680)>>16&255;this._flip=(this._key&4278190080)>>24&255};Box2D.Collision.b2ContactID.prototype.Set=function(a){this.SetKey(a._key)};Box2D.Collision.b2ContactID.prototype.SetReferenceEdge=function(a){this._referenceEdge=a;this._key=this._key&4294967040|this._referenceEdge&255};Box2D.Collision.b2ContactID.prototype.SetIncidentEdge=function(a){this._incidentEdge=a;
this._key=this._key&4294902015|this._incidentEdge<<8&65280};Box2D.Collision.b2ContactID.prototype.SetIncidentVertex=function(a){this._incidentVertex=a;this._key=this._key&4278255615|this._incidentVertex<<16&16711680};Box2D.Collision.b2ContactID.prototype.SetFlip=function(a){this._flip=a;this._key=this._key&16777215|this._flip<<24&4278190080};Box2D.Collision.b2ContactID.prototype.Copy=function(){var a=new Box2D.Collision.b2ContactID;a.Set(this);return a};Box2D.Collision.ClipVertex=function(){this.v=
Box2D.Common.Math.b2Vec2.Get(0,0);this.id=new Box2D.Collision.b2ContactID};Box2D.Collision.ClipVertex.prototype.Set=function(a){this.v.SetV(a.v);this.id.Set(a.id)};Box2D.Collision.IBroadPhase="Box2D.Collision.IBroadPhase";Box2D.Collision.b2AABB=function(){this.lowerBound_=Box2D.Common.Math.b2Vec2.Get(0,0);this.upperBound_=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Collision.b2AABB._freeCache=[];Box2D.Collision.b2AABB.Get=function(){if(0<Box2D.Collision.b2AABB._freeCache.length){var a=Box2D.Collision.b2AABB._freeCache.pop();
a.SetZero();return a}return new Box2D.Collision.b2AABB};Box2D.Collision.b2AABB.Free=function(a){Box2D.Collision.b2AABB._freeCache.push(a)};Box2D.Collision.b2AABB.prototype.SetZero=function(){this.lowerBound_.Set(0,0);this.upperBound_.Set(0,0)};Box2D.Collision.b2AABB.prototype.IsValid=function(){return 0>this.upperBound_.x-this.lowerBound_.x||0>this.upperBound_.y-this.lowerBound_.y?!1:this.lowerBound_.IsValid()&&this.upperBound_.IsValid()};Box2D.Collision.b2AABB.prototype.GetCenter=function(){return Box2D.Common.Math.b2Vec2.Get((this.lowerBound_.x+
this.upperBound_.x)/2,(this.lowerBound_.y+this.upperBound_.y)/2)};Box2D.Collision.b2AABB.prototype.SetCenter=function(a){var b=this.GetCenter();this.lowerBound_.Subtract(b);this.upperBound_.Subtract(b);this.lowerBound_.Add(a);this.upperBound_.Add(a);Box2D.Common.Math.b2Vec2.Free(b)};Box2D.Collision.b2AABB.prototype.GetExtents=function(){return Box2D.Common.Math.b2Vec2.Get((this.upperBound_.x-this.lowerBound_.x)/2,(this.upperBound_.y-this.lowerBound_.y)/2)};Box2D.Collision.b2AABB.prototype.Contains=
function(a){var b;return b=(b=(b=(b=this.lowerBound_.x<=a.lowerBound_.x)&&this.lowerBound_.y<=a.lowerBound_.y)&&a.upperBound_.x<=this.upperBound_.x)&&a.upperBound_.y<=this.upperBound_.y};Box2D.Collision.b2AABB.prototype.RayCast=function(a,b){var c=-Number.MAX_VALUE,d=Number.MAX_VALUE,e=b.p2.x-b.p1.x;if(Math.abs(e)<Number.MIN_VALUE){if(b.p1.x<this.lowerBound_.x||this.upperBound_.x<b.p1.x)return!1}else{var g=1/e,e=(this.lowerBound_.x-b.p1.x)*g,g=(this.upperBound_.x-b.p1.x)*g,f=-1;e>g&&(f=e,e=g,g=f,
f=1);e>c&&(a.normal.x=f,a.normal.y=0,c=e);d=Math.min(d,g);if(c>d)return!1}e=b.p2.y-b.p1.y;if(Math.abs(e)<Number.MIN_VALUE){if(b.p1.y<this.lowerBound_.y||this.upperBound_.y<b.p1.y)return!1}else if(g=1/e,e=(this.lowerBound_.y-b.p1.y)*g,g*=this.upperBound_.y-b.p1.y,f=-1,e>g&&(f=e,e=g,g=f,f=1),e>c&&(a.normal.y=f,a.normal.x=0,c=e),d=Math.min(d,g),c>d)return!1;a.fraction=c;return!0};Box2D.Collision.b2AABB.prototype.TestOverlap=function(a){return 0<a.lowerBound_.x-this.upperBound_.x||0<a.lowerBound_.y-this.upperBound_.y||
0<this.lowerBound_.x-a.upperBound_.x||0<this.lowerBound_.y-a.upperBound_.y?!1:!0};Box2D.Collision.b2AABB.Combine=function(a,b){var c=Box2D.Collision.b2AABB.Get();c.Combine(a,b);return c};Box2D.Collision.b2AABB.prototype.Combine=function(a,b){this.lowerBound_.x=Math.min(a.lowerBound_.x,b.lowerBound_.x);this.lowerBound_.y=Math.min(a.lowerBound_.y,b.lowerBound_.y);this.upperBound_.x=Math.max(a.upperBound_.x,b.upperBound_.x);this.upperBound_.y=Math.max(a.upperBound_.y,b.upperBound_.y)};Box2D.Collision.b2Collision.ClipSegmentToLine=
function(a,b,c,d){var e=0,g=b[0].v,f=b[1].v,l=c.x*g.x+c.y*g.y-d;c=c.x*f.x+c.y*f.y-d;0>=l&&a[e++].Set(b[0]);0>=c&&a[e++].Set(b[1]);0>l*c&&(c=l/(l-c),d=a[e].v,d.x=g.x+c*(f.x-g.x),d.y=g.y+c*(f.y-g.y),a[e].id=0<l?b[0].id:b[1].id,e++);return e};Box2D.Collision.b2Collision.EdgeSeparation=function(a,b,c,d,e){for(var g=b.R.col1.x*a.m_normals[c].x+b.R.col2.x*a.m_normals[c].y,f=b.R.col1.y*a.m_normals[c].x+b.R.col2.y*a.m_normals[c].y,l=e.R.col1.x*g+e.R.col1.y*f,k=e.R.col2.x*g+e.R.col2.y*f,h=0,m=Number.MAX_VALUE,
n=0;n<d.m_vertexCount;n++){var q=d.m_vertices[n].x*l+d.m_vertices[n].y*k;q<m&&(m=q,h=n)}return(e.position.x+(e.R.col1.x*d.m_vertices[h].x+e.R.col2.x*d.m_vertices[h].y)-(b.position.x+(b.R.col1.x*a.m_vertices[c].x+b.R.col2.x*a.m_vertices[c].y)))*g+(e.position.y+(e.R.col1.y*d.m_vertices[h].x+e.R.col2.y*d.m_vertices[h].y)-(b.position.y+(b.R.col1.y*a.m_vertices[c].x+b.R.col2.y*a.m_vertices[c].y)))*f};Box2D.Collision.b2Collision.FindMaxSeparation=function(a,b,c,d){for(var e=d.position.x+(d.R.col1.x*c.m_centroid.x+
d.R.col2.x*c.m_centroid.y),g=d.position.y+(d.R.col1.y*c.m_centroid.x+d.R.col2.y*c.m_centroid.y),e=e-(b.position.x+(b.R.col1.x*a.m_centroid.x+b.R.col2.x*a.m_centroid.y)),g=g-(b.position.y+(b.R.col1.y*a.m_centroid.x+b.R.col2.y*a.m_centroid.y)),f=e*b.R.col1.x+g*b.R.col1.y,g=e*b.R.col2.x+g*b.R.col2.y,e=0,l=-Number.MAX_VALUE,k=0;k<a.m_vertexCount;++k){var h=a.m_normals[k].x*f+a.m_normals[k].y*g;h>l&&(l=h,e=k)}f=Box2D.Collision.b2Collision.EdgeSeparation(a,b,e,c,d);g=e-1;0>g&&(g=a.m_vertexCount-1);l=Box2D.Collision.b2Collision.EdgeSeparation(a,
b,g,c,d);k=e+1;k>=a.m_vertexCount&&(k=0);var h=Box2D.Collision.b2Collision.EdgeSeparation(a,b,k,c,d),m=0,n=0;if(l>f&&l>h){m=g;for(n=l;;)if(e=m-1,0>e&&(e=a.m_vertexCount-1),f=Box2D.Collision.b2Collision.EdgeSeparation(a,b,e,c,d),f>n)m=e,n=f;else break}else if(h>f){m=k;for(n=h;;)if(e=m+1,e>=a.m_vertexCount&&(e=0),f=Box2D.Collision.b2Collision.EdgeSeparation(a,b,e,c,d),f>n)m=e,n=f;else break}else m=e,n=f;return{bestEdge:m,separation:n}};Box2D.Collision.b2Collision.FindIncidentEdge=function(a,b,c,d,e,
g){void 0===d&&(d=0);var f=c.R.col1.x*b.m_normals[d].x+c.R.col2.x*b.m_normals[d].y;b=c.R.col1.y*b.m_normals[d].x+c.R.col2.y*b.m_normals[d].y;c=g.R.col1.x*f+g.R.col1.y*b;b=g.R.col2.x*f+g.R.col2.y*b;f=c;c=0;for(var l=Number.MAX_VALUE,k=0;k<e.m_vertexCount;k++){var h=f*e.m_normals[k].x+b*e.m_normals[k].y;h<l&&(l=h,c=k)}f=c+1;f>=e.m_vertexCount&&(f=0);a[0].v.x=g.position.x+(g.R.col1.x*e.m_vertices[c].x+g.R.col2.x*e.m_vertices[c].y);a[0].v.y=g.position.y+(g.R.col1.y*e.m_vertices[c].x+g.R.col2.y*e.m_vertices[c].y);
a[0].id.SetReferenceEdge(d);a[0].id.SetIncidentEdge(c);a[0].id.SetIncidentVertex(0);a[1].v.x=g.position.x+(g.R.col1.x*e.m_vertices[f].x+g.R.col2.x*e.m_vertices[f].y);a[1].v.y=g.position.y+(g.R.col1.y*e.m_vertices[f].x+g.R.col2.y*e.m_vertices[f].y);a[1].id.SetReferenceEdge(d);a[1].id.SetIncidentEdge(f);a[1].id.SetIncidentVertex(1)};Box2D.Collision.b2Collision.MakeClipPointVector=function(){return[new Box2D.Collision.ClipVertex,new Box2D.Collision.ClipVertex]};Box2D.Collision.b2Collision.CollidePolygons=
function(a,b,c,d,e){a.m_pointCount=0;var g=b.m_radius+d.m_radius,f=Box2D.Collision.b2Collision.FindMaxSeparation(b,c,d,e),l=f.bestEdge;if(!(f.separation>g)){var k=Box2D.Collision.b2Collision.FindMaxSeparation(d,e,b,c);if(!(k.separation>g)){var h=b,m=d,n=c,q=e,p=0;a.m_type=Box2D.Collision.b2Manifold.e_faceA;k.separation>0.98*f.separation+0.001&&(h=d,m=b,n=e,q=c,l=k.bestEdge,a.m_type=Box2D.Collision.b2Manifold.e_faceB,p=1);b=Box2D.Collision.b2Collision.s_incidentEdge;Box2D.Collision.b2Collision.FindIncidentEdge(b,
h,n,l,m,q);m=h.m_vertices[l];l=l+1<h.m_vertexCount?h.m_vertices[l+1]:h.m_vertices[0];Box2D.Collision.b2Collision.s_localTangent.Set(l.x-m.x,l.y-m.y);Box2D.Collision.b2Collision.s_localTangent.Normalize();Box2D.Collision.b2Collision.s_localNormal.x=Box2D.Collision.b2Collision.s_localTangent.y;Box2D.Collision.b2Collision.s_localNormal.y=-Box2D.Collision.b2Collision.s_localTangent.x;Box2D.Collision.b2Collision.s_planePoint.Set(0.5*(m.x+l.x),0.5*(m.y+l.y));Box2D.Collision.b2Collision.s_tangent.x=n.R.col1.x*
Box2D.Collision.b2Collision.s_localTangent.x+n.R.col2.x*Box2D.Collision.b2Collision.s_localTangent.y;Box2D.Collision.b2Collision.s_tangent.y=n.R.col1.y*Box2D.Collision.b2Collision.s_localTangent.x+n.R.col2.y*Box2D.Collision.b2Collision.s_localTangent.y;Box2D.Collision.b2Collision.s_tangent2.x=-Box2D.Collision.b2Collision.s_tangent.x;Box2D.Collision.b2Collision.s_tangent2.y=-Box2D.Collision.b2Collision.s_tangent.y;Box2D.Collision.b2Collision.s_normal.x=Box2D.Collision.b2Collision.s_tangent.y;Box2D.Collision.b2Collision.s_normal.y=
-Box2D.Collision.b2Collision.s_tangent.x;Box2D.Collision.b2Collision.s_v11.x=n.position.x+(n.R.col1.x*m.x+n.R.col2.x*m.y);Box2D.Collision.b2Collision.s_v11.y=n.position.y+(n.R.col1.y*m.x+n.R.col2.y*m.y);Box2D.Collision.b2Collision.s_v12.x=n.position.x+(n.R.col1.x*l.x+n.R.col2.x*l.y);Box2D.Collision.b2Collision.s_v12.y=n.position.y+(n.R.col1.y*l.x+n.R.col2.y*l.y);if(!(2>Box2D.Collision.b2Collision.ClipSegmentToLine(Box2D.Collision.b2Collision.s_clipPoints1,b,Box2D.Collision.b2Collision.s_tangent2,
-Box2D.Collision.b2Collision.s_tangent.x*Box2D.Collision.b2Collision.s_v11.x-Box2D.Collision.b2Collision.s_tangent.y*Box2D.Collision.b2Collision.s_v11.y+g))&&!(2>Box2D.Collision.b2Collision.ClipSegmentToLine(Box2D.Collision.b2Collision.s_clipPoints2,Box2D.Collision.b2Collision.s_clipPoints1,Box2D.Collision.b2Collision.s_tangent,Box2D.Collision.b2Collision.s_tangent.x*Box2D.Collision.b2Collision.s_v12.x+Box2D.Collision.b2Collision.s_tangent.y*Box2D.Collision.b2Collision.s_v12.y+g))){a.m_localPlaneNormal.SetV(Box2D.Collision.b2Collision.s_localNormal);
a.m_localPoint.SetV(Box2D.Collision.b2Collision.s_planePoint);n=Box2D.Collision.b2Collision.s_normal.x*Box2D.Collision.b2Collision.s_v11.x+Box2D.Collision.b2Collision.s_normal.y*Box2D.Collision.b2Collision.s_v11.y;for(h=l=0;h<Box2D.Common.b2Settings.b2_maxManifoldPoints;++h)Box2D.Collision.b2Collision.s_normal.x*Box2D.Collision.b2Collision.s_clipPoints2[h].v.x+Box2D.Collision.b2Collision.s_normal.y*Box2D.Collision.b2Collision.s_clipPoints2[h].v.y-n<=g&&(m=Box2D.Collision.b2Collision.s_clipPoints2[h].v.x-
q.position.x,b=Box2D.Collision.b2Collision.s_clipPoints2[h].v.y-q.position.y,a.m_points[l].m_localPoint.x=m*q.R.col1.x+b*q.R.col1.y,a.m_points[l].m_localPoint.y=m*q.R.col2.x+b*q.R.col2.y,a.m_points[l].m_id.Set(Box2D.Collision.b2Collision.s_clipPoints2[h].id),a.m_points[l].m_id.SetFlip(p),l++);a.m_pointCount=l}}}};Box2D.Collision.b2Collision.CollideCircles=function(a,b,c,d,e){a.m_pointCount=0;var g=e.position.x+(e.R.col1.x*d.m_p.x+e.R.col2.x*d.m_p.y)-(c.position.x+(c.R.col1.x*b.m_p.x+c.R.col2.x*b.m_p.y));
c=e.position.y+(e.R.col1.y*d.m_p.x+e.R.col2.y*d.m_p.y)-(c.position.y+(c.R.col1.y*b.m_p.x+c.R.col2.y*b.m_p.y));e=b.m_radius+d.m_radius;g*g+c*c>e*e||(a.m_type=Box2D.Collision.b2Manifold.e_circles,a.m_localPoint.SetV(b.m_p),a.m_localPlaneNormal.SetZero(),a.m_pointCount=1,a.m_points[0].m_localPoint.SetV(d.m_p),a.m_points[0].m_id.SetKey(0))};Box2D.Collision.b2Collision.CollidePolygonAndCircle=function(a,b,c,d,e){a.m_pointCount=0;var g=e.position.x+(e.R.col1.x*d.m_p.x+e.R.col2.x*d.m_p.y)-c.position.x,f=
e.position.y+(e.R.col1.y*d.m_p.x+e.R.col2.y*d.m_p.y)-c.position.y;e=g*c.R.col1.x+f*c.R.col1.y;c=g*c.R.col2.x+f*c.R.col2.y;for(var g=0,f=-Number.MAX_VALUE,l=b.m_radius+d.m_radius,k=0;k<b.m_vertexCount;++k){var h=b.m_normals[k].x*(e-b.m_vertices[k].x)+b.m_normals[k].y*(c-b.m_vertices[k].y);if(h>l)return;h>f&&(f=h,g=k)}h=g+1;h>=b.m_vertexCount&&(h=0);var k=b.m_vertices[g],m=b.m_vertices[h];f<Number.MIN_VALUE?(a.m_pointCount=1,a.m_type=Box2D.Collision.b2Manifold.e_faceA,a.m_localPlaneNormal.SetV(b.m_normals[g]),
a.m_localPoint.x=0.5*(k.x+m.x),a.m_localPoint.y=0.5*(k.y+m.y),a.m_points[0].m_localPoint.SetV(d.m_p),a.m_points[0].m_id.SetKey(0)):0>=(e-k.x)*(m.x-k.x)+(c-k.y)*(m.y-k.y)?(e-k.x)*(e-k.x)+(c-k.y)*(c-k.y)>l*l||(a.m_pointCount=1,a.m_type=Box2D.Collision.b2Manifold.e_faceA,a.m_localPlaneNormal.x=e-k.x,a.m_localPlaneNormal.y=c-k.y,a.m_localPlaneNormal.Normalize(),a.m_localPoint.SetV(k),a.m_points[0].m_localPoint.SetV(d.m_p),a.m_points[0].m_id.SetKey(0)):0>=(e-m.x)*(k.x-m.x)+(c-m.y)*(k.y-m.y)?(e-m.x)*(e-
m.x)+(c-m.y)*(c-m.y)>l*l||(a.m_pointCount=1,a.m_type=Box2D.Collision.b2Manifold.e_faceA,a.m_localPlaneNormal.x=e-m.x,a.m_localPlaneNormal.y=c-m.y,a.m_localPlaneNormal.Normalize(),a.m_localPoint.SetV(m),a.m_points[0].m_localPoint.SetV(d.m_p),a.m_points[0].m_id.SetKey(0)):(h=0.5*(k.x+m.x),k=0.5*(k.y+m.y),f=(e-h)*b.m_normals[g].x+(c-k)*b.m_normals[g].y,f>l||(a.m_pointCount=1,a.m_type=Box2D.Collision.b2Manifold.e_faceA,a.m_localPlaneNormal.x=b.m_normals[g].x,a.m_localPlaneNormal.y=b.m_normals[g].y,a.m_localPlaneNormal.Normalize(),
a.m_localPoint.Set(h,k),a.m_points[0].m_localPoint.SetV(d.m_p),a.m_points[0].m_id.SetKey(0)))};Box2D.Collision.b2Collision.TestOverlap=function(a,b){return 0<b.lowerBound_.x-a.upperBound_.x||0<b.lowerBound_.y-a.upperBound_.y||0<a.lowerBound_.x-b.upperBound_.x||0<a.lowerBound_.y-b.upperBound_.y?!1:!0};Box2D.Collision.b2ContactPoint=function(){this.position=Box2D.Common.Math.b2Vec2.Get(0,0);this.velocity=Box2D.Common.Math.b2Vec2.Get(0,0);this.normal=Box2D.Common.Math.b2Vec2.Get(0,0);this.id=new Box2D.Collision.b2ContactID};
Box2D.Collision.b2Distance.Distance=function(a,b,c){var d=new Box2D.Collision.b2Simplex;d.ReadCache(b,c.proxyA,c.transformA,c.proxyB,c.transformB);for(var e=0;20>e;){for(var g=[],f=0;f<d.m_count;f++)g[f]={},g[f].indexA=d.m_vertices[f].indexA,g[f].indexB=d.m_vertices[f].indexB;2==d.m_count?d.Solve2():3==d.m_count&&d.Solve3();if(3==d.m_count)break;f=d.GetSearchDirection();if(f.LengthSquared()<Box2D.Common.b2Settings.MIN_VALUE_SQUARED)break;var l=f.GetNegative();d.m_vertices[d.m_count].indexA=c.proxyA.GetSupport(Box2D.Common.Math.b2Math.MulTMV(c.transformA.R,
l));d.m_vertices[d.m_count].wA=Box2D.Common.Math.b2Math.MulX(c.transformA,c.proxyA.GetVertex(d.m_vertices[d.m_count].indexA));d.m_vertices[d.m_count].indexB=c.proxyB.GetSupport(Box2D.Common.Math.b2Math.MulTMV(c.transformB.R,f));d.m_vertices[d.m_count].wB=Box2D.Common.Math.b2Math.MulX(c.transformB,c.proxyB.GetVertex(d.m_vertices[d.m_count].indexB));d.m_vertices[d.m_count].w=Box2D.Common.Math.b2Math.SubtractVV(d.m_vertices[d.m_count].wB,d.m_vertices[d.m_count].wA);Box2D.Common.Math.b2Vec2.Free(f);Box2D.Common.Math.b2Vec2.Free(l);
e++;l=!1;for(f=0;f<g.length;f++)if(d.m_vertices[d.m_count].indexA==g[f].indexA&&d.m_vertices[d.m_count].indexB==g[f].indexB){l=!0;break}if(l)break;d.m_count++}d.GetWitnessPoints(a.pointA,a.pointB);a.distance=Box2D.Common.Math.b2Math.SubtractVV(a.pointA,a.pointB).Length();d.WriteCache(b);c.useRadii&&(b=c.proxyA.m_radius,c=c.proxyB.m_radius,a.distance>b+c&&a.distance>Number.MIN_VALUE?(a.distance-=b+c,d=Box2D.Common.Math.b2Math.SubtractVV(a.pointB,a.pointA),d.Normalize(),a.pointA.x+=b*d.x,a.pointA.y+=
b*d.y,a.pointB.x-=c*d.x,a.pointB.y-=c*d.y,Box2D.Common.Math.b2Vec2.Free(d)):(c=Box2D.Common.Math.b2Vec2.Get(0,0),c.x=0.5*(a.pointA.x+a.pointB.x),c.y=0.5*(a.pointA.y+a.pointB.y),a.pointA.x=a.pointB.x=c.x,a.pointA.y=a.pointB.y=c.y,a.distance=0,Box2D.Common.Math.b2Vec2.Free(c)))};Box2D.Collision.b2DistanceInput=function(){};Box2D.Collision.b2DistanceOutput=function(){this.pointA=Box2D.Common.Math.b2Vec2.Get(0,0);this.pointB=Box2D.Common.Math.b2Vec2.Get(0,0);this.distance=0};Box2D.Collision.b2DistanceProxy=
function(){};Box2D.Collision.b2DistanceProxy.prototype.Set=function(a){a.SetDistanceProxy(this)};Box2D.Collision.b2DistanceProxy.prototype.GetSupport=function(a){for(var b=0,c=this.m_vertices[0].x*a.x+this.m_vertices[0].y*a.y,d=1;d<this.m_count;d++){var e=this.m_vertices[d].x*a.x+this.m_vertices[d].y*a.y;e>c&&(b=d,c=e)}return b};Box2D.Collision.b2DistanceProxy.prototype.GetSupportVertex=function(a){return this.m_vertices[this.GetSupport(a)]};Box2D.Collision.b2DistanceProxy.prototype.GetVertexCount=
function(){return this.m_count};Box2D.Collision.b2DistanceProxy.prototype.GetVertex=function(a){void 0===a&&(a=0);return this.m_vertices[a]};Box2D.Collision.b2DynamicTree=function(){this.m_root=null;this.m_insertionCount=this.m_path=0};Box2D.Collision.b2DynamicTree.prototype.CreateProxy=function(a,b){var c=Box2D.Collision.b2DynamicTreeNode.Get(b),d=Box2D.Common.b2Settings.b2_aabbExtension,e=Box2D.Common.b2Settings.b2_aabbExtension;c.aabb.lowerBound_.x=a.lowerBound_.x-d;c.aabb.lowerBound_.y=a.lowerBound_.y-
e;c.aabb.upperBound_.x=a.upperBound_.x+d;c.aabb.upperBound_.y=a.upperBound_.y+e;this.InsertLeaf(c);return c};Box2D.Collision.b2DynamicTree.prototype.DestroyProxy=function(a){this.RemoveLeaf(a);a.Destroy()};Box2D.Collision.b2DynamicTree.prototype.MoveProxy=function(a,b,c){if(a.aabb.Contains(b))return!1;this.RemoveLeaf(a);var d=Box2D.Common.b2Settings.b2_aabbExtension+Box2D.Common.b2Settings.b2_aabbMultiplier*Math.abs(c.x);c=Box2D.Common.b2Settings.b2_aabbExtension+Box2D.Common.b2Settings.b2_aabbMultiplier*
Math.abs(c.y);a.aabb.lowerBound_.x=b.lowerBound_.x-d;a.aabb.lowerBound_.y=b.lowerBound_.y-c;a.aabb.upperBound_.x=b.upperBound_.x+d;a.aabb.upperBound_.y=b.upperBound_.y+c;this.InsertLeaf(a);return!0};Box2D.Collision.b2DynamicTree.prototype.Rebalance=function(a){if(null!==this.m_root)for(var b=0;b<a;b++){for(var c=this.m_root,d=0;!c.IsLeaf();)c=this.m_path>>d&1?c.child2:c.child1,d=d+1&31;this.m_path++;this.RemoveLeaf(c);this.InsertLeaf(c)}};Box2D.Collision.b2DynamicTree.prototype.GetFatAABB=function(a){return a.aabb};
Box2D.Collision.b2DynamicTree.prototype.Query=function(a,b){if(null!==this.m_root){var c=[];for(c.push(this.m_root);0<c.length;){var d=c.pop();if(d.aabb.TestOverlap(b))if(d.IsLeaf()){if(!a(d.fixture))break}else c.push(d.child1),c.push(d.child2)}}};Box2D.Collision.b2DynamicTree.prototype.RayCast=function(a,b){if(null!==this.m_root){var c=Box2D.Common.Math.b2Math.SubtractVV(b.p1,b.p2);c.Normalize();var c=Box2D.Common.Math.b2Math.CrossFV(1,c),d=Box2D.Common.Math.b2Math.AbsV(c),e=b.maxFraction,g=b.p1.x+
e*(b.p2.x-b.p1.x),e=b.p1.y+e*(b.p2.y-b.p1.y),f=Box2D.Collision.b2AABB.Get();f.lowerBound_.x=Math.min(b.p1.x,g);f.lowerBound_.y=Math.min(b.p1.y,e);f.upperBound_.x=Math.max(b.p1.x,g);f.upperBound_.y=Math.max(b.p1.y,e);var l=[];for(l.push(this.m_root);0<l.length;)if(g=l.pop(),g.aabb.TestOverlap(f)){var e=g.aabb.GetCenter(),k=g.aabb.GetExtents();if(!(0<Math.abs(c.x*(b.p1.x-e.x)+c.y*(b.p1.y-e.y))-d.x*k.x-d.y*k.y))if(g.IsLeaf()){new Box2D.Collision.b2RayCastInput(b.p1,b.p2,b.maxFraction);e=a(b,g.fixture);
if(0==e)break;0<e&&(g=b.p1.x+e*(b.p2.x-b.p1.x),e=b.p1.y+e*(b.p2.y-b.p1.y),f.lowerBound_.x=Math.min(b.p1.x,g),f.lowerBound_.y=Math.min(b.p1.y,e),f.upperBound_.x=Math.max(b.p1.x,g),f.upperBound_.y=Math.max(b.p1.y,e))}else l.push(g.child1),l.push(g.child2)}Box2D.Collision.b2AABB.Free(f)}};Box2D.Collision.b2DynamicTree.prototype.InsertLeaf=function(a){this.m_insertionCount++;if(null===this.m_root)this.m_root=a,this.m_root.parent=null;else{var b=this.GetBestSibling(a),c=b.parent,d=Box2D.Collision.b2DynamicTreeNode.Get();
d.parent=c;d.aabb.Combine(a.aabb,b.aabb);if(c){b.parent.child1==b?c.child1=d:c.child2=d;d.child1=b;d.child2=a;b.parent=d;for(a.parent=d;c&&!c.aabb.Contains(d.aabb);)c.aabb.Combine(c.child1.aabb,c.child2.aabb),d=c,c=c.parent}else d.child1=b,d.child2=a,b.parent=d,this.m_root=a.parent=d}};Box2D.Collision.b2DynamicTree.prototype.GetBestSibling=function(a){a=a.aabb.GetCenter();for(var b=this.m_root;!b.IsLeaf();)var c=b.child1,b=b.child2,d=Math.abs((c.aabb.lowerBound_.x+c.aabb.upperBound_.x)/2-a.x)+Math.abs((c.aabb.lowerBound_.y+
c.aabb.upperBound_.y)/2-a.y),e=Math.abs((b.aabb.lowerBound_.x+b.aabb.upperBound_.x)/2-a.x)+Math.abs((b.aabb.lowerBound_.y+b.aabb.upperBound_.y)/2-a.y),b=d<e?c:b;Box2D.Common.Math.b2Vec2.Free(a);return b};Box2D.Collision.b2DynamicTree.prototype.RemoveLeaf=function(a){if(a==this.m_root)this.m_root=null;else{var b=a.parent,c=b.parent;a=b.child1==a?b.child2:b.child1;if(c){c.child1==b?c.child1=a:c.child2=a;for(a.parent=c;c;){a=c.aabb;c.aabb.Combine(c.child1.aabb,c.child2.aabb);if(a.Contains(c.aabb))break;
c=c.parent}}else this.m_root=a,a.parent=null;b.Destroy()}};Box2D.Collision.b2DynamicTreeBroadPhase=function(){this.m_tree=new Box2D.Collision.b2DynamicTree;this.m_moveBuffer=[]};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.CreateProxy=function(a,b){var c=this.m_tree.CreateProxy(a,b);this.BufferMove(c);return c};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.DestroyProxy=function(a){this.UnBufferMove(a);this.m_tree.DestroyProxy(a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.MoveProxy=
function(a,b,c){this.m_tree.MoveProxy(a,b,c)&&this.BufferMove(a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.TestOverlap=function(a,b){var c=this.m_tree.GetFatAABB(a),d=this.m_tree.GetFatAABB(b);return c.TestOverlap(d)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.GetFatAABB=function(a){return this.m_tree.GetFatAABB(a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.GetProxyCount=function(){return this.m_tree.length};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.UpdatePairs=function(a){for(var b=
[];0<this.m_moveBuffer.length;){var c=this.m_moveBuffer.pop(),d=this.m_tree.GetFatAABB(c);this.m_tree.Query(function(a){a!=c.fixture&&b.push(new Box2D.Collision.b2DynamicTreePair(c.fixture,a));return!0},d)}for(d=0;d<b.length;){var e=b[d];a(e.fixtureA,e.fixtureB);for(d++;d<b.length;){var g=b[d];if(!(g.fixtureA==e.fixtureA&&g.fixtureB==e.fixtureB)&&!(g.fixtureA==e.fixtureB&&g.fixtureB==e.fixtureA))break;d++}}};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.Query=function(a,b){this.m_tree.Query(a,
b)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.RayCast=function(a,b){this.m_tree.RayCast(a,b)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.Rebalance=function(a){this.m_tree.Rebalance(a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.BufferMove=function(a){this.m_moveBuffer.push(a)};Box2D.Collision.b2DynamicTreeBroadPhase.prototype.UnBufferMove=function(a){cr.arrayFindRemove(this.m_moveBuffer,a)};Box2D.Collision.b2DynamicTreeBroadPhase.__implements={};Box2D.Collision.b2DynamicTreeBroadPhase.__implements[Box2D.Collision.IBroadPhase]=
!0;Box2D.Collision.b2DynamicTreeNode=function(a){this.aabb=Box2D.Collision.b2AABB.Get();this.fixture=this.parent=this.child2=this.child1=null;"undefined"!=typeof a&&(this.fixture=a)};Box2D.Collision.b2DynamicTreeNode._freeCache=[];Box2D.Collision.b2DynamicTreeNode.Get=function(a){if(0<Box2D.Collision.b2DynamicTreeNode._freeCache.length){var b=Box2D.Collision.b2DynamicTreeNode._freeCache.pop();"undefined"!=typeof a&&(b.fixture=a);b.aabb.SetZero();return b}return new Box2D.Collision.b2DynamicTreeNode(a)};
Box2D.Collision.b2DynamicTreeNode.prototype.Destroy=function(){this.fixture=this.parent=this.child2=this.child1=null;Box2D.Collision.b2DynamicTreeNode._freeCache.push(this)};Box2D.Collision.b2DynamicTreeNode.prototype.IsLeaf=function(){return null===this.child1};Box2D.Collision.b2DynamicTreePair=function(a,b){this.fixtureA=a;this.fixtureB=b};Box2D.Collision.b2Manifold=function(){this.m_type=this.m_pointCount=0;this.m_points=[];for(var a=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++)this.m_points[a]=
new Box2D.Collision.b2ManifoldPoint;this.m_localPlaneNormal=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localPoint=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Collision.b2Manifold.prototype.Reset=function(){for(var a=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++)this.m_points[a].Reset();this.m_localPlaneNormal.SetZero();this.m_localPoint.SetZero();this.m_pointCount=this.m_type=0};Box2D.Collision.b2Manifold.prototype.Set=function(a){this.m_pointCount=a.m_pointCount;for(var b=0;b<Box2D.Common.b2Settings.b2_maxManifoldPoints;b++)this.m_points[b].Set(a.m_points[b]);
this.m_localPlaneNormal.SetV(a.m_localPlaneNormal);this.m_localPoint.SetV(a.m_localPoint);this.m_type=a.m_type};Box2D.Collision.b2Manifold.prototype.Copy=function(){var a=new Box2D.Collision.b2Manifold;a.Set(this);return a};Box2D.Collision.b2Manifold.e_circles=1;Box2D.Collision.b2Manifold.e_faceA=2;Box2D.Collision.b2Manifold.e_faceB=4;Box2D.Collision.b2ManifoldPoint=function(){this.m_localPoint=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_id=new Box2D.Collision.b2ContactID;this.Reset()};Box2D.Collision.b2ManifoldPoint.prototype.Reset=
function(){this.m_localPoint.SetZero();this.m_tangentImpulse=this.m_normalImpulse=0;this.m_id.SetKey(0)};Box2D.Collision.b2ManifoldPoint.prototype.Set=function(a){this.m_localPoint.SetV(a.m_localPoint);this.m_normalImpulse=a.m_normalImpulse;this.m_tangentImpulse=a.m_tangentImpulse;this.m_id.Set(a.m_id)};Box2D.Collision.b2RayCastInput=function(a,b,c){this.p1=Box2D.Common.Math.b2Vec2.Get(0,0);this.p2=Box2D.Common.Math.b2Vec2.Get(0,0);void 0===c&&(c=1);a&&this.p1.SetV(a);b&&this.p2.SetV(b);this.maxFraction=
c};Box2D.Collision.b2RayCastOutput=function(){this.normal=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Collision.b2Segment=function(){this.p1=Box2D.Common.Math.b2Vec2.Get(0,0);this.p2=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Collision.b2Segment.prototype.TestSegment=function(a,b,c,d){void 0===d&&(d=0);var e=c.p1,g=c.p2.x-e.x,f=c.p2.y-e.y;c=this.p2.y-this.p1.y;var l=-(this.p2.x-this.p1.x),k=100*Number.MIN_VALUE,h=-(g*c+f*l);if(h>k){var m=e.x-this.p1.x,n=e.y-this.p1.y,e=m*c+n*l;if(0<=e&&e<=d*h&&(d=-g*n+
f*m,-k*h<=d&&d<=h*(1+k)))return e/=h,d=Math.sqrt(c*c+l*l),a[0]=e,b.Set(c/d,l/d),!0}return!1};Box2D.Collision.b2Segment.prototype.Extend=function(a){this.ExtendForward(a);this.ExtendBackward(a)};Box2D.Collision.b2Segment.prototype.ExtendForward=function(a){var b=this.p2.x-this.p1.x,c=this.p2.y-this.p1.y;a=Math.min(0<b?(a.upperBound_.x-this.p1.x)/b:0>b?(a.lowerBound_.x-this.p1.x)/b:Number.POSITIVE_INFINITY,0<c?(a.upperBound_.y-this.p1.y)/c:0>c?(a.lowerBound_.y-this.p1.y)/c:Number.POSITIVE_INFINITY);
this.p2.x=this.p1.x+b*a;this.p2.y=this.p1.y+c*a};Box2D.Collision.b2Segment.prototype.ExtendBackward=function(a){var b=-this.p2.x+this.p1.x,c=-this.p2.y+this.p1.y;a=Math.min(0<b?(a.upperBound_.x-this.p2.x)/b:0>b?(a.lowerBound_.x-this.p2.x)/b:Number.POSITIVE_INFINITY,0<c?(a.upperBound_.y-this.p2.y)/c:0>c?(a.lowerBound_.y-this.p2.y)/c:Number.POSITIVE_INFINITY);this.p1.x=this.p2.x+b*a;this.p1.y=this.p2.y+c*a};Box2D.Collision.b2SeparationFunction=function(){this.m_localPoint=Box2D.Common.Math.b2Vec2.Get(0,
0);this.m_axis=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Collision.b2SeparationFunction.prototype.Initialize=function(a,b,c,d,e){this.m_proxyA=b;this.m_proxyB=d;var g,f,l,k=l=f=0,h=0;d=b=0;var m,n,k=0;1==a.count?(this.m_type=Box2D.Collision.b2SeparationFunction.e_points,g=this.m_proxyA.GetVertex(a.indexA[0]),a=this.m_proxyB.GetVertex(a.indexB[0]),n=g,m=c.R,f=c.position.x+(m.col1.x*n.x+m.col2.x*n.y),l=c.position.y+(m.col1.y*n.x+m.col2.y*n.y),n=a,m=e.R,k=e.position.x+(m.col1.x*n.x+m.col2.x*n.y),h=e.position.y+
(m.col1.y*n.x+m.col2.y*n.y),this.m_axis.x=k-f,this.m_axis.y=h-l,this.m_axis.Normalize()):(a.indexB[0]==a.indexB[1]?(this.m_type=Box2D.Collision.b2SeparationFunction.e_faceA,b=this.m_proxyA.GetVertex(a.indexA[0]),d=this.m_proxyA.GetVertex(a.indexA[1]),a=this.m_proxyB.GetVertex(a.indexB[0]),this.m_localPoint.x=0.5*(b.x+d.x),this.m_localPoint.y=0.5*(b.y+d.y),this.m_axis=Box2D.Common.Math.b2Math.CrossVF(Box2D.Common.Math.b2Math.SubtractVV(d,b),1),this.m_axis.Normalize(),n=this.m_axis,m=c.R,b=m.col1.x*
n.x+m.col2.x*n.y,d=m.col1.y*n.x+m.col2.y*n.y,n=this.m_localPoint,m=c.R,f=c.position.x+(m.col1.x*n.x+m.col2.x*n.y),l=c.position.y+(m.col1.y*n.x+m.col2.y*n.y),n=a,m=e.R,k=e.position.x+(m.col1.x*n.x+m.col2.x*n.y),h=e.position.y+(m.col1.y*n.x+m.col2.y*n.y),k=(k-f)*b+(h-l)*d):a.indexA[0]==a.indexA[0]?(this.m_type=Box2D.Collision.b2SeparationFunction.e_faceB,f=this.m_proxyB.GetVertex(a.indexB[0]),l=this.m_proxyB.GetVertex(a.indexB[1]),g=this.m_proxyA.GetVertex(a.indexA[0]),this.m_localPoint.x=0.5*(f.x+
l.x),this.m_localPoint.y=0.5*(f.y+l.y),this.m_axis=Box2D.Common.Math.b2Math.CrossVF(Box2D.Common.Math.b2Math.SubtractVV(l,f),1),this.m_axis.Normalize(),n=this.m_axis,m=e.R,b=m.col1.x*n.x+m.col2.x*n.y,d=m.col1.y*n.x+m.col2.y*n.y,n=this.m_localPoint,m=e.R,k=e.position.x+(m.col1.x*n.x+m.col2.x*n.y),h=e.position.y+(m.col1.y*n.x+m.col2.y*n.y),n=g,m=c.R,f=c.position.x+(m.col1.x*n.x+m.col2.x*n.y),l=c.position.y+(m.col1.y*n.x+m.col2.y*n.y),k=(f-k)*b+(l-h)*d):(b=this.m_proxyA.GetVertex(a.indexA[0]),d=this.m_proxyA.GetVertex(a.indexA[1]),
f=this.m_proxyB.GetVertex(a.indexB[0]),l=this.m_proxyB.GetVertex(a.indexB[1]),k=Box2D.Common.Math.b2Math.MulMV(c.R,Box2D.Common.Math.b2Math.SubtractVV(d,b)),h=Box2D.Common.Math.b2Math.MulMV(e.R,Box2D.Common.Math.b2Math.SubtractVV(l,f)),e=k.x*k.x+k.y*k.y,c=h.x*h.x+h.y*h.y,g=Box2D.Common.Math.b2Math.SubtractVV(h,k),a=k.x*g.x+k.y*g.y,g=h.x*g.x+h.y*g.y,h=k.x*h.x+k.y*h.y,m=e*c-h*h,k=0,0!=m&&(k=Box2D.Common.Math.b2Math.Clamp((h*g-a*c)/m,0,1)),0>(h*k+g)/c&&(k=Box2D.Common.Math.b2Math.Clamp((h-a)/e,0,1)),
g=Box2D.Common.Math.b2Vec2.Get(0,0),g.x=b.x+k*(d.x-b.x),g.y=b.y+k*(d.y-b.y),a=Box2D.Common.Math.b2Vec2.Get(0,0),a.x=f.x+k*(l.x-f.x),a.y=f.y+k*(l.y-f.y),0==k||1==k?(this.m_type=Box2D.Collision.b2SeparationFunction.e_faceB,this.m_axis=Box2D.Common.Math.b2Math.CrossVF(Box2D.Common.Math.b2Math.SubtractVV(l,f),1),this.m_axis.Normalize(),this.m_localPoint=a):(this.m_type=Box2D.Collision.b2SeparationFunction.e_faceA,this.m_axis=Box2D.Common.Math.b2Math.CrossVF(Box2D.Common.Math.b2Math.SubtractVV(d,b),1),
this.m_localPoint=g)),0>k&&this.m_axis.NegativeSelf())};Box2D.Collision.b2SeparationFunction.prototype.Evaluate=function(a,b){var c,d,e=0;switch(this.m_type){case Box2D.Collision.b2SeparationFunction.e_points:c=Box2D.Common.Math.b2Math.MulTMV(a.R,this.m_axis);d=Box2D.Common.Math.b2Math.MulTMV(b.R,this.m_axis.GetNegative());c=this.m_proxyA.GetSupportVertex(c);d=this.m_proxyB.GetSupportVertex(d);c=Box2D.Common.Math.b2Math.MulX(a,c);d=Box2D.Common.Math.b2Math.MulX(b,d);e=(d.x-c.x)*this.m_axis.x+(d.y-
c.y)*this.m_axis.y;break;case Box2D.Collision.b2SeparationFunction.e_faceA:e=Box2D.Common.Math.b2Math.MulMV(a.R,this.m_axis);c=Box2D.Common.Math.b2Math.MulX(a,this.m_localPoint);d=Box2D.Common.Math.b2Math.MulTMV(b.R,e.GetNegative());d=this.m_proxyB.GetSupportVertex(d);d=Box2D.Common.Math.b2Math.MulX(b,d);e=(d.x-c.x)*e.x+(d.y-c.y)*e.y;break;case Box2D.Collision.b2SeparationFunction.e_faceB:e=Box2D.Common.Math.b2Math.MulMV(b.R,this.m_axis),d=Box2D.Common.Math.b2Math.MulX(b,this.m_localPoint),c=Box2D.Common.Math.b2Math.MulTMV(a.R,
e.GetNegative()),c=this.m_proxyA.GetSupportVertex(c),c=Box2D.Common.Math.b2Math.MulX(a,c),e=(c.x-d.x)*e.x+(c.y-d.y)*e.y}return e};Box2D.Collision.b2SeparationFunction.e_points=1;Box2D.Collision.b2SeparationFunction.e_faceA=2;Box2D.Collision.b2SeparationFunction.e_faceB=4;Box2D.Collision.b2Simplex=function(){this.m_v1=new Box2D.Collision.b2SimplexVertex;this.m_v2=new Box2D.Collision.b2SimplexVertex;this.m_v3=new Box2D.Collision.b2SimplexVertex;this.m_vertices=[this.m_v1,this.m_v2,this.m_v3]};Box2D.Collision.b2Simplex.prototype.ReadCache=
function(a,b,c,d,e){var g,f;this.m_count=a.count;for(var l=this.m_vertices,k=0;k<this.m_count;k++){var h=l[k];h.indexA=a.indexA[k];h.indexB=a.indexB[k];g=b.GetVertex(h.indexA);f=d.GetVertex(h.indexB);h.wA=Box2D.Common.Math.b2Math.MulX(c,g);h.wB=Box2D.Common.Math.b2Math.MulX(e,f);h.w=Box2D.Common.Math.b2Math.SubtractVV(h.wB,h.wA);h.a=0}if(1<this.m_count&&(a=a.metric,g=this.GetMetric(),g<0.5*a||2*a<g||g<Number.MIN_VALUE))this.m_count=0;0==this.m_count&&(h=l[0],h.indexA=0,h.indexB=0,g=b.GetVertex(0),
f=d.GetVertex(0),h.wA=Box2D.Common.Math.b2Math.MulX(c,g),h.wB=Box2D.Common.Math.b2Math.MulX(e,f),h.w=Box2D.Common.Math.b2Math.SubtractVV(h.wB,h.wA),this.m_count=1)};Box2D.Collision.b2Simplex.prototype.WriteCache=function(a){a.metric=this.GetMetric();a.count=this.m_count;for(var b=this.m_vertices,c=0;c<this.m_count;c++)a.indexA[c]=b[c].indexA,a.indexB[c]=b[c].indexB};Box2D.Collision.b2Simplex.prototype.GetSearchDirection=function(){if(1==this.m_count)return this.m_v1.w.GetNegative();if(2==this.m_count){var a=
Box2D.Common.Math.b2Math.SubtractVV(this.m_v2.w,this.m_v1.w);return 0<Box2D.Common.Math.b2Math.CrossVV(a,this.m_v1.w.GetNegative())?Box2D.Common.Math.b2Math.CrossFV(1,a):Box2D.Common.Math.b2Math.CrossVF(a,1)}return Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Collision.b2Simplex.prototype.GetClosestPoint=function(){return 1==this.m_count?this.m_v1.w:2==this.m_count?Box2D.Common.Math.b2Vec2.Get(this.m_v1.a*this.m_v1.w.x+this.m_v2.a*this.m_v2.w.x,this.m_v1.a*this.m_v1.w.y+this.m_v2.a*this.m_v2.w.y):Box2D.Common.Math.b2Vec2.Get(0,
0)};Box2D.Collision.b2Simplex.prototype.GetWitnessPoints=function(a,b){1==this.m_count?(a.SetV(this.m_v1.wA),b.SetV(this.m_v1.wB)):2==this.m_count?(a.x=this.m_v1.a*this.m_v1.wA.x+this.m_v2.a*this.m_v2.wA.x,a.y=this.m_v1.a*this.m_v1.wA.y+this.m_v2.a*this.m_v2.wA.y,b.x=this.m_v1.a*this.m_v1.wB.x+this.m_v2.a*this.m_v2.wB.x,b.y=this.m_v1.a*this.m_v1.wB.y+this.m_v2.a*this.m_v2.wB.y):3==this.m_count&&(b.x=a.x=this.m_v1.a*this.m_v1.wA.x+this.m_v2.a*this.m_v2.wA.x+this.m_v3.a*this.m_v3.wA.x,b.y=a.y=this.m_v1.a*
this.m_v1.wA.y+this.m_v2.a*this.m_v2.wA.y+this.m_v3.a*this.m_v3.wA.y)};Box2D.Collision.b2Simplex.prototype.GetMetric=function(){return 1==this.m_count?0:2==this.m_count?Box2D.Common.Math.b2Math.SubtractVV(this.m_v1.w,this.m_v2.w).Length():3==this.m_count?Box2D.Common.Math.b2Math.CrossVV(Box2D.Common.Math.b2Math.SubtractVV(this.m_v2.w,this.m_v1.w),Box2D.Common.Math.b2Math.SubtractVV(this.m_v3.w,this.m_v1.w)):0};Box2D.Collision.b2Simplex.prototype.Solve2=function(){var a=this.m_v1.w,b=this.m_v2.w,c=
Box2D.Common.Math.b2Math.SubtractVV(b,a),a=-(a.x*c.x+a.y*c.y);0>=a?this.m_count=this.m_v1.a=1:(b=b.x*c.x+b.y*c.y,0>=b?(this.m_count=this.m_v2.a=1,this.m_v1.Set(this.m_v2)):(c=1/(b+a),this.m_v1.a=b*c,this.m_v2.a=a*c,this.m_count=2))};Box2D.Collision.b2Simplex.prototype.Solve3=function(){var a=this.m_v1.w,b=this.m_v2.w,c=this.m_v3.w,d=Box2D.Common.Math.b2Math.SubtractVV(b,a),e=Box2D.Common.Math.b2Math.Dot(a,d),g=Box2D.Common.Math.b2Math.Dot(b,d),e=-e,f=Box2D.Common.Math.b2Math.SubtractVV(c,a),l=Box2D.Common.Math.b2Math.Dot(a,
f),k=Box2D.Common.Math.b2Math.Dot(c,f),l=-l,h=Box2D.Common.Math.b2Math.SubtractVV(c,b),m=Box2D.Common.Math.b2Math.Dot(b,h),h=Box2D.Common.Math.b2Math.Dot(c,h),m=-m,f=Box2D.Common.Math.b2Math.CrossVV(d,f),d=f*Box2D.Common.Math.b2Math.CrossVV(b,c),c=f*Box2D.Common.Math.b2Math.CrossVV(c,a),a=f*Box2D.Common.Math.b2Math.CrossVV(a,b);0>=e&&0>=l?this.m_count=this.m_v1.a=1:0<g&&0<e&&0>=a?(k=1/(g+e),this.m_v1.a=g*k,this.m_v2.a=e*k,this.m_count=2):0<k&&0<l&&0>=c?(g=1/(k+l),this.m_v1.a=k*g,this.m_v3.a=l*g,this.m_count=
2,this.m_v2.Set(this.m_v3)):0>=g&&0>=m?(this.m_count=this.m_v2.a=1,this.m_v1.Set(this.m_v2)):0>=k&&0>=h?(this.m_count=this.m_v3.a=1,this.m_v1.Set(this.m_v3)):0<h&&0<m&&0>=d?(g=1/(h+m),this.m_v2.a=h*g,this.m_v3.a=m*g,this.m_count=2,this.m_v1.Set(this.m_v3)):(g=1/(d+c+a),this.m_v1.a=d*g,this.m_v2.a=c*g,this.m_v3.a=a*g,this.m_count=3)};Box2D.Collision.b2SimplexCache=function(){this.indexA=[0,0,0];this.indexB=[0,0,0]};Box2D.Collision.b2SimplexVertex=function(){};Box2D.Collision.b2SimplexVertex.prototype.Set=
function(a){this.wA.SetV(a.wA);this.wB.SetV(a.wB);this.w.SetV(a.w);this.a=a.a;this.indexA=a.indexA;this.indexB=a.indexB};Box2D.Collision.b2TOIInput=function(){this.proxyA=new Box2D.Collision.b2DistanceProxy;this.proxyB=new Box2D.Collision.b2DistanceProxy;this.sweepA=new Box2D.Common.Math.b2Sweep;this.sweepB=new Box2D.Common.Math.b2Sweep};Box2D.Collision.b2TimeOfImpact={};Box2D.Collision.b2TimeOfImpact.TimeOfImpact=function(a){Box2D.Collision.b2TimeOfImpact.b2_toiCalls++;var b=a.proxyA,c=a.proxyB,
d=a.sweepA,e=a.sweepB,g=b.m_radius+c.m_radius;a=a.tolerance;var f=0,l=0,k=0;Box2D.Collision.b2TimeOfImpact.s_cache.count=0;for(Box2D.Collision.b2TimeOfImpact.s_distanceInput.useRadii=!1;;){d.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfA,f);e.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfB,f);Box2D.Collision.b2TimeOfImpact.s_distanceInput.proxyA=b;Box2D.Collision.b2TimeOfImpact.s_distanceInput.proxyB=c;Box2D.Collision.b2TimeOfImpact.s_distanceInput.transformA=Box2D.Collision.b2TimeOfImpact.s_xfA;
Box2D.Collision.b2TimeOfImpact.s_distanceInput.transformB=Box2D.Collision.b2TimeOfImpact.s_xfB;Box2D.Collision.b2Distance.Distance(Box2D.Collision.b2TimeOfImpact.s_distanceOutput,Box2D.Collision.b2TimeOfImpact.s_cache,Box2D.Collision.b2TimeOfImpact.s_distanceInput);if(0>=Box2D.Collision.b2TimeOfImpact.s_distanceOutput.distance){f=1;break}Box2D.Collision.b2TimeOfImpact.s_fcn.Initialize(Box2D.Collision.b2TimeOfImpact.s_cache,b,Box2D.Collision.b2TimeOfImpact.s_xfA,c,Box2D.Collision.b2TimeOfImpact.s_xfB);
var h=Box2D.Collision.b2TimeOfImpact.s_fcn.Evaluate(Box2D.Collision.b2TimeOfImpact.s_xfA,Box2D.Collision.b2TimeOfImpact.s_xfB);if(0>=h){f=1;break}0==l&&(k=h>g?Math.max(g-a,0.75*g):Math.max(h-a,0.02*g));if(h-k<0.5*a){if(0==l){f=1;break}break}var m=f,n=f,q=1;d.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfA,q);e.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfB,q);var p=Box2D.Collision.b2TimeOfImpact.s_fcn.Evaluate(Box2D.Collision.b2TimeOfImpact.s_xfA,Box2D.Collision.b2TimeOfImpact.s_xfB);if(p>=k){f=
1;break}for(var r=0;;){var s=0,s=r&1?n+(k-h)*(q-n)/(p-h):0.5*(n+q);d.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfA,s);e.GetTransform(Box2D.Collision.b2TimeOfImpact.s_xfB,s);var t=Box2D.Collision.b2TimeOfImpact.s_fcn.Evaluate(Box2D.Collision.b2TimeOfImpact.s_xfA,Box2D.Collision.b2TimeOfImpact.s_xfB);if(Math.abs(t-k)<0.025*a){m=s;break}t>k?(n=s,h=t):(q=s,p=t);r++;Box2D.Collision.b2TimeOfImpact.b2_toiRootIters++;if(50==r)break}Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters=Math.max(Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters,
r);if(m<(1+100*Number.MIN_VALUE)*f)break;f=m;l++;Box2D.Collision.b2TimeOfImpact.b2_toiIters++;if(1E3==l)break}Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters=Math.max(Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters,l);return f};Box2D.Collision.b2WorldManifold=function(){this.m_normal=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_points=[];for(var a=this.m_pointCount=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++)this.m_points[a]=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Collision.b2WorldManifold.prototype.Initialize=
function(a,b,c,d,e){if(0!=a.m_pointCount){var g=0,f,l,k=0,h=0,m=0,n=0,q=0;f=0;switch(a.m_type){case Box2D.Collision.b2Manifold.e_circles:l=b.R;f=a.m_localPoint;g=b.position.x+l.col1.x*f.x+l.col2.x*f.y;b=b.position.y+l.col1.y*f.x+l.col2.y*f.y;l=d.R;f=a.m_points[0].m_localPoint;a=d.position.x+l.col1.x*f.x+l.col2.x*f.y;d=d.position.y+l.col1.y*f.x+l.col2.y*f.y;f=a-g;l=d-b;k=f*f+l*l;k>Box2D.Common.b2Settings.MIN_VALUE_SQUARED?(k=Math.sqrt(k),this.m_normal.x=f/k,this.m_normal.y=l/k):(this.m_normal.x=1,
this.m_normal.y=0);f=b+c*this.m_normal.y;d-=e*this.m_normal.y;this.m_points[0].x=0.5*(g+c*this.m_normal.x+(a-e*this.m_normal.x));this.m_points[0].y=0.5*(f+d);break;case Box2D.Collision.b2Manifold.e_faceA:l=b.R;f=a.m_localPlaneNormal;k=l.col1.x*f.x+l.col2.x*f.y;h=l.col1.y*f.x+l.col2.y*f.y;l=b.R;f=a.m_localPoint;m=b.position.x+l.col1.x*f.x+l.col2.x*f.y;n=b.position.y+l.col1.y*f.x+l.col2.y*f.y;this.m_normal.x=k;this.m_normal.y=h;for(g=0;g<a.m_pointCount;g++)l=d.R,f=a.m_points[g].m_localPoint,q=d.position.x+
l.col1.x*f.x+l.col2.x*f.y,f=d.position.y+l.col1.y*f.x+l.col2.y*f.y,this.m_points[g].x=q+0.5*(c-(q-m)*k-(f-n)*h-e)*k,this.m_points[g].y=f+0.5*(c-(q-m)*k-(f-n)*h-e)*h;break;case Box2D.Collision.b2Manifold.e_faceB:l=d.R;f=a.m_localPlaneNormal;k=l.col1.x*f.x+l.col2.x*f.y;h=l.col1.y*f.x+l.col2.y*f.y;l=d.R;f=a.m_localPoint;m=d.position.x+l.col1.x*f.x+l.col2.x*f.y;n=d.position.y+l.col1.y*f.x+l.col2.y*f.y;this.m_normal.x=-k;this.m_normal.y=-h;for(g=0;g<a.m_pointCount;g++)l=b.R,f=a.m_points[g].m_localPoint,
q=b.position.x+l.col1.x*f.x+l.col2.x*f.y,f=b.position.y+l.col1.y*f.x+l.col2.y*f.y,this.m_points[g].x=q+0.5*(e-(q-m)*k-(f-n)*h-c)*k,this.m_points[g].y=f+0.5*(e-(q-m)*k-(f-n)*h-c)*h}}};Box2D.Dynamics.b2Body=function(a,b){this.ID="Body"+Box2D.Dynamics.b2Body.NEXT_ID++;this.m_xf=new Box2D.Common.Math.b2Transform;this.m_xf.position.SetV(a.position);this.m_xf.R.Set(a.angle);this.m_sweep=new Box2D.Common.Math.b2Sweep;this.m_sweep.localCenter.SetZero();this.m_sweep.t0=1;this.m_sweep.a0=this.m_sweep.a=a.angle;
this.m_sweep.c.x=this.m_xf.R.col1.x*this.m_sweep.localCenter.x+this.m_xf.R.col2.x*this.m_sweep.localCenter.y;this.m_sweep.c.y=this.m_xf.R.col1.y*this.m_sweep.localCenter.x+this.m_xf.R.col2.y*this.m_sweep.localCenter.y;this.m_sweep.c.x+=this.m_xf.position.x;this.m_sweep.c.y+=this.m_xf.position.y;this.m_sweep.c0.SetV(this.m_sweep.c);this.m_linearVelocity=a.linearVelocity.Copy();this.m_force=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_bullet=a.bullet;this.m_fixedRotation=a.fixedRotation;this.m_allowSleep=
a.allowSleep;this.m_awake=a.awake;this.m_active=a.active;this.m_world=b;this.m_jointList=null;this.contactList=new Box2D.Dynamics.Contacts.b2ContactList;this.controllerList=new Box2D.Dynamics.Controllers.b2ControllerList;this.m_controllerCount=0;this.m_angularVelocity=a.angularVelocity;this.m_linearDamping=a.linearDamping;this.m_angularDamping=a.angularDamping;this.m_sleepTime=this.m_torque=0;this.m_type=a.type;this.m_mass=this.m_type==Box2D.Dynamics.b2BodyDef.b2_dynamicBody?1:0;this.m_invMass=this.m_type==
Box2D.Dynamics.b2BodyDef.b2_dynamicBody?1:0;this.m_invI=this.m_I=0;this.m_inertiaScale=a.inertiaScale;this.fixtureList=new Box2D.Dynamics.b2FixtureList;this.m_lists=[]};Box2D.Dynamics.b2Body.prototype.CreateFixture=function(a){a=new Box2D.Dynamics.b2Fixture(this,this.m_xf,a);this.m_active&&a.CreateProxy(this.m_world.m_contactManager.m_broadPhase,this.m_xf);this.fixtureList.AddFixture(a);a.m_body=this;0<a.m_density&&this.ResetMassData();this.m_world.m_newFixture=!0;return a};Box2D.Dynamics.b2Body.prototype.CreateFixture2=
function(a,b){void 0===b&&(b=0);var c=new Box2D.Dynamics.b2FixtureDef;c.shape=a;c.density=b;return this.CreateFixture(c)};Box2D.Dynamics.b2Body.prototype.Destroy=function(){Box2D.Common.Math.b2Vec2.Free(this.m_linearVelocity);Box2D.Common.Math.b2Vec2.Free(this.m_force)};Box2D.Dynamics.b2Body.prototype.DestroyFixture=function(a){this.fixtureList.RemoveFixture(a);for(var b=this.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);b;b=b.GetNextNode())(a==b.contact.m_fixtureA||
a==b.contact.m_fixtureB)&&this.m_world.m_contactManager.Destroy(b.contact);this.m_active&&a.DestroyProxy(this.m_world.m_contactManager.m_broadPhase);a.Destroy();a.m_body=null;this.ResetMassData()};Box2D.Dynamics.b2Body.prototype.SetPositionAndAngle=function(a,b){this.m_xf.R.Set(b);this.m_xf.position.SetV(a);var c=this.m_xf.R,d=this.m_sweep.localCenter;this.m_sweep.c.x=c.col1.x*d.x+c.col2.x*d.y;this.m_sweep.c.y=c.col1.y*d.x+c.col2.y*d.y;this.m_sweep.c.x+=this.m_xf.position.x;this.m_sweep.c.y+=this.m_xf.position.y;
this.m_sweep.c0.SetV(this.m_sweep.c);this.m_sweep.a0=this.m_sweep.a=b;c=this.m_world.m_contactManager.m_broadPhase;for(d=this.fixtureList.GetFirstNode();d;d=d.GetNextNode())d.fixture.Synchronize(c,this.m_xf,this.m_xf);this.m_world.m_contactManager.FindNewContacts()};Box2D.Dynamics.b2Body.prototype.SetTransform=function(a){this.SetPositionAndAngle(a.position,a.GetAngle())};Box2D.Dynamics.b2Body.prototype.GetTransform=function(){return this.m_xf};Box2D.Dynamics.b2Body.prototype.GetPosition=function(){return this.m_xf.position};
Box2D.Dynamics.b2Body.prototype.SetPosition=function(a){this.SetPositionAndAngle(a,this.GetAngle())};Box2D.Dynamics.b2Body.prototype.GetAngle=function(){return this.m_sweep.a};Box2D.Dynamics.b2Body.prototype.SetAngle=function(a){this.SetPositionAndAngle(this.GetPosition(),a)};Box2D.Dynamics.b2Body.prototype.GetWorldCenter=function(){return this.m_sweep.c};Box2D.Dynamics.b2Body.prototype.GetLocalCenter=function(){return this.m_sweep.localCenter};Box2D.Dynamics.b2Body.prototype.SetLinearVelocity=function(a){this.m_type!=
Box2D.Dynamics.b2BodyDef.b2_staticBody&&this.m_linearVelocity.SetV(a)};Box2D.Dynamics.b2Body.prototype.GetLinearVelocity=function(){return this.m_linearVelocity};Box2D.Dynamics.b2Body.prototype.SetAngularVelocity=function(a){void 0===a&&(a=0);this.m_type!=Box2D.Dynamics.b2BodyDef.b2_staticBody&&(this.m_angularVelocity=a)};Box2D.Dynamics.b2Body.prototype.GetAngularVelocity=function(){return this.m_angularVelocity};Box2D.Dynamics.b2Body.prototype.GetDefinition=function(){var a=new Box2D.Dynamics.b2BodyDef;
a.type=this.GetType();a.allowSleep=this.m_allowSleep;a.angle=this.GetAngle();a.angularDamping=this.m_angularDamping;a.angularVelocity=this.m_angularVelocity;a.fixedRotation=this.m_fixedRotation;a.bullet=this.m_bullet;a.active=this.m_active;a.awake=this.m_awake;a.linearDamping=this.m_linearDamping;a.linearVelocity.SetV(this.GetLinearVelocity());a.position=this.GetPosition();return a};Box2D.Dynamics.b2Body.prototype.ApplyForce=function(a,b){this.m_type==Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&(this.SetAwake(!0),
this.m_force.x+=a.x,this.m_force.y+=a.y,this.m_torque+=(b.x-this.m_sweep.c.x)*a.y-(b.y-this.m_sweep.c.y)*a.x)};Box2D.Dynamics.b2Body.prototype.ApplyTorque=function(a){void 0===a&&(a=0);this.m_type==Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&(this.SetAwake(!0),this.m_torque+=a)};Box2D.Dynamics.b2Body.prototype.ApplyImpulse=function(a,b){this.m_type==Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&(this.SetAwake(!0),this.m_linearVelocity.x+=this.m_invMass*a.x,this.m_linearVelocity.y+=this.m_invMass*a.y,this.m_angularVelocity+=
this.m_invI*((b.x-this.m_sweep.c.x)*a.y-(b.y-this.m_sweep.c.y)*a.x))};Box2D.Dynamics.b2Body.prototype.Split=function(a){for(var b=this.GetLinearVelocity().Copy(),c=this.GetAngularVelocity(),d=this.GetWorldCenter(),e=this.m_world.CreateBody(this.GetDefinition()),g=this.fixtureList.GetFirstNode();g;g=g.GetNextNode()){var f=g.fixture;a(f)&&(this.fixtureList.RemoveFixture(f),e.fixtureList.AddFixture(f))}this.ResetMassData();e.ResetMassData();g=this.GetWorldCenter();a=e.GetWorldCenter();g=Box2D.Common.Math.b2Math.AddVV(b,
Box2D.Common.Math.b2Math.CrossFV(c,Box2D.Common.Math.b2Math.SubtractVV(g,d)));b=Box2D.Common.Math.b2Math.AddVV(b,Box2D.Common.Math.b2Math.CrossFV(c,Box2D.Common.Math.b2Math.SubtractVV(a,d)));this.SetLinearVelocity(g);e.SetLinearVelocity(b);this.SetAngularVelocity(c);e.SetAngularVelocity(c);this.SynchronizeFixtures();e.SynchronizeFixtures();return e};Box2D.Dynamics.b2Body.prototype.Merge=function(a){for(var b=a.fixtureList.GetFirstNode();b;b=b.GetNextNode())this.fixtureList.AddFixture(b.fixture),a.fixtureList.RemoveFixture(b.fixture);
a.ResetMassData();this.ResetMassData();this.SynchronizeFixtures()};Box2D.Dynamics.b2Body.prototype.GetMass=function(){return this.m_mass};Box2D.Dynamics.b2Body.prototype.GetInertia=function(){return this.m_I};Box2D.Dynamics.b2Body.prototype.GetMassData=function(a){a||(a=new Box2D.Collision.Shapes.b2MassData);a.mass=this.m_mass;a.I=this.m_I;a.center.SetV(this.m_sweep.localCenter);return a};Box2D.Dynamics.b2Body.prototype.SetMassData=function(a){if(this.m_type==Box2D.Dynamics.b2BodyDef.b2_dynamicBody){this.m_invI=
this.m_I=this.m_invMass=0;this.m_mass=a.mass;0>=this.m_mass&&(this.m_mass=1);this.m_invMass=1/this.m_mass;0<a.I&&!this.m_fixedRotation&&(this.m_I=a.I-this.m_mass*(a.center.x*a.center.x+a.center.y*a.center.y),this.m_invI=1/this.m_I);var b=this.m_sweep.c.Copy();this.m_sweep.localCenter.SetV(a.center);this.m_sweep.c0.SetV(Box2D.Common.Math.b2Math.MulX(this.m_xf,this.m_sweep.localCenter));this.m_sweep.c.SetV(this.m_sweep.c0);this.m_linearVelocity.x+=this.m_angularVelocity*-(this.m_sweep.c.y-b.y);this.m_linearVelocity.y+=
this.m_angularVelocity*+(this.m_sweep.c.x-b.x)}};Box2D.Dynamics.b2Body.prototype.ResetMassData=function(){this.m_invI=this.m_I=this.m_invMass=this.m_mass=0;this.m_sweep.localCenter.SetZero();if(!(this.m_type==Box2D.Dynamics.b2BodyDef.b2_staticBody||this.m_type==Box2D.Dynamics.b2BodyDef.b2_kinematicBody)){for(var a=Box2D.Common.Math.b2Vec2.Get(0,0),b=this.fixtureList.GetFirstNode();b;b=b.GetNextNode()){var c=b.fixture;0!=c.m_density&&(c=c.GetMassData(),this.m_mass+=c.mass,a.x+=c.center.x*c.mass,a.y+=
c.center.y*c.mass,this.m_I+=c.I)}0<this.m_mass?(this.m_invMass=1/this.m_mass,a.x*=this.m_invMass,a.y*=this.m_invMass):this.m_invMass=this.m_mass=1;0<this.m_I&&!this.m_fixedRotation?(this.m_I-=this.m_mass*(a.x*a.x+a.y*a.y),this.m_I*=this.m_inertiaScale,this.m_invI=1/this.m_I):this.m_invI=this.m_I=0;b=this.m_sweep.c.Copy();this.m_sweep.localCenter.SetV(a);this.m_sweep.c0.SetV(Box2D.Common.Math.b2Math.MulX(this.m_xf,this.m_sweep.localCenter));this.m_sweep.c.SetV(this.m_sweep.c0);this.m_linearVelocity.x+=
this.m_angularVelocity*-(this.m_sweep.c.y-b.y);this.m_linearVelocity.y+=this.m_angularVelocity*+(this.m_sweep.c.x-b.x);Box2D.Common.Math.b2Vec2.Free(a);Box2D.Common.Math.b2Vec2.Free(b)}};Box2D.Dynamics.b2Body.prototype.GetWorldPoint=function(a){var b=this.m_xf.R;a=Box2D.Common.Math.b2Vec2.Get(b.col1.x*a.x+b.col2.x*a.y,b.col1.y*a.x+b.col2.y*a.y);a.x+=this.m_xf.position.x;a.y+=this.m_xf.position.y;return a};Box2D.Dynamics.b2Body.prototype.GetWorldVector=function(a){return Box2D.Common.Math.b2Math.MulMV(this.m_xf.R,
a)};Box2D.Dynamics.b2Body.prototype.GetLocalPoint=function(a){return Box2D.Common.Math.b2Math.MulXT(this.m_xf,a)};Box2D.Dynamics.b2Body.prototype.GetLocalVector=function(a){return Box2D.Common.Math.b2Math.MulTMV(this.m_xf.R,a)};Box2D.Dynamics.b2Body.prototype.GetLinearVelocityFromWorldPoint=function(a){return Box2D.Common.Math.b2Vec2.Get(this.m_linearVelocity.x-this.m_angularVelocity*(a.y-this.m_sweep.c.y),this.m_linearVelocity.y+this.m_angularVelocity*(a.x-this.m_sweep.c.x))};Box2D.Dynamics.b2Body.prototype.GetLinearVelocityFromLocalPoint=
function(a){var b=this.m_xf.R;a=Box2D.Common.Math.b2Vec2.Get(b.col1.x*a.x+b.col2.x*a.y,b.col1.y*a.x+b.col2.y*a.y);a.x+=this.m_xf.position.x;a.y+=this.m_xf.position.y;b=Box2D.Common.Math.b2Vec2.Get(this.m_linearVelocity.x-this.m_angularVelocity*(a.y-this.m_sweep.c.y),this.m_linearVelocity.y+this.m_angularVelocity*(a.x-this.m_sweep.c.x));Box2D.Common.Math.b2Vec2.Free(a);return b};Box2D.Dynamics.b2Body.prototype.GetLinearDamping=function(){return this.m_linearDamping};Box2D.Dynamics.b2Body.prototype.SetLinearDamping=
function(a){this.m_linearDamping=a};Box2D.Dynamics.b2Body.prototype.GetAngularDamping=function(){return this.m_angularDamping};Box2D.Dynamics.b2Body.prototype.SetAngularDamping=function(a){this.m_angularDamping=a};Box2D.Dynamics.b2Body.prototype.SetType=function(a){if(this.m_type!=a){this.m_type=a;this.ResetMassData();this.m_type==Box2D.Dynamics.b2BodyDef.b2_staticBody&&(this.m_linearVelocity.SetZero(),this.m_angularVelocity=0);this.SetAwake(!0);this.m_force.SetZero();this.m_torque=0;for(a=this.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=
a.GetNextNode())a.contact.FlagForFiltering();for(a=0;a<this.m_lists.length;a++)this.m_lists[a].UpdateBody(this)}};Box2D.Dynamics.b2Body.prototype.GetType=function(){return this.m_type};Box2D.Dynamics.b2Body.prototype.SetBullet=function(a){this.m_bullet=a};Box2D.Dynamics.b2Body.prototype.IsBullet=function(){return this.m_bullet};Box2D.Dynamics.b2Body.prototype.SetSleepingAllowed=function(a){(this.m_allowSleep=a)||this.SetAwake(!0)};Box2D.Dynamics.b2Body.prototype.SetAwake=function(a){if(this.m_awake!=
a){this.m_awake=a;this.m_sleepTime=0;a||(this.m_linearVelocity.SetZero(),this.m_angularVelocity=0,this.m_force.SetZero(),this.m_torque=0);for(a=0;a<this.m_lists.length;a++)this.m_lists[a].UpdateBody(this)}};Box2D.Dynamics.b2Body.prototype.IsAwake=function(){return this.m_awake};Box2D.Dynamics.b2Body.prototype.SetFixedRotation=function(a){this.m_fixedRotation=a;this.ResetMassData()};Box2D.Dynamics.b2Body.prototype.IsFixedRotation=function(){return this.m_fixedRotation};Box2D.Dynamics.b2Body.prototype.SetActive=
function(a){if(a!=this.m_active){if(a){this.m_active=!0;a=this.m_world.m_contactManager.m_broadPhase;for(var b=this.fixtureList.GetFirstNode();b;b=b.GetNextNode())b.fixture.CreateProxy(a,this.m_xf)}else{this.m_active=!1;a=this.m_world.m_contactManager.m_broadPhase;for(b=this.fixtureList.GetFirstNode();b;b=b.GetNextNode())b.fixture.DestroyProxy(a);for(a=this.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=a.GetNextNode())this.m_world.m_contactManager.Destroy(a.contact)}for(a=
0;a<this.m_lists.length;a++)this.m_lists[a].UpdateBody(this)}};Box2D.Dynamics.b2Body.prototype.IsActive=function(){return this.m_active};Box2D.Dynamics.b2Body.prototype.IsSleepingAllowed=function(){return this.m_allowSleep};Box2D.Dynamics.b2Body.prototype.GetFixtureList=function(){return this.fixtureList};Box2D.Dynamics.b2Body.prototype.GetJointList=function(){return this.m_jointList};Box2D.Dynamics.b2Body.prototype.GetControllerList=function(){return this.controllerList};Box2D.Dynamics.b2Body.prototype.AddController=
function(a){this.controllerList.AddController(a)};Box2D.Dynamics.b2Body.prototype.RemoveController=function(a){this.controllerList.RemoveController(a)};Box2D.Dynamics.b2Body.prototype.GetContactList=function(){return this.contactList};Box2D.Dynamics.b2Body.prototype.GetWorld=function(){return this.m_world};Box2D.Dynamics.b2Body.prototype.SynchronizeFixtures=function(){var a=Box2D.Dynamics.b2Body.s_xf1;a.R.Set(this.m_sweep.a0);var b=a.R,c=this.m_sweep.localCenter;a.position.x=this.m_sweep.c0.x-(b.col1.x*
c.x+b.col2.x*c.y);a.position.y=this.m_sweep.c0.y-(b.col1.y*c.x+b.col2.y*c.y);b=this.m_world.m_contactManager.m_broadPhase;for(c=this.fixtureList.GetFirstNode();c;c=c.GetNextNode())c.fixture.Synchronize(b,a,this.m_xf)};Box2D.Dynamics.b2Body.prototype.SynchronizeTransform=function(){this.m_xf.R.Set(this.m_sweep.a);var a=this.m_xf.R,b=this.m_sweep.localCenter;this.m_xf.position.x=this.m_sweep.c.x-(a.col1.x*b.x+a.col2.x*b.y);this.m_xf.position.y=this.m_sweep.c.y-(a.col1.y*b.x+a.col2.y*b.y)};Box2D.Dynamics.b2Body.prototype.ShouldCollide=
function(a){if(this.m_type!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&a.m_type!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody)return!1;for(var b=this.m_jointList;b;b=b.next)if(b.other==a&&!1==b.joint.m_collideConnected)return!1;return!0};Box2D.Dynamics.b2Body.prototype.Advance=function(a){this.m_sweep.Advance(a);this.m_sweep.c.SetV(this.m_sweep.c0);this.m_sweep.a=this.m_sweep.a0;this.SynchronizeTransform()};Box2D.Dynamics.b2Body.NEXT_ID=0;Box2D.Dynamics.b2BodyDef=function(){this.position=Box2D.Common.Math.b2Vec2.Get(0,
0);this.linearVelocity=Box2D.Common.Math.b2Vec2.Get(0,0);this.angularDamping=this.linearDamping=this.angularVelocity=this.angle=0;this.awake=this.allowSleep=!0;this.bullet=this.fixedRotation=!1;this.type=Box2D.Dynamics.b2BodyDef.b2_staticBody;this.active=!0;this.inertiaScale=1};Box2D.Dynamics.b2BodyDef.b2_staticBody=0;Box2D.Dynamics.b2BodyDef.b2_kinematicBody=1;Box2D.Dynamics.b2BodyDef.b2_dynamicBody=2;Box2D.Dynamics.b2BodyList=function(){this.bodyFirstNodes=[];for(var a=0;a<=Box2D.Dynamics.b2BodyList.TYPES.allBodies;a++)this.bodyFirstNodes[a]=
null;this.bodyLastNodes=[];for(a=0;a<=Box2D.Dynamics.b2BodyList.TYPES.allBodies;a++)this.bodyLastNodes[a]=null;this.bodyNodeLookup={};this.bodyCount=0};Box2D.Dynamics.b2BodyList.prototype.GetFirstNode=function(a){return this.bodyFirstNodes[a]};Box2D.Dynamics.b2BodyList.prototype.AddBody=function(a){var b=a.ID;null==this.bodyNodeLookup[b]&&(this.CreateNode(a,b,Box2D.Dynamics.b2BodyList.TYPES.allBodies),this.UpdateBody(a),a.m_lists.push(this),this.bodyCount++)};Box2D.Dynamics.b2BodyList.prototype.UpdateBody=
function(a){var b=a.GetType(),c=a.ID,d=a.IsAwake(),e=a.IsActive();b==Box2D.Dynamics.b2BodyDef.b2_dynamicBody?this.CreateNode(a,c,Box2D.Dynamics.b2BodyList.TYPES.dynamicBodies):this.RemoveNode(c,Box2D.Dynamics.b2BodyList.TYPES.dynamicBodies);b!=Box2D.Dynamics.b2BodyDef.b2_staticBody?this.CreateNode(a,c,Box2D.Dynamics.b2BodyList.TYPES.nonStaticBodies):this.RemoveNode(c,Box2D.Dynamics.b2BodyList.TYPES.nonStaticBodies);b!=Box2D.Dynamics.b2BodyDef.b2_staticBody&&e&&d?this.CreateNode(a,c,Box2D.Dynamics.b2BodyList.TYPES.nonStaticActiveAwakeBodies):
this.RemoveNode(c,Box2D.Dynamics.b2BodyList.TYPES.nonStaticActiveAwakeBodies);d?this.CreateNode(a,c,Box2D.Dynamics.b2BodyList.TYPES.awakeBodies):this.RemoveNode(c,Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);e?this.CreateNode(a,c,Box2D.Dynamics.b2BodyList.TYPES.activeBodies):this.RemoveNode(c,Box2D.Dynamics.b2BodyList.TYPES.activeBodies)};Box2D.Dynamics.b2BodyList.prototype.RemoveBody=function(a){var b=a.ID;if(null!=this.bodyNodeLookup[b]){cr.arrayFindRemove(a.m_lists,this);for(a=0;a<=Box2D.Dynamics.b2BodyList.TYPES.allBodies;a++)this.RemoveNode(b,
a);delete this.bodyNodeLookup[b];this.bodyCount--}};Box2D.Dynamics.b2BodyList.prototype.RemoveNode=function(a,b){var c=this.bodyNodeLookup[a];if(null!=c){var d=c[b];null!=d&&(c[b]=null,c=d.GetPreviousNode(),d=d.GetNextNode(),null==c?this.bodyFirstNodes[b]=d:c.SetNextNode(d),null==d?this.bodyLastNodes[b]=c:d.SetPreviousNode(c))}};Box2D.Dynamics.b2BodyList.prototype.CreateNode=function(a,b,c){var d=this.bodyNodeLookup[b];if(null==d){for(var d=[],e=0;e<=Box2D.Dynamics.b2BodyList.TYPES.allBodies;e++)d[e]=
null;this.bodyNodeLookup[b]=d}null==d[c]&&(d[c]=new Box2D.Dynamics.b2BodyListNode(a),a=this.bodyLastNodes[c],null!=a?a.SetNextNode(d[c]):this.bodyFirstNodes[c]=d[c],d[c].SetPreviousNode(a),this.bodyLastNodes[c]=d[c])};Box2D.Dynamics.b2BodyList.prototype.GetBodyCount=function(){return this.bodyCount};Box2D.Dynamics.b2BodyList.TYPES={dynamicBodies:0,nonStaticBodies:1,activeBodies:2,nonStaticActiveAwakeBodies:3,awakeBodies:4,allBodies:5};Box2D.Dynamics.b2BodyListNode=function(a){this.body=a;this.previous=
this.next=null};Box2D.Dynamics.b2BodyListNode.prototype.SetNextNode=function(a){this.next=a};Box2D.Dynamics.b2BodyListNode.prototype.SetPreviousNode=function(a){this.previous=a};Box2D.Dynamics.b2BodyListNode.prototype.GetBody=function(){return this.body};Box2D.Dynamics.b2BodyListNode.prototype.GetNextNode=function(){return this.next};Box2D.Dynamics.b2BodyListNode.prototype.GetPreviousNode=function(){return this.previous};Box2D.Dynamics.b2ContactFilter=function(){};Box2D.Dynamics.b2ContactFilter.prototype.ShouldCollide=
function(a,b){var c=a.GetFilterData(),d=b.GetFilterData();return c.groupIndex==d.groupIndex&&0!=c.groupIndex?0<c.groupIndex:0!=(c.maskBits&d.categoryBits)&&0!=(c.categoryBits&d.maskBits)};Box2D.Dynamics.b2ContactFilter.b2_defaultFilter=new Box2D.Dynamics.b2ContactFilter;Box2D.Dynamics.b2ContactImpulse=function(){this.normalImpulses=[];this.tangentImpulses=[]};Box2D.Dynamics.b2ContactListener=function(){};Box2D.Dynamics.b2ContactListener.prototype.BeginContact=function(a){};Box2D.Dynamics.b2ContactListener.prototype.EndContact=
function(a){};Box2D.Dynamics.b2ContactListener.prototype.PreSolve=function(a,b){};Box2D.Dynamics.b2ContactListener.prototype.PostSolve=function(a,b){};Box2D.Dynamics.b2ContactManager=function(a){this.m_world=a;this.m_contactFilter=Box2D.Dynamics.b2ContactFilter.b2_defaultFilter;this.m_contactListener=Box2D.Dynamics.b2ContactListener.b2_defaultListener;this.m_contactFactory=new Box2D.Dynamics.Contacts.b2ContactFactory;this.m_broadPhase=new Box2D.Collision.b2DynamicTreeBroadPhase};Box2D.Dynamics.b2ContactManager.prototype.AddPair=
function(a,b){var c=a.GetBody(),d=b.GetBody();if(c!=d&&d.ShouldCollide(c)&&this.m_contactFilter.ShouldCollide(a,b)){for(c=d.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);c;c=c.GetNextNode())if(d=c.contact.m_fixtureA,d==a){if(d=c.contact.m_fixtureB,d==b)return}else if(d==b&&(d=c.contact.m_fixtureB,d==a))return;this.m_contactFactory.Create(a,b)}};Box2D.Dynamics.b2ContactManager.prototype.FindNewContacts=function(){var a=this;this.m_broadPhase.UpdatePairs(function(b,
c){a.AddPair(b,c)})};Box2D.Dynamics.b2ContactManager.prototype.Destroy=function(a){var b=a.m_fixtureB;a.m_fixtureA.GetBody();b.GetBody();a.touching&&this.m_contactListener.EndContact(a);0<a.m_manifold.m_pointCount&&(a.m_fixtureA.GetBody().SetAwake(!0),a.m_fixtureB.GetBody().SetAwake(!0));a.RemoveFromLists();this.m_contactFactory.Destroy(a)};Box2D.Dynamics.b2ContactManager.prototype.Collide=function(){for(var a=this.m_world.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=
a.GetNextNode()){var b=a.contact,c=b.m_fixtureA,d=b.m_fixtureB,e=c.GetBody(),g=d.GetBody();if(!(!1==e.IsAwake()&&!1==g.IsAwake())){if(b.IsFiltering()){if(!1==g.ShouldCollide(e)){this.Destroy(b);continue}if(!1==this.m_contactFilter.ShouldCollide(c,d)){this.Destroy(b);continue}b.ClearFiltering()}!1==this.m_broadPhase.TestOverlap(c.m_proxy,d.m_proxy)?this.Destroy(b):b.Update(this.m_contactListener)}}};Box2D.Dynamics.b2DestructionListener=function(){};Box2D.Dynamics.b2DestructionListener.prototype.SayGoodbyeJoint=
function(a){};Box2D.Dynamics.b2DestructionListener.prototype.SayGoodbyeFixture=function(a){};Box2D.Dynamics.b2FilterData=function(){this.categoryBits=1;this.maskBits=65535;this.groupIndex=0};Box2D.Dynamics.b2FilterData.prototype.Copy=function(){var a=new Box2D.Dynamics.b2FilterData;a.categoryBits=this.categoryBits;a.maskBits=this.maskBits;a.groupIndex=this.groupIndex;return a};Box2D.Dynamics.b2Fixture=function(a,b,c){this.ID="Fixture"+Box2D.Dynamics.b2Fixture.NEXT_ID++;this.m_filter=c.filter.Copy();
this.m_aabb=Box2D.Collision.b2AABB.Get();this.m_body=a;this.m_shape=c.shape.Copy();this.m_density=c.density;this.m_friction=c.friction;this.m_restitution=c.restitution;this.m_isSensor=c.isSensor};Box2D.Dynamics.b2Fixture.prototype.GetShape=function(){return this.m_shape};Box2D.Dynamics.b2Fixture.prototype.SetSensor=function(a){if(this.m_isSensor!=a&&(this.m_isSensor=a,null!=this.m_body))for(a=this.m_body.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=a.GetNextNode()){var b=
a.contact.m_fixtureA,c=a.contact.m_fixtureB;if(b==this||c==this)a.contact.SetSensor(b.sensor||c.sensor)}};Box2D.Dynamics.b2Fixture.prototype.IsSensor=function(){return this.m_isSensor};Box2D.Dynamics.b2Fixture.prototype.SetFilterData=function(a){this.m_filter=a.Copy();if(null!=this.m_body)for(a=this.m_body.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=a.GetNextNode())(a.contact.m_fixtureA==this||a.contact.m_fixtureB==this)&&a.contact.FlagForFiltering()};Box2D.Dynamics.b2Fixture.prototype.GetFilterData=
function(){return this.m_filter.Copy()};Box2D.Dynamics.b2Fixture.prototype.GetBody=function(){return this.m_body};Box2D.Dynamics.b2Fixture.prototype.TestPoint=function(a){return this.m_shape.TestPoint(this.m_body.GetTransform(),a)};Box2D.Dynamics.b2Fixture.prototype.RayCast=function(a,b){return this.m_shape.RayCast(a,b,this.m_body.GetTransform())};Box2D.Dynamics.b2Fixture.prototype.GetMassData=function(a){a||(a=new Box2D.Collision.Shapes.b2MassData);this.m_shape.ComputeMass(a,this.m_density);return a};
Box2D.Dynamics.b2Fixture.prototype.SetDensity=function(a){this.m_density=a};Box2D.Dynamics.b2Fixture.prototype.GetDensity=function(){return this.m_density};Box2D.Dynamics.b2Fixture.prototype.GetFriction=function(){return this.m_friction};Box2D.Dynamics.b2Fixture.prototype.SetFriction=function(a){this.m_friction=a};Box2D.Dynamics.b2Fixture.prototype.GetRestitution=function(){return this.m_restitution};Box2D.Dynamics.b2Fixture.prototype.SetRestitution=function(a){this.m_restitution=a};Box2D.Dynamics.b2Fixture.prototype.GetAABB=
function(){return this.m_aabb};Box2D.Dynamics.b2Fixture.prototype.Destroy=function(){Box2D.Collision.b2AABB.Free(this.m_aabb)};Box2D.Dynamics.b2Fixture.prototype.CreateProxy=function(a,b){this.m_shape.ComputeAABB(this.m_aabb,b);this.m_proxy=a.CreateProxy(this.m_aabb,this)};Box2D.Dynamics.b2Fixture.prototype.DestroyProxy=function(a){null!=this.m_proxy&&(a.DestroyProxy(this.m_proxy),this.m_proxy=null)};Box2D.Dynamics.b2Fixture.prototype.Synchronize=function(a,b,c){if(this.m_proxy){var d=Box2D.Collision.b2AABB.Get(),
e=Box2D.Collision.b2AABB.Get();this.m_shape.ComputeAABB(d,b);this.m_shape.ComputeAABB(e,c);this.m_aabb.Combine(d,e);Box2D.Collision.b2AABB.Free(d);Box2D.Collision.b2AABB.Free(e);b=Box2D.Common.Math.b2Math.SubtractVV(c.position,b.position);a.MoveProxy(this.m_proxy,this.m_aabb,b);Box2D.Common.Math.b2Vec2.Free(b)}};Box2D.Dynamics.b2Fixture.NEXT_ID=0;Box2D.Dynamics.b2FixtureDef=function(){this.filter=new Box2D.Dynamics.b2FilterData;this.filter.categoryBits=1;this.filter.maskBits=65535;this.filter.groupIndex=
0;this.shape=null;this.friction=0.2;this.density=this.restitution=0;this.isSensor=!1};Box2D.Dynamics.b2FixtureList=function(){this.fixtureLastNode=this.fixtureFirstNode=null;this.fixtureNodeLookup={};this.fixtureCount=0};Box2D.Dynamics.b2FixtureList.prototype.GetFirstNode=function(){return this.fixtureFirstNode};Box2D.Dynamics.b2FixtureList.prototype.AddFixture=function(a){var b=a.ID;if(null==this.fixtureNodeLookup[b]){a=new Box2D.Dynamics.b2FixtureListNode(a);var c=this.fixtureLastNode;null!=c?c.SetNextNode(a):
this.fixtureFirstNode=a;a.SetPreviousNode(c);this.fixtureLastNode=a;this.fixtureNodeLookup[b]=a;this.fixtureCount++}};Box2D.Dynamics.b2FixtureList.prototype.RemoveFixture=function(a){a=a.ID;var b=this.fixtureNodeLookup[a];if(null!=b){var c=b.GetPreviousNode(),b=b.GetNextNode();null==c?this.fixtureFirstNode=b:c.SetNextNode(b);null==b?this.fixtureLastNode=c:b.SetPreviousNode(c);delete this.fixtureNodeLookup[a];this.fixtureCount--}};Box2D.Dynamics.b2FixtureList.prototype.GetFixtureCount=function(){return this.fixtureCount};
Box2D.Dynamics.b2FixtureListNode=function(a){this.fixture=a;this.previous=this.next=null};Box2D.Dynamics.b2FixtureListNode.prototype.SetNextNode=function(a){this.next=a};Box2D.Dynamics.b2FixtureListNode.prototype.SetPreviousNode=function(a){this.previous=a};Box2D.Dynamics.b2FixtureListNode.prototype.GetNextNode=function(){return this.next};Box2D.Dynamics.b2FixtureListNode.prototype.GetPreviousNode=function(){return this.previous};Box2D.Dynamics.b2Island=function(a,b){this.m_listener=a;this.m_contactSolver=
b;this.m_bodies=[];this.m_dynamicBodies=[];this.m_nonStaticBodies=[];this.m_contacts=[];this.m_joints=[]};Box2D.Dynamics.b2Island.prototype.Clear=function(){this.m_bodies=[];this.m_dynamicBodies=[];this.m_nonStaticBodies=[];this.m_contacts=[];this.m_joints=[]};Box2D.Dynamics.b2Island.prototype.Solve=function(a,b,c){this._InitializeVelocities(a,b);this.m_contactSolver.Initialize(a,this.m_contacts,this.m_contacts.length);this._SolveVelocityConstraints(a);this._SolveBodies(a);this._SolvePositionConstraints(a);
this.Report(this.m_contactSolver.m_constraints);c&&this._SleepIfTired(a)};Box2D.Dynamics.b2Island.prototype._InitializeVelocities=function(a,b){for(var c=0;c<this.m_dynamicBodies.length;c++){var d=this.m_dynamicBodies[c];d.m_linearVelocity.x+=a.dt*(b.x+d.m_invMass*d.m_force.x);d.m_linearVelocity.y+=a.dt*(b.y+d.m_invMass*d.m_force.y);d.m_angularVelocity+=a.dt*d.m_invI*d.m_torque;d.m_linearVelocity.Multiply(Box2D.Common.Math.b2Math.Clamp(1-a.dt*d.m_linearDamping,0,1));d.m_angularVelocity*=Box2D.Common.Math.b2Math.Clamp(1-
a.dt*d.m_angularDamping,0,1)}};Box2D.Dynamics.b2Island.prototype._SolveVelocityConstraints=function(a){this.m_contactSolver.InitVelocityConstraints(a);for(var b=0;b<this.m_joints.length;b++)this.m_joints[b].InitVelocityConstraints(a);for(b=0;b<a.velocityIterations;b++){for(var c=0;c<this.m_joints.length;c++)this.m_joints[c].SolveVelocityConstraints(a);this.m_contactSolver.SolveVelocityConstraints()}for(a=0;a<this.m_joints.length;a++)this.m_joints[a].FinalizeVelocityConstraints();this.m_contactSolver.FinalizeVelocityConstraints()};
Box2D.Dynamics.b2Island.prototype._SolveBodies=function(a){for(var b=0;b<this.m_nonStaticBodies.length;++b){var c=this.m_nonStaticBodies[b],d=a.dt*c.m_linearVelocity.x,e=a.dt*c.m_linearVelocity.y;d*d+e*e>Box2D.Common.b2Settings.b2_maxTranslationSquared&&(c.m_linearVelocity.Normalize(),c.m_linearVelocity.x*=Box2D.Common.b2Settings.b2_maxTranslation*a.inv_dt,c.m_linearVelocity.y*=Box2D.Common.b2Settings.b2_maxTranslation*a.inv_dt);d=a.dt*c.m_angularVelocity;d*d>Box2D.Common.b2Settings.b2_maxRotationSquared&&
(c.m_angularVelocity=0>c.m_angularVelocity?-Box2D.Common.b2Settings.b2_maxRotation*a.inv_dt:Box2D.Common.b2Settings.b2_maxRotation*a.inv_dt);c.m_sweep.c0.SetV(c.m_sweep.c);c.m_sweep.a0=c.m_sweep.a;c.m_sweep.c.x+=a.dt*c.m_linearVelocity.x;c.m_sweep.c.y+=a.dt*c.m_linearVelocity.y;c.m_sweep.a+=a.dt*c.m_angularVelocity;c.SynchronizeTransform()}};Box2D.Dynamics.b2Island.prototype._SolvePositionConstraints=function(a){for(var b=0;b<a.positionIterations;b++){for(var c=this.m_contactSolver.SolvePositionConstraints(Box2D.Common.b2Settings.b2_contactBaumgarte),
d=!0,e=0;e<this.m_joints.length;e++)var g=this.m_joints[e].SolvePositionConstraints(Box2D.Common.b2Settings.b2_contactBaumgarte),d=d&&g;if(c&&d)break}};Box2D.Dynamics.b2Island.prototype._SleepIfTired=function(a){for(var b=Number.MAX_VALUE,c=0;c<this.m_nonStaticBodies.length;c++){var d=this.m_nonStaticBodies[c];!d.m_allowSleep||Math.abs(d.m_angularVelocity)>Box2D.Common.b2Settings.b2_angularSleepTolerance||Box2D.Common.Math.b2Math.Dot(d.m_linearVelocity,d.m_linearVelocity)>Box2D.Common.b2Settings.b2_linearSleepToleranceSquared?
b=d.m_sleepTime=0:(d.m_sleepTime+=a.dt,b=Math.min(b,d.m_sleepTime))}if(b>=Box2D.Common.b2Settings.b2_timeToSleep)for(a=0;a<this.m_bodies.length;a++)this.m_bodies[a].SetAwake(!1)};Box2D.Dynamics.b2Island.prototype.SolveTOI=function(a){var b=0,c=0;this.m_contactSolver.Initialize(a,this.m_contacts,this.m_contacts.length);for(var d=this.m_contactSolver,b=0;b<this.m_joints.length;++b)this.m_joints[b].InitVelocityConstraints(a);for(b=0;b<a.velocityIterations;++b){d.SolveVelocityConstraints();for(c=0;c<
this.m_joints.length;++c)this.m_joints[c].SolveVelocityConstraints(a)}for(b=0;b<this.m_nonStaticBodies.length;++b){var c=this.m_nonStaticBodies[b],e=a.dt*c.m_linearVelocity.x,g=a.dt*c.m_linearVelocity.y;e*e+g*g>Box2D.Common.b2Settings.b2_maxTranslationSquared&&(c.m_linearVelocity.Normalize(),c.m_linearVelocity.x*=Box2D.Common.b2Settings.b2_maxTranslation*a.inv_dt,c.m_linearVelocity.y*=Box2D.Common.b2Settings.b2_maxTranslation*a.inv_dt);e=a.dt*c.m_angularVelocity;e*e>Box2D.Common.b2Settings.b2_maxRotationSquared&&
(c.m_angularVelocity=0>c.m_angularVelocity?-Box2D.Common.b2Settings.b2_maxRotation*a.inv_dt:Box2D.Common.b2Settings.b2_maxRotation*a.inv_dt);c.m_sweep.c0.SetV(c.m_sweep.c);c.m_sweep.a0=c.m_sweep.a;c.m_sweep.c.x+=a.dt*c.m_linearVelocity.x;c.m_sweep.c.y+=a.dt*c.m_linearVelocity.y;c.m_sweep.a+=a.dt*c.m_angularVelocity;c.SynchronizeTransform()}for(b=0;b<a.positionIterations;++b){e=d.SolvePositionConstraints(0.75);g=!0;for(c=0;c<this.m_joints.length;++c)var f=this.m_joints[c].SolvePositionConstraints(Box2D.Common.b2Settings.b2_contactBaumgarte),
g=g&&f;if(e&&g)break}this.Report(d.m_constraints)};Box2D.Dynamics.b2Island.prototype.Report=function(a){if(null!=this.m_listener)for(var b=0;b<this.m_contacts.length;++b){for(var c=this.m_contacts[b],d=a[b],e=new Box2D.Dynamics.b2ContactImpulse,g=0;g<d.pointCount;++g)e.normalImpulses[g]=d.points[g].normalImpulse,e.tangentImpulses[g]=d.points[g].tangentImpulse;this.m_listener.PostSolve(c,e)}};Box2D.Dynamics.b2Island.prototype.AddBody=function(a){this.m_bodies.push(a);a.GetType()!=Box2D.Dynamics.b2BodyDef.b2_staticBody&&
(this.m_nonStaticBodies.push(a),a.GetType()==Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&this.m_dynamicBodies.push(a))};Box2D.Dynamics.b2Island.prototype.AddContact=function(a){this.m_contacts.push(a)};Box2D.Dynamics.b2Island.prototype.AddJoint=function(a){this.m_joints.push(a)};Box2D.Dynamics.b2TimeStep=function(a,b,c,d,e){this.dt=a;var g=0;0<a&&(g=1/a);this.inv_dt=g;this.dtRatio=b;this.positionIterations=c;this.velocityIterations=d;this.warmStarting=e};Box2D.Dynamics.b2World=function(a,b){this.m_contactManager=
new Box2D.Dynamics.b2ContactManager(this);this.m_contactSolver=new Box2D.Dynamics.Contacts.b2ContactSolver;this.m_newFixture=this.m_isLocked=!1;this.m_destructionListener=null;this.bodyList=new Box2D.Dynamics.b2BodyList;this.contactList=new Box2D.Dynamics.Contacts.b2ContactList;this.m_jointList=null;this.controllerList=new Box2D.Dynamics.Controllers.b2ControllerList;this.m_jointCount=0;this.m_continuousPhysics=this.m_warmStarting=!0;this.m_allowSleep=b;this.m_gravity=a;this.m_inv_dt0=0;this.m_groundBody=
this.CreateBody(new Box2D.Dynamics.b2BodyDef)};Box2D.Dynamics.b2World.MAX_TOI=1-100*Number.MIN_VALUE;Box2D.Dynamics.b2World.prototype.SetDestructionListener=function(a){this.m_destructionListener=a};Box2D.Dynamics.b2World.prototype.SetContactFilter=function(a){this.m_contactManager.m_contactFilter=a};Box2D.Dynamics.b2World.prototype.SetContactListener=function(a){this.m_contactManager.m_contactListener=a};Box2D.Dynamics.b2World.prototype.SetBroadPhase=function(a){var b=this.m_contactManager.m_broadPhase;
this.m_contactManager.m_broadPhase=a;for(var c=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);c;c=c.GetNextNode())for(var d=c.body.GetFixtureList().GetFirstNode();d;d=d.GetNextNode()){var e=d.fixture;e.m_proxy=a.CreateProxy(b.GetFatAABB(e.m_proxy),e)}};Box2D.Dynamics.b2World.prototype.GetProxyCount=function(){return this.m_contactManager.m_broadPhase.GetProxyCount()};Box2D.Dynamics.b2World.prototype.CreateBody=function(a){a=new Box2D.Dynamics.b2Body(a,this);this.bodyList.AddBody(a);
return a};Box2D.Dynamics.b2World.prototype.DestroyBody=function(a){for(var b=a.m_jointList;b;){var c=b,b=b.next;this.m_destructionListener&&this.m_destructionListener.SayGoodbyeJoint(c.joint);this.DestroyJoint(c.joint)}for(b=a.GetControllerList().GetFirstNode();b;b=b.GetNextNode())b.controller.RemoveBody(a);for(b=a.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);b;b=b.GetNextNode())this.m_contactManager.Destroy(b.contact);for(b=a.GetFixtureList().GetFirstNode();b;b=
b.GetNextNode())this.m_destructionListener&&this.m_destructionListener.SayGoodbyeFixture(b.fixture),a.DestroyFixture(b.fixture);a.Destroy();this.bodyList.RemoveBody(a)};Box2D.Dynamics.b2World.prototype.CreateJoint=function(a){var b=Box2D.Dynamics.Joints.b2Joint.Create(a);b.m_prev=null;if(b.m_next=this.m_jointList)this.m_jointList.m_prev=b;this.m_jointList=b;this.m_jointCount++;b.m_edgeA.joint=b;b.m_edgeA.other=b.m_bodyB;b.m_edgeA.prev=null;if(b.m_edgeA.next=b.m_bodyA.m_jointList)b.m_bodyA.m_jointList.prev=
b.m_edgeA;b.m_bodyA.m_jointList=b.m_edgeA;b.m_edgeB.joint=b;b.m_edgeB.other=b.m_bodyA;b.m_edgeB.prev=null;if(b.m_edgeB.next=b.m_bodyB.m_jointList)b.m_bodyB.m_jointList.prev=b.m_edgeB;b.m_bodyB.m_jointList=b.m_edgeB;var c=a.bodyA,d=a.bodyB;if(!a.collideConnected)for(a=d.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=a.GetNextNode())a.contact.GetOther(d)==c&&a.contact.FlagForFiltering();return b};Box2D.Dynamics.b2World.prototype.DestroyJoint=function(a){var b=
a.m_collideConnected;a.m_prev&&(a.m_prev.m_next=a.m_next);a.m_next&&(a.m_next.m_prev=a.m_prev);a==this.m_jointList&&(this.m_jointList=a.m_next);var c=a.m_bodyA,d=a.m_bodyB;c.SetAwake(!0);d.SetAwake(!0);a.m_edgeA.prev&&(a.m_edgeA.prev.next=a.m_edgeA.next);a.m_edgeA.next&&(a.m_edgeA.next.prev=a.m_edgeA.prev);a.m_edgeA==c.m_jointList&&(c.m_jointList=a.m_edgeA.next);a.m_edgeA.prev=null;a.m_edgeA.next=null;a.m_edgeB.prev&&(a.m_edgeB.prev.next=a.m_edgeB.next);a.m_edgeB.next&&(a.m_edgeB.next.prev=a.m_edgeB.prev);
a.m_edgeB==d.m_jointList&&(d.m_jointList=a.m_edgeB.next);a.m_edgeB.prev=null;a.m_edgeB.next=null;this.m_jointCount--;if(!b)for(a=d.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);a;a=a.GetNextNode())a.contact.GetOther(d)==c&&a.contact.FlagForFiltering()};Box2D.Dynamics.b2World.prototype.GetControllerList=function(){return this.controllerList};Box2D.Dynamics.b2World.prototype.AddController=function(a){if(null!==a.m_world&&a.m_world!=this)throw Error("Controller can only be a member of one world");
this.controllerList.AddController(a);a.m_world=this;return a};Box2D.Dynamics.b2World.prototype.RemoveController=function(a){this.controllerList.RemoveController(a);a.m_world=null;a.Clear()};Box2D.Dynamics.b2World.prototype.CreateController=function(a){return this.AddController(a)};Box2D.Dynamics.b2World.prototype.DestroyController=function(a){this.RemoveController(a)};Box2D.Dynamics.b2World.prototype.SetWarmStarting=function(a){this.m_warmStarting=a};Box2D.Dynamics.b2World.prototype.SetContinuousPhysics=
function(a){this.m_continuousPhysics=a};Box2D.Dynamics.b2World.prototype.GetBodyCount=function(){return this.bodyList.GetBodyCount()};Box2D.Dynamics.b2World.prototype.GetJointCount=function(){return this.m_jointCount};Box2D.Dynamics.b2World.prototype.GetContactCount=function(){return this.contactList.GetContactCount()};Box2D.Dynamics.b2World.prototype.SetGravity=function(a){this.m_gravity=a};Box2D.Dynamics.b2World.prototype.GetGravity=function(){return this.m_gravity};Box2D.Dynamics.b2World.prototype.GetGroundBody=
function(){return this.m_groundBody};Box2D.Dynamics.b2World.prototype.Step=function(a,b,c){this.m_newFixture&&(this.m_contactManager.FindNewContacts(),this.m_newFixture=!1);this.m_isLocked=!0;a=new Box2D.Dynamics.b2TimeStep(a,this.m_inv_dt0*a,b,c,this.m_warmStarting);this.m_contactManager.Collide();0<a.dt&&(this.Solve(a),this.m_continuousPhysics&&this.SolveTOI(a),this.m_inv_dt0=a.inv_dt);this.m_isLocked=!1};Box2D.Dynamics.b2World.prototype.ClearForces=function(){for(var a=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.dynamicBodies);a;a=
a.GetNextNode())a.body.m_force.SetZero(),a.body.m_torque=0};Box2D.Dynamics.b2World.prototype.QueryAABB=function(a,b){this.m_contactManager.m_broadPhase.Query(a,b)};Box2D.Dynamics.b2World.prototype.QueryPoint=function(a,b){var c=Box2D.Collision.b2AABB.Get();c.lowerBound_.Set(b.x-Box2D.Common.b2Settings.b2_linearSlop,b.y-Box2D.Common.b2Settings.b2_linearSlop);c.upperBound_.Set(b.x+Box2D.Common.b2Settings.b2_linearSlop,b.y+Box2D.Common.b2Settings.b2_linearSlop);this.m_contactManager.m_broadPhase.Query(function(c){return c.TestPoint(b)?
a(c):!0},c);Box2D.Collision.b2AABB.Free(c)};Box2D.Dynamics.b2World.prototype.RayCast=function(a,b,c){var d=this.m_contactManager.m_broadPhase,e=new Box2D.Collision.b2RayCastOutput,g=new Box2D.Collision.b2RayCastInput(b,c,1);d.RayCast(function(d,g){if(g.RayCast(e,d)){var k=1-e.fraction,k=Box2D.Common.Math.b2Vec2.Get(k*b.x+e.fraction*c.x,k*b.y+e.fraction*c.y),h=a(g,k,e.normal,e.fraction);Box2D.Common.Math.b2Vec2.Free(k);return h}return d.maxFraction},g)};Box2D.Dynamics.b2World.prototype.RayCastOne=
function(a,b){var c=null;this.RayCast(function(a,b,g,f){c=a;return f},a,b);return c};Box2D.Dynamics.b2World.prototype.RayCastAll=function(a,b){var c=[];this.RayCast(function(a,b,g,f){c.push(a);return 1},a,b);return c};Box2D.Dynamics.b2World.prototype.GetBodyList=function(){return this.bodyList};Box2D.Dynamics.b2World.prototype.GetJointList=function(){return this.m_jointList};Box2D.Dynamics.b2World.prototype.GetContactList=function(){return this.contactList};Box2D.Dynamics.b2World.prototype.IsLocked=
function(){return this.m_isLocked};var b2solvearray=[];Box2D.Dynamics.b2World.prototype.Solve=function(a){for(var b=this.controllerList.GetFirstNode();b;b=b.GetNextNode())b.controller.Step(a);for(var b=new Box2D.Dynamics.b2Island(this.m_contactManager.m_contactListener,this.m_contactSolver),c=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);c;c=c.GetNextNode())c.body.m_islandFlag=!1;for(var d=this.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);d;d=
d.GetNextNode())d.contact.m_islandFlag=!1;for(c=this.m_jointList;c;c=c.m_next)c.m_islandFlag=!1;for(c=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.nonStaticActiveAwakeBodies);c;c=c.GetNextNode())if(d=c.body,!d.m_islandFlag){b.Clear();b2solvearray.length=0;var e=b2solvearray;e.push(d);for(d.m_islandFlag=!0;0<e.length;){var g=e.pop();b.AddBody(g);g.IsAwake()||g.SetAwake(!0);if(g.GetType()!=Box2D.Dynamics.b2BodyDef.b2_staticBody){for(d=g.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledTouchingContacts);d;d=
d.GetNextNode()){var f=d.contact;f.m_islandFlag||(b.AddContact(f),f.m_islandFlag=!0,f=f.GetOther(g),f.m_islandFlag||(e.push(f),f.m_islandFlag=!0))}for(d=g.m_jointList;d;d=d.next)!d.joint.m_islandFlag&&d.other.IsActive()&&(b.AddJoint(d.joint),d.joint.m_islandFlag=!0,d.other.m_islandFlag||(e.push(d.other),d.other.m_islandFlag=!0))}}b.Solve(a,this.m_gravity,this.m_allowSleep)}for(c=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.nonStaticActiveAwakeBodies);c;c=c.GetNextNode())c.body.SynchronizeFixtures();
this.m_contactManager.FindNewContacts()};Box2D.Dynamics.b2World.prototype.SolveTOI=function(a){for(var b=new Box2D.Dynamics.b2Island(this.m_contactManager.m_contactListener,this.m_contactSolver),c=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);c;c=c.GetNextNode()){var d=c.body;d.m_islandFlag=!1;d.m_sweep.t0=0}for(var e=this.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);e;e=e.GetNextNode())e.contact.m_islandFlag=!1,e.contact.m_toi=null;for(c=
this.m_jointList;c;c=c.m_next)c.m_islandFlag=!1;for(;;){var c=this._SolveTOI2(a),g=c.minContact,c=c.minTOI;if(null===g||Box2D.Dynamics.b2World.MAX_TOI<c)break;e=g.m_fixtureA.GetBody();d=g.m_fixtureB.GetBody();Box2D.Dynamics.b2World.s_backupA.Set(e.m_sweep);Box2D.Dynamics.b2World.s_backupB.Set(d.m_sweep);e.Advance(c);d.Advance(c);g.Update(this.m_contactManager.m_contactListener);g.m_toi=null;if(g.sensor||!g.enabled)e.m_sweep.Set(Box2D.Dynamics.b2World.s_backupA),d.m_sweep.Set(Box2D.Dynamics.b2World.s_backupB),
e.SynchronizeTransform(),d.SynchronizeTransform();else if(g.touching){e.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody&&(e=d);b.Clear();b2solvearray.length=0;g=b2solvearray;g.push(e);for(e.m_islandFlag=!0;0<g.length;)if(d=g.pop(),b.AddBody(d),d.IsAwake()||d.SetAwake(!0),d.GetType()==Box2D.Dynamics.b2BodyDef.b2_dynamicBody){for(e=d.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledTouchingContacts);e&&b.m_contactCount!=Box2D.Common.b2Settings.b2_maxTOIContactsPerIsland;e=
e.GetNextNode()){var f=e.contact;f.m_islandFlag||(b.AddContact(f),f.m_islandFlag=!0,f=f.GetOther(d),f.m_islandFlag||(f.GetType()!=Box2D.Dynamics.b2BodyDef.b2_staticBody&&(f.Advance(c),f.SetAwake(!0),g.push(f)),f.m_islandFlag=!0))}for(d=d.m_jointList;d;d=d.next)b.m_jointCount!=Box2D.Common.b2Settings.b2_maxTOIJointsPerIsland&&(!d.joint.m_islandFlag&&d.other.IsActive())&&(b.AddJoint(d.joint),d.joint.m_islandFlag=!0,d.other.m_islandFlag||(d.other.GetType()!=Box2D.Dynamics.b2BodyDef.b2_staticBody&&(d.other.Advance(c),
d.other.SetAwake(!0),g.push(d.other)),d.other.m_islandFlag=!0))}b.SolveTOI(new Box2D.Dynamics.b2TimeStep((1-c)*a.dt,0,a.velocityIterations,a.positionIterations,!1));for(c=0;c<b.m_bodies.length;c++)if(b.m_bodies[c].m_islandFlag=!1,b.m_bodies[c].IsAwake()&&b.m_bodies[c].GetType()==Box2D.Dynamics.b2BodyDef.b2_dynamicBody){b.m_bodies[c].SynchronizeFixtures();for(e=b.m_bodies[c].contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);e;e=e.GetNextNode())e.contact.m_toi=null}for(c=
0;c<b.m_contactCount;c++)b.m_contacts[c].m_islandFlag=!1,b.m_contacts[c].m_toi=null;for(c=0;c<b.m_jointCount;c++)b.m_joints[c].m_islandFlag=!1;this.m_contactManager.FindNewContacts()}}};Box2D.Dynamics.b2World.prototype._SolveTOI2=function(a){for(var b=null,c=1,d=this.contactList.GetFirstNode(Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledContinuousContacts);d;d=d.GetNextNode()){var e=d.contact;if(!this._SolveTOI2SkipContact(a,e)){var g=1;if(null!=e.m_toi)g=e.m_toi;else{if(e.touching)g=
1;else{var g=e.m_fixtureA.GetBody(),f=e.m_fixtureB.GetBody(),l=g.m_sweep.t0;g.m_sweep.t0<f.m_sweep.t0?(l=f.m_sweep.t0,g.m_sweep.Advance(l)):f.m_sweep.t0<g.m_sweep.t0&&(l=g.m_sweep.t0,f.m_sweep.Advance(l));g=e.ComputeTOI(g.m_sweep,f.m_sweep);0<g&&1>g&&(g=(1-g)*l+g)}e.m_toi=g}Number.MIN_VALUE<g&&g<c&&(b=e,c=g)}}return{minContact:b,minTOI:c}};Box2D.Dynamics.b2World.prototype._SolveTOI2SkipContact=function(a,b){var c=b.m_fixtureA.GetBody(),d=b.m_fixtureB.GetBody();return(c.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||
!c.IsAwake())&&(d.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||!d.IsAwake())?!0:!1};Box2D.Dynamics.Contacts.b2Contact=function(a,b){this.ID="Contact"+Box2D.Dynamics.Contacts.b2Contact.NEXT_ID++;this.m_manifold=new Box2D.Collision.b2Manifold;this.m_oldManifold=new Box2D.Collision.b2Manifold;this.touching=!1;var c=a.GetBody(),d=b.GetBody();this.continuous=c.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||c.IsBullet()||d.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||d.IsBullet();this.sensor=
a.IsSensor()||b.IsSensor();this.filtering=!1;this.m_fixtureA=a;this.m_fixtureB=b;this.enabled=!0;this.bodyAList=c.GetContactList();this.bodyBList=d.GetContactList();this.worldList=d.GetWorld().GetContactList();this.AddToLists()};Box2D.Dynamics.Contacts.b2Contact.prototype.Reset=function(a,b){this.m_manifold.Reset();this.m_oldManifold.Reset();this.touching=!1;var c=a.GetBody(),d=b.GetBody();this.continuous=c.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||c.IsBullet()||d.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||
d.IsBullet();this.sensor=a.IsSensor()||b.IsSensor();this.filtering=!1;this.m_fixtureA=a;this.m_fixtureB=b;this.enabled=!0;this.bodyAList=c.GetContactList();this.bodyBList=d.GetContactList();this.worldList=d.GetWorld().GetContactList();this.AddToLists()};Box2D.Dynamics.Contacts.b2Contact.prototype.AddToLists=function(){this.bodyAList.AddContact(this);this.bodyBList.AddContact(this);this.worldList.AddContact(this);this.UpdateLists()};Box2D.Dynamics.Contacts.b2Contact.prototype.UpdateLists=function(){var a=
!1,b=!1;!this.IsSensor()&&this.IsEnabled()&&(this.IsTouching()&&(a=!0),this.IsContinuous()&&(b=!0));this.bodyAList.UpdateContact(this,a,b);this.bodyBList.UpdateContact(this,a,b);this.worldList.UpdateContact(this,a,b)};Box2D.Dynamics.Contacts.b2Contact.prototype.RemoveFromLists=function(){this.bodyAList.RemoveContact(this);this.bodyBList.RemoveContact(this);this.worldList.RemoveContact(this)};Box2D.Dynamics.Contacts.b2Contact.prototype.GetManifold=function(){return this.m_manifold};Box2D.Dynamics.Contacts.b2Contact.prototype.GetWorldManifold=
function(a){var b=this.m_fixtureA.GetBody(),c=this.m_fixtureB.GetBody(),d=this.m_fixtureA.GetShape(),e=this.m_fixtureB.GetShape();a.Initialize(this.m_manifold,b.GetTransform(),d.m_radius,c.GetTransform(),e.m_radius)};Box2D.Dynamics.Contacts.b2Contact.prototype.IsTouching=function(){return this.touching};Box2D.Dynamics.Contacts.b2Contact.prototype.IsContinuous=function(){return this.continuous};Box2D.Dynamics.Contacts.b2Contact.prototype.SetSensor=function(a){this.sensor=a;this.UpdateLists()};Box2D.Dynamics.Contacts.b2Contact.prototype.IsSensor=
function(){return this.sensor};Box2D.Dynamics.Contacts.b2Contact.prototype.SetEnabled=function(a){this.enabled=a;this.UpdateLists()};Box2D.Dynamics.Contacts.b2Contact.prototype.IsEnabled=function(){return this.enabled};Box2D.Dynamics.Contacts.b2Contact.prototype.GetNext=function(){return this.m_next};Box2D.Dynamics.Contacts.b2Contact.prototype.GetFixtureA=function(){return this.m_fixtureA};Box2D.Dynamics.Contacts.b2Contact.prototype.GetFixtureB=function(){return this.m_fixtureB};Box2D.Dynamics.Contacts.b2Contact.prototype.GetOther=
function(a){var b=this.m_fixtureA.GetBody();return b!=a?b:this.m_fixtureB.GetBody()};Box2D.Dynamics.Contacts.b2Contact.prototype.FlagForFiltering=function(){this.filtering=!0};Box2D.Dynamics.Contacts.b2Contact.prototype.ClearFiltering=function(){this.filtering=!1};Box2D.Dynamics.Contacts.b2Contact.prototype.IsFiltering=function(){return this.filtering};Box2D.Dynamics.Contacts.b2Contact.prototype.Update=function(a){var b=this.m_oldManifold;this.m_oldManifold=this.m_manifold;this.m_manifold=b;this.enabled=
!0;var b=!1,c=this.IsTouching(),d=this.m_fixtureA.GetBody(),e=this.m_fixtureB.GetBody(),g=this.m_fixtureA.m_aabb.TestOverlap(this.m_fixtureB.m_aabb);if(this.sensor)g&&(b=Box2D.Collision.Shapes.b2Shape.TestOverlap(this.m_fixtureA.GetShape(),d.GetTransform(),this.m_fixtureB.GetShape(),e.GetTransform())),this.m_manifold.m_pointCount=0;else{d.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||d.IsBullet()||e.GetType()!=Box2D.Dynamics.b2BodyDef.b2_dynamicBody||e.IsBullet()?this.continuous=!0:this.continuous=
!1;if(g){this.Evaluate();b=0<this.m_manifold.m_pointCount;for(g=0;g<this.m_manifold.m_pointCount;g++){var f=this.m_manifold.m_points[g];f.m_normalImpulse=0;for(var l=f.m_tangentImpulse=0;l<this.m_oldManifold.m_pointCount;l++){var k=this.m_oldManifold.m_points[l];if(k.m_id.GetKey()==f.m_id.GetKey()){f.m_normalImpulse=k.m_normalImpulse;f.m_tangentImpulse=k.m_tangentImpulse;break}}}}else this.m_manifold.m_pointCount=0;b!=c&&(d.SetAwake(!0),e.SetAwake(!0))}this.touching=b;b!=c&&this.UpdateLists();!c&&
b&&a.BeginContact(this);c&&!b&&a.EndContact(this);this.sensor||a.PreSolve(this,this.m_oldManifold)};Box2D.Dynamics.Contacts.b2Contact.prototype.Evaluate=function(){};Box2D.Dynamics.Contacts.b2Contact.prototype.ComputeTOI=function(a,b){Box2D.Dynamics.Contacts.b2Contact.s_input.proxyA.Set(this.m_fixtureA.GetShape());Box2D.Dynamics.Contacts.b2Contact.s_input.proxyB.Set(this.m_fixtureB.GetShape());Box2D.Dynamics.Contacts.b2Contact.s_input.sweepA=a;Box2D.Dynamics.Contacts.b2Contact.s_input.sweepB=b;Box2D.Dynamics.Contacts.b2Contact.s_input.tolerance=
Box2D.Common.b2Settings.b2_linearSlop;return Box2D.Collision.b2TimeOfImpact.TimeOfImpact(Box2D.Dynamics.Contacts.b2Contact.s_input)};Box2D.Dynamics.Contacts.b2Contact.s_input=new Box2D.Collision.b2TOIInput;Box2D.Dynamics.Contacts.b2Contact.NEXT_ID=0;Box2D.Dynamics.Contacts.b2CircleContact=function(a,b){Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};c2inherit(Box2D.Dynamics.Contacts.b2CircleContact,Box2D.Dynamics.Contacts.b2Contact);Box2D.Dynamics.Contacts.b2CircleContact.prototype.Reset=function(a,
b){Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};Box2D.Dynamics.Contacts.b2CircleContact.prototype.Evaluate=function(){Box2D.Collision.b2Collision.CollideCircles(this.m_manifold,this.m_fixtureA.GetShape(),this.m_fixtureA.GetBody().m_xf,this.m_fixtureB.GetShape(),this.m_fixtureB.GetBody().m_xf)};Box2D.Dynamics.Contacts.b2ContactConstraint=function(){this.localPlaneNormal=Box2D.Common.Math.b2Vec2.Get(0,0);this.localPoint=Box2D.Common.Math.b2Vec2.Get(0,0);this.normal=Box2D.Common.Math.b2Vec2.Get(0,
0);this.normalMass=new Box2D.Common.Math.b2Mat22;this.K=new Box2D.Common.Math.b2Mat22;this.points=[];for(var a=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++)this.points[a]=new Box2D.Dynamics.Contacts.b2ContactConstraintPoint};Box2D.Dynamics.Contacts.b2ContactConstraintPoint=function(){this.localPoint=Box2D.Common.Math.b2Vec2.Get(0,0);this.rA=Box2D.Common.Math.b2Vec2.Get(0,0);this.rB=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Dynamics.Contacts.b2ContactConstraintPoint.prototype.Reset=function(){this.localPoint.Set(0,
0);this.rA.Set(0,0);this.rB.Set(0,0)};Box2D.Dynamics.Contacts.b2ContactFactory=function(){this.m_registers={};this.m_freeContacts={};this.AddType(Box2D.Dynamics.Contacts.b2CircleContact,Box2D.Collision.Shapes.b2CircleShape.NAME,Box2D.Collision.Shapes.b2CircleShape.NAME);this.AddType(Box2D.Dynamics.Contacts.b2PolyAndCircleContact,Box2D.Collision.Shapes.b2PolygonShape.NAME,Box2D.Collision.Shapes.b2CircleShape.NAME);this.AddType(Box2D.Dynamics.Contacts.b2PolygonContact,Box2D.Collision.Shapes.b2PolygonShape.NAME,
Box2D.Collision.Shapes.b2PolygonShape.NAME);this.AddType(Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,Box2D.Collision.Shapes.b2EdgeShape.NAME,Box2D.Collision.Shapes.b2CircleShape.NAME);this.AddType(Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,Box2D.Collision.Shapes.b2PolygonShape.NAME,Box2D.Collision.Shapes.b2EdgeShape.NAME)};Box2D.Dynamics.Contacts.b2ContactFactory.prototype.AddType=function(a,b,c){this.m_freeContacts[b]=this.m_freeContacts[b]||{};this.m_freeContacts[b][c]=this.m_freeContacts[b][c]||
[];this.m_registers[b]=this.m_registers[b]||{};this.m_registers[b][c]=new Box2D.Dynamics.Contacts.b2ContactRegister;this.m_registers[b][c].ctor=a;this.m_registers[b][c].primary=!0;b!=c&&(this.m_registers[c]=this.m_registers[c]||{},this.m_registers[c][b]=new Box2D.Dynamics.Contacts.b2ContactRegister,this.m_registers[c][b].ctor=a,this.m_registers[c][b].primary=!1)};Box2D.Dynamics.Contacts.b2ContactFactory.prototype.Create=function(a,b){var c=a.GetShape().GetTypeName(),d=b.GetShape().GetTypeName(),e=
this.m_registers[c][d],g=e.ctor;return null!=g?e.primary?0<this.m_freeContacts[c][d].length?(c=this.m_freeContacts[c][d].pop(),c.Reset(a,b),c):new g(a,b):0<this.m_freeContacts[d][c].length?(c=this.m_freeContacts[d][c].pop(),c.Reset(b,a),c):new g(b,a):null};Box2D.Dynamics.Contacts.b2ContactFactory.prototype.Destroy=function(a){var b=a.m_fixtureA.GetShape().GetTypeName(),c=a.m_fixtureB.GetShape().GetTypeName();this.m_freeContacts[b][c].push(a)};Box2D.Dynamics.Contacts.b2ContactList=function(){this.contactFirstNodes=
[];for(var a=0;a<=Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts;a++)this.contactFirstNodes[a]=null;this.contactLastNodes=[];for(a=0;a<=Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts;a++)this.contactLastNodes[a]=null;this.contactNodeLookup={};this.contactCount=0};Box2D.Dynamics.Contacts.b2ContactList.prototype.GetFirstNode=function(a){return this.contactFirstNodes[a]};Box2D.Dynamics.Contacts.b2ContactList.prototype.AddContact=function(a){var b=a.ID;if(null==this.contactNodeLookup[b]){this.contactNodeLookup[b]=
[];for(var c=0;c<=Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts;c++)this.contactNodeLookup[b][c]=null;this.CreateNode(a,b,Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts);this.contactCount++}};Box2D.Dynamics.Contacts.b2ContactList.prototype.UpdateContact=function(a,b,c){b?this.CreateNode(a,a.ID,Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledTouchingContacts):this.RemoveNode(a.ID,Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledTouchingContacts);c?this.CreateNode(a,
a.ID,Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledContinuousContacts):this.RemoveNode(a.ID,Box2D.Dynamics.Contacts.b2ContactList.TYPES.nonSensorEnabledContinuousContacts)};Box2D.Dynamics.Contacts.b2ContactList.prototype.RemoveContact=function(a){a=a.ID;if(null!=this.contactNodeLookup[a]){for(var b=0;b<=Box2D.Dynamics.Contacts.b2ContactList.TYPES.allContacts;b++)this.RemoveNode(a,b);delete this.contactNodeLookup[a];this.contactCount--}};Box2D.Dynamics.Contacts.b2ContactList.prototype.RemoveNode=
function(a,b){var c=this.contactNodeLookup[a];if(null!=c){var d=c[b];if(null!=d){c[b]=null;var c=d.GetPreviousNode(),e=d.GetNextNode();null==c?this.contactFirstNodes[b]=e:c.SetNextNode(e);null==e?this.contactLastNodes[b]=c:e.SetPreviousNode(c);Box2D.Dynamics.Contacts.b2ContactListNode.FreeNode(d)}}};Box2D.Dynamics.Contacts.b2ContactList.prototype.CreateNode=function(a,b,c){b=this.contactNodeLookup[b];null==b[c]&&(b[c]=Box2D.Dynamics.Contacts.b2ContactListNode.GetNode(a),a=this.contactLastNodes[c],
null!=a?(a.SetNextNode(b[c]),b[c].SetPreviousNode(a)):this.contactFirstNodes[c]=b[c],this.contactLastNodes[c]=b[c])};Box2D.Dynamics.Contacts.b2ContactList.prototype.GetContactCount=function(){return this.contactCount};Box2D.Dynamics.Contacts.b2ContactList.TYPES={nonSensorEnabledTouchingContacts:0,nonSensorEnabledContinuousContacts:1,allContacts:2};Box2D.Dynamics.Contacts.b2ContactListNode=function(a){this.contact=a;this.previous=this.next=null};Box2D.Dynamics.Contacts.b2ContactListNode.freeNodes=
[];Box2D.Dynamics.Contacts.b2ContactListNode.GetNode=function(a){if(0<Box2D.Dynamics.Contacts.b2ContactListNode.freeNodes.length){var b=Box2D.Dynamics.Contacts.b2ContactListNode.freeNodes.pop();b.next=null;b.previous=null;b.contact=a;return b}return new Box2D.Dynamics.Contacts.b2ContactListNode(a)};Box2D.Dynamics.Contacts.b2ContactListNode.FreeNode=function(a){Box2D.Dynamics.Contacts.b2ContactListNode.freeNodes.push(a)};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.SetNextNode=function(a){this.next=
a};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.SetPreviousNode=function(a){this.previous=a};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.GetContact=function(){return this.contact};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.GetNextNode=function(){return this.next};Box2D.Dynamics.Contacts.b2ContactListNode.prototype.GetPreviousNode=function(){return this.previous};Box2D.Dynamics.Contacts.b2ContactRegister=function(){this.pool=null;this.poolCount=0};Box2D.Dynamics.Contacts.b2PositionSolverManifold=
function(){this.m_normal=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_separations=[];this.m_points=[];for(var a=0;a<Box2D.Common.b2Settings.b2_maxManifoldPoints;a++)this.m_points[a]=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Dynamics.Contacts.b2PositionSolverManifold.prototype.Initialize=function(a){switch(a.type){case Box2D.Collision.b2Manifold.e_circles:this._InitializeCircles(a);break;case Box2D.Collision.b2Manifold.e_faceA:this._InitializeFaceA(a);break;case Box2D.Collision.b2Manifold.e_faceB:this._InitializeFaceB(a)}};
Box2D.Dynamics.Contacts.b2PositionSolverManifold.prototype._InitializeCircles=function(a){var b=a.bodyA.m_xf.R,c=a.localPoint,d=a.bodyA.m_xf.position.x+(b.col1.x*c.x+b.col2.x*c.y),e=a.bodyA.m_xf.position.y+(b.col1.y*c.x+b.col2.y*c.y),b=a.bodyB.m_xf.R,c=a.points[0].localPoint,g=a.bodyB.m_xf.position.x+(b.col1.x*c.x+b.col2.x*c.y),b=a.bodyB.m_xf.position.y+(b.col1.y*c.x+b.col2.y*c.y),c=g-d,f=b-e,l=c*c+f*f;l>Box2D.Common.b2Settings.MIN_VALUE_SQUARED?(l=Math.sqrt(l),this.m_normal.x=c/l,this.m_normal.y=
f/l):(this.m_normal.x=1,this.m_normal.y=0);this.m_points[0].x=0.5*(d+g);this.m_points[0].y=0.5*(e+b);this.m_separations[0]=c*this.m_normal.x+f*this.m_normal.y-a.radius};Box2D.Dynamics.Contacts.b2PositionSolverManifold.prototype._InitializeFaceA=function(a){this.m_normal.x=a.bodyA.m_xf.R.col1.x*a.localPlaneNormal.x+a.bodyA.m_xf.R.col2.x*a.localPlaneNormal.y;this.m_normal.y=a.bodyA.m_xf.R.col1.y*a.localPlaneNormal.x+a.bodyA.m_xf.R.col2.y*a.localPlaneNormal.y;for(var b=a.bodyA.m_xf.position.x+(a.bodyA.m_xf.R.col1.x*
a.localPoint.x+a.bodyA.m_xf.R.col2.x*a.localPoint.y),c=a.bodyA.m_xf.position.y+(a.bodyA.m_xf.R.col1.y*a.localPoint.x+a.bodyA.m_xf.R.col2.y*a.localPoint.y),d=0;d<a.pointCount;d++){var e=a.bodyB.m_xf.position.x+(a.bodyB.m_xf.R.col1.x*a.points[d].localPoint.x+a.bodyB.m_xf.R.col2.x*a.points[d].localPoint.y),g=a.bodyB.m_xf.position.y+(a.bodyB.m_xf.R.col1.y*a.points[d].localPoint.x+a.bodyB.m_xf.R.col2.y*a.points[d].localPoint.y);this.m_separations[d]=(e-b)*this.m_normal.x+(g-c)*this.m_normal.y-a.radius;
this.m_points[d].x=e;this.m_points[d].y=g}};Box2D.Dynamics.Contacts.b2PositionSolverManifold.prototype._InitializeFaceB=function(a){this.m_normal.x=a.bodyB.m_xf.R.col1.x*a.localPlaneNormal.x+a.bodyB.m_xf.R.col2.x*a.localPlaneNormal.y;this.m_normal.y=a.bodyB.m_xf.R.col1.y*a.localPlaneNormal.x+a.bodyB.m_xf.R.col2.y*a.localPlaneNormal.y;for(var b=a.bodyB.m_xf.position.x+(a.bodyB.m_xf.R.col1.x*a.localPoint.x+a.bodyB.m_xf.R.col2.x*a.localPoint.y),c=a.bodyB.m_xf.position.y+(a.bodyB.m_xf.R.col1.y*a.localPoint.x+
a.bodyB.m_xf.R.col2.y*a.localPoint.y),d=0;d<a.pointCount;d++){var e=a.bodyA.m_xf.position.x+(a.bodyA.m_xf.R.col1.x*a.points[d].localPoint.x+a.bodyA.m_xf.R.col2.x*a.points[d].localPoint.y),g=a.bodyA.m_xf.position.y+(a.bodyA.m_xf.R.col1.y*a.points[d].localPoint.x+a.bodyA.m_xf.R.col2.y*a.points[d].localPoint.y);this.m_separations[d]=(e-b)*this.m_normal.x+(g-c)*this.m_normal.y-a.radius;this.m_points[d].Set(e,g)}this.m_normal.x*=-1;this.m_normal.y*=-1};Box2D.Dynamics.Contacts.b2ContactSolver=function(){this.m_constraints=
[]};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.Initialize=function(a,b,c){for(this.m_constraintCount=c;this.m_constraints.length<this.m_constraintCount;)this.m_constraints[this.m_constraints.length]=new Box2D.Dynamics.Contacts.b2ContactConstraint;for(a=0;a<c;a++){var d=b[a],e=d.m_fixtureA,g=d.m_fixtureB,f=e.m_shape.m_radius,l=g.m_shape.m_radius,k=e.GetBody(),h=g.GetBody(),m=d.GetManifold(),n=Box2D.Common.b2Settings.b2MixFriction(e.GetFriction(),g.GetFriction()),q=Box2D.Common.b2Settings.b2MixRestitution(e.GetRestitution(),
g.GetRestitution()),p=k.m_linearVelocity.x,r=k.m_linearVelocity.y,s=h.m_linearVelocity.x,t=h.m_linearVelocity.y,v=k.m_angularVelocity,w=h.m_angularVelocity;Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.Initialize(m,k.m_xf,f,h.m_xf,l);g=Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.m_normal.x;d=Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.m_normal.y;e=this.m_constraints[a];e.bodyA=k;e.bodyB=h;e.manifold=m;e.normal.x=g;e.normal.y=d;e.pointCount=m.m_pointCount;e.friction=
n;e.restitution=q;e.localPlaneNormal.x=m.m_localPlaneNormal.x;e.localPlaneNormal.y=m.m_localPlaneNormal.y;e.localPoint.x=m.m_localPoint.x;e.localPoint.y=m.m_localPoint.y;e.radius=f+l;e.type=m.m_type;for(f=0;f<e.pointCount;++f){n=m.m_points[f];l=e.points[f];l.normalImpulse=n.m_normalImpulse;l.tangentImpulse=n.m_tangentImpulse;l.localPoint.SetV(n.m_localPoint);var n=l.rA.x=Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.m_points[f].x-k.m_sweep.c.x,q=l.rA.y=Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.m_points[f].y-
k.m_sweep.c.y,y=l.rB.x=Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.m_points[f].x-h.m_sweep.c.x,C=l.rB.y=Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold.m_points[f].y-h.m_sweep.c.y,z=n*d-q*g,x=y*d-C*g,z=z*z,x=x*x;l.normalMass=1/(k.m_invMass+h.m_invMass+k.m_invI*z+h.m_invI*x);var A=k.m_mass*k.m_invMass+h.m_mass*h.m_invMass,A=A+(k.m_mass*k.m_invI*z+h.m_mass*h.m_invI*x);l.equalizedMass=1/A;x=d;A=-g;z=n*A-q*x;x=y*A-C*x;z*=z;x*=x;l.tangentMass=1/(k.m_invMass+h.m_invMass+k.m_invI*z+h.m_invI*
x);l.velocityBias=0;n=e.normal.x*(s+-w*C-p- -v*q)+e.normal.y*(t+w*y-r-v*n);n<-Box2D.Common.b2Settings.b2_velocityThreshold&&(l.velocityBias+=-e.restitution*n)}2==e.pointCount&&(t=e.points[0],s=e.points[1],m=k.m_invMass,k=k.m_invI,p=h.m_invMass,h=h.m_invI,r=t.rA.x*d-t.rA.y*g,t=t.rB.x*d-t.rB.y*g,v=s.rA.x*d-s.rA.y*g,s=s.rB.x*d-s.rB.y*g,g=m+p+k*r*r+h*t*t,d=m+p+k*v*v+h*s*s,h=m+p+k*r*v+h*t*s,g*g<100*(g*d-h*h)?(e.K.col1.Set(g,h),e.K.col2.Set(h,d),e.K.GetInverse(e.normalMass)):e.pointCount=1)}};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.InitVelocityConstraints=
function(a){for(var b=0;b<this.m_constraintCount;++b){var c=this.m_constraints[b],d=c.bodyA,e=c.bodyB,g=d.m_invMass,f=d.m_invI,l=e.m_invMass,k=e.m_invI,h=c.normal.x,m=c.normal.y,n=m,q=-h,p=0,r=0;if(a.warmStarting){r=c.pointCount;for(p=0;p<r;++p){var s=c.points[p];s.normalImpulse*=a.dtRatio;s.tangentImpulse*=a.dtRatio;var t=s.normalImpulse*h+s.tangentImpulse*n,v=s.normalImpulse*m+s.tangentImpulse*q;d.m_angularVelocity-=f*(s.rA.x*v-s.rA.y*t);d.m_linearVelocity.x-=g*t;d.m_linearVelocity.y-=g*v;e.m_angularVelocity+=
k*(s.rB.x*v-s.rB.y*t);e.m_linearVelocity.x+=l*t;e.m_linearVelocity.y+=l*v}}else{r=c.pointCount;for(p=0;p<r;++p)d=c.points[p],d.normalImpulse=0,d.tangentImpulse=0}}};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints=function(){for(var a=0;a<this.m_constraintCount;a++)this.SolveVelocityConstraints_Constraint(this.m_constraints[a])};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints_Constraint=function(a){for(var b=a.normal.x,c=a.normal.y,d=0;d<a.pointCount;d++)Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints_ConstraintPoint(a,
a.points[d]);if(1==a.pointCount){var d=a.points[0],e=d.normalImpulse-d.normalMass*((a.bodyB.m_linearVelocity.x-a.bodyB.m_angularVelocity*d.rB.y-a.bodyA.m_linearVelocity.x+a.bodyA.m_angularVelocity*d.rA.y)*b+(a.bodyB.m_linearVelocity.y+a.bodyB.m_angularVelocity*d.rB.x-a.bodyA.m_linearVelocity.y-a.bodyA.m_angularVelocity*d.rA.x)*c-d.velocityBias),e=0<e?e:0,g=e-d.normalImpulse,f=g*b,c=g*c;a.bodyA.m_linearVelocity.x-=a.bodyA.m_invMass*f;a.bodyA.m_linearVelocity.y-=a.bodyA.m_invMass*c;a.bodyA.m_angularVelocity-=
a.bodyA.m_invI*(d.rA.x*c-d.rA.y*f);a.bodyB.m_linearVelocity.x+=a.bodyB.m_invMass*f;a.bodyB.m_linearVelocity.y+=a.bodyB.m_invMass*c;a.bodyB.m_angularVelocity+=a.bodyB.m_invI*(d.rB.x*c-d.rB.y*f);d.normalImpulse=e}else for(var d=a.points[0],e=a.points[1],g=d.normalImpulse,f=e.normalImpulse,l=(a.bodyB.m_linearVelocity.x-a.bodyB.m_angularVelocity*d.rB.y-a.bodyA.m_linearVelocity.x+a.bodyA.m_angularVelocity*d.rA.y)*b+(a.bodyB.m_linearVelocity.y+a.bodyB.m_angularVelocity*d.rB.x-a.bodyA.m_linearVelocity.y-
a.bodyA.m_angularVelocity*d.rA.x)*c-d.velocityBias,c=(a.bodyB.m_linearVelocity.x-a.bodyB.m_angularVelocity*e.rB.y-a.bodyA.m_linearVelocity.x+a.bodyA.m_angularVelocity*e.rA.y)*b+(a.bodyB.m_linearVelocity.y+a.bodyB.m_angularVelocity*e.rB.x-a.bodyA.m_linearVelocity.y-a.bodyA.m_angularVelocity*e.rA.x)*c-e.velocityBias,l=l-(a.K.col1.x*g+a.K.col2.x*f),c=c-(a.K.col1.y*g+a.K.col2.y*f);;){b=-(a.normalMass.col1.x*l+a.normalMass.col2.x*c);if(0<=b){var k=-(a.normalMass.col1.y*l+a.normalMass.col2.y*c);if(0<=k){this.SolveVelocityConstraints_ConstraintPointUpdate(a,
d,e,b-g,k-f);d.normalImpulse=b;e.normalImpulse=k;break}}b=-d.normalMass*l;if(0<=b&&0<=a.K.col1.y*b+c){this.SolveVelocityConstraints_ConstraintPointUpdate(a,d,e,b-g,-f);d.normalImpulse=b;e.normalImpulse=0;break}b=-e.normalMass*c;if(0<=b&&0<=a.K.col2.x*b+l){this.SolveVelocityConstraints_ConstraintPointUpdate(a,d,e,-g,b-f);d.normalImpulse=0;e.normalImpulse=b;break}if(0<=l&&0<=c){this.SolveVelocityConstraints_ConstraintPointUpdate(a,d,e,-g,-f);d.normalImpulse=0;e.normalImpulse=0;break}break}};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints_ConstraintPoint=
function(a,b){var c=a.normal.y,d=-a.normal.x,e=a.friction*b.normalImpulse,e=Box2D.Common.Math.b2Math.Clamp(b.tangentImpulse-b.tangentMass*((a.bodyB.m_linearVelocity.x-a.bodyB.m_angularVelocity*b.rB.y-a.bodyA.m_linearVelocity.x+a.bodyA.m_angularVelocity*b.rA.y)*c+(a.bodyB.m_linearVelocity.y+a.bodyB.m_angularVelocity*b.rB.x-a.bodyA.m_linearVelocity.y-a.bodyA.m_angularVelocity*b.rA.x)*d),-e,e),g=e-b.tangentImpulse,c=g*c,d=g*d;a.bodyA.m_linearVelocity.x-=a.bodyA.m_invMass*c;a.bodyA.m_linearVelocity.y-=
a.bodyA.m_invMass*d;a.bodyA.m_angularVelocity-=a.bodyA.m_invI*(b.rA.x*d-b.rA.y*c);a.bodyB.m_linearVelocity.x+=a.bodyB.m_invMass*c;a.bodyB.m_linearVelocity.y+=a.bodyB.m_invMass*d;a.bodyB.m_angularVelocity+=a.bodyB.m_invI*(b.rB.x*d-b.rB.y*c);b.tangentImpulse=e};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolveVelocityConstraints_ConstraintPointUpdate=function(a,b,c,d,e){var g=d*a.normal.x;d*=a.normal.y;var f=e*a.normal.x;e*=a.normal.y;a.bodyA.m_linearVelocity.x-=a.bodyA.m_invMass*(g+f);a.bodyA.m_linearVelocity.y-=
a.bodyA.m_invMass*(d+e);a.bodyA.m_angularVelocity-=a.bodyA.m_invI*(b.rA.x*d-b.rA.y*g+c.rA.x*e-c.rA.y*f);a.bodyB.m_linearVelocity.x+=a.bodyB.m_invMass*(g+f);a.bodyB.m_linearVelocity.y+=a.bodyB.m_invMass*(d+e);a.bodyB.m_angularVelocity+=a.bodyB.m_invI*(b.rB.x*d-b.rB.y*g+c.rB.x*e-c.rB.y*f);b.normalImpulse=0;c.normalImpulse=0};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.FinalizeVelocityConstraints=function(){for(var a=0;a<this.m_constraintCount;++a)for(var b=this.m_constraints[a],c=b.manifold,d=
0;d<b.pointCount;++d){var e=c.m_points[d],g=b.points[d];e.m_normalImpulse=g.normalImpulse;e.m_tangentImpulse=g.tangentImpulse}};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolvePositionConstraints=function(a){void 0===a&&(a=0);for(var b=0,c=0;c<this.m_constraintCount;c++){var d=this.m_constraints[c],e=d.bodyA,g=d.bodyB,f=e.m_mass*e.m_invMass,l=e.m_mass*e.m_invI,k=g.m_mass*g.m_invMass,h=g.m_mass*g.m_invI;Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.Initialize(d);for(var m=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_normal,
n=0;n<d.pointCount;n++){var q=d.points[n],p=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_points[n],r=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_separations[n],s=p.x-e.m_sweep.c.x,t=p.y-e.m_sweep.c.y,v=p.x-g.m_sweep.c.x,p=p.y-g.m_sweep.c.y,b=b<r?b:r,r=Box2D.Common.Math.b2Math.Clamp(a*(r+Box2D.Common.b2Settings.b2_linearSlop),-Box2D.Common.b2Settings.b2_maxLinearCorrection,0),r=-q.equalizedMass*r,q=r*m.x,r=r*m.y;e.m_sweep.c.x-=f*q;e.m_sweep.c.y-=f*r;e.m_sweep.a-=l*(s*r-t*q);e.SynchronizeTransform();
g.m_sweep.c.x+=k*q;g.m_sweep.c.y+=k*r;g.m_sweep.a+=h*(v*r-p*q);g.SynchronizeTransform()}}return b>-1.5*Box2D.Common.b2Settings.b2_linearSlop};Box2D.Dynamics.Contacts.b2ContactSolver.prototype.SolvePositionConstraints_NEW=function(a){void 0===a&&(a=0);for(var b=0,c=0;c<this.m_constraintCount;c++){var d=this.m_constraints[c],e=d.bodyA,g=d.bodyB,f=e.m_mass*e.m_invMass,l=e.m_mass*e.m_invI,k=g.m_mass*g.m_invMass,h=g.m_mass*g.m_invI;Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.Initialize(d);for(var m=
Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_normal,n=0;n<d.pointCount;n++){var q=d.points[n],p=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_points[n],r=Box2D.Dynamics.Contacts.b2ContactSolver.s_psm.m_separations[n],s=p.x-e.m_sweep.c.x,t=p.y-e.m_sweep.c.y,v=p.x-g.m_sweep.c.x,p=p.y-g.m_sweep.c.y;r<b&&(b=r);0!=a&&Box2D.Common.Math.b2Math.Clamp(a*(r+Box2D.Common.b2Settings.b2_linearSlop),-Box2D.Common.b2Settings.b2_maxLinearCorrection,0);r=0*-q.equalizedMass;q=r*m.x;r*=m.y;e.m_sweep.c.x-=f*q;e.m_sweep.c.y-=
f*r;e.m_sweep.a-=l*(s*r-t*q);e.SynchronizeTransform();g.m_sweep.c.x+=k*q;g.m_sweep.c.y+=k*r;g.m_sweep.a+=h*(v*r-p*q);g.SynchronizeTransform()}}return b>-1.5*Box2D.Common.b2Settings.b2_linearSlop};Box2D.Dynamics.Contacts.b2EdgeAndCircleContact=function(a,b){Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};c2inherit(Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,Box2D.Dynamics.Contacts.b2Contact);Box2D.Dynamics.Contacts.b2EdgeAndCircleContact.prototype.Reset=function(a,b){Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,
a,b)};Box2D.Dynamics.Contacts.b2EdgeAndCircleContact.prototype.Evaluate=function(){this.m_fixtureA.GetBody();this.m_fixtureB.GetBody();this.b2CollideEdgeAndCircle(this.m_manifold,this.m_fixtureA.GetShape(),this.m_fixtureA.GetBody().m_xf,this.m_fixtureB.GetShape(),this.m_fixtureB.GetBody().m_xf)};Box2D.Dynamics.Contacts.b2EdgeAndCircleContact.prototype.b2CollideEdgeAndCircle=function(a,b,c,d,e){};Box2D.Dynamics.Contacts.b2PolyAndCircleContact=function(a,b){Box2D.Dynamics.Contacts.b2Contact.call(this,
a,b)};c2inherit(Box2D.Dynamics.Contacts.b2PolyAndCircleContact,Box2D.Dynamics.Contacts.b2Contact);Box2D.Dynamics.Contacts.b2PolyAndCircleContact.prototype.Reset=function(a,b){Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};Box2D.Dynamics.Contacts.b2PolyAndCircleContact.prototype.Evaluate=function(){Box2D.Collision.b2Collision.CollidePolygonAndCircle(this.m_manifold,this.m_fixtureA.GetShape(),this.m_fixtureA.GetBody().m_xf,this.m_fixtureB.GetShape(),this.m_fixtureB.GetBody().m_xf)};
Box2D.Dynamics.Contacts.b2PolyAndEdgeContact=function(a,b){Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};c2inherit(Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,Box2D.Dynamics.Contacts.b2Contact);Box2D.Dynamics.Contacts.b2PolyAndEdgeContact.prototype.Reset=function(a,b){Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};Box2D.Dynamics.Contacts.b2PolyAndEdgeContact.prototype.Evaluate=function(){this.b2CollidePolyAndEdge(this.m_manifold,this.m_fixtureA.GetShape(),this.m_fixtureA.GetBody().m_xf,
this.m_fixtureB.GetShape(),this.m_fixtureB.GetBody().m_xf)};Box2D.Dynamics.Contacts.b2PolyAndEdgeContact.prototype.b2CollidePolyAndEdge=function(a,b,c,d,e){};Box2D.Dynamics.Contacts.b2PolygonContact=function(a,b){Box2D.Dynamics.Contacts.b2Contact.call(this,a,b)};c2inherit(Box2D.Dynamics.Contacts.b2PolygonContact,Box2D.Dynamics.Contacts.b2Contact);Box2D.Dynamics.Contacts.b2PolygonContact.prototype.Reset=function(a,b){Box2D.Dynamics.Contacts.b2Contact.prototype.Reset.call(this,a,b)};Box2D.Dynamics.Contacts.b2PolygonContact.prototype.Evaluate=
function(){Box2D.Collision.b2Collision.CollidePolygons(this.m_manifold,this.m_fixtureA.GetShape(),this.m_fixtureA.GetBody().m_xf,this.m_fixtureB.GetShape(),this.m_fixtureB.GetBody().m_xf)};Box2D.Dynamics.Controllers.b2Controller=function(){this.ID="Controller"+Box2D.Dynamics.Controllers.b2Controller.NEXT_ID++;this.m_world=null;this.bodyList=new Box2D.Dynamics.b2BodyList};Box2D.Dynamics.Controllers.b2Controller.prototype.Step=function(a){};Box2D.Dynamics.Controllers.b2Controller.prototype.AddBody=
function(a){this.bodyList.AddBody(a);a.AddController(this)};Box2D.Dynamics.Controllers.b2Controller.prototype.RemoveBody=function(a){this.bodyList.RemoveBody(a);a.RemoveController(this)};Box2D.Dynamics.Controllers.b2Controller.prototype.Clear=function(){for(var a=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);a;a=a.GetNextNode())this.RemoveBody(a.body)};Box2D.Dynamics.Controllers.b2Controller.prototype.GetBodyList=function(){return this.bodyList};Box2D.Dynamics.Controllers.b2Controller.NEXT_ID=
0;Box2D.Dynamics.Controllers.b2BuoyancyController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.normal=Box2D.Common.Math.b2Vec2.Get(0,-1);this.density=this.offset=0;this.velocity=Box2D.Common.Math.b2Vec2.Get(0,0);this.linearDrag=2;this.angularDrag=1;this.useDensity=!1;this.useWorldGravity=!0;this.gravity=null};c2inherit(Box2D.Dynamics.Controllers.b2BuoyancyController,Box2D.Dynamics.Controllers.b2Controller);Box2D.Dynamics.Controllers.b2BuoyancyController.prototype.Step=function(a){this.useWorldGravity&&
(this.gravity=this.m_world.GetGravity().Copy());for(a=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);a;a=a.GetNextNode()){for(var b=a.body,c=Box2D.Common.Math.b2Vec2.Get(0,0),d=Box2D.Common.Math.b2Vec2.Get(0,0),e=0,g=0,f=b.GetFixtureList().GetFirstNode();f;f=f.GetNextNode()){var l=Box2D.Common.Math.b2Vec2.Get(0,0),k=f.fixture.GetShape().ComputeSubmergedArea(this.normal,this.offset,b.GetTransform(),l),e=e+k;c.x+=k*l.x;c.y+=k*l.y;var h=0,h=1,g=g+k*h;d.x+=k*l.x*h;d.y+=k*l.y*
h}e<Number.MIN_VALUE||(c.x/=e,c.y/=e,d.x/=g,d.y/=g,g=this.gravity.GetNegative(),g.Multiply(this.density*e),b.ApplyForce(g,d),g=b.GetLinearVelocityFromWorldPoint(c),g.Subtract(this.velocity),g.Multiply(-this.linearDrag*e),b.ApplyForce(g,c),b.ApplyTorque(-b.GetInertia()/b.GetMass()*e*b.GetAngularVelocity()*this.angularDrag),Box2D.Common.Math.b2Vec2.Free(c),Box2D.Common.Math.b2Vec2.Free(d))}};Box2D.Dynamics.Controllers.b2ConstantAccelController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);
this.A=Box2D.Common.Math.b2Vec2.Get(0,0)};c2inherit(Box2D.Dynamics.Controllers.b2ConstantAccelController,Box2D.Dynamics.Controllers.b2Controller);Box2D.Dynamics.Controllers.b2ConstantAccelController.prototype.Step=function(a){a=Box2D.Common.Math.b2Vec2.Get(this.A.x*a.dt,this.A.y*a.dt);for(var b=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);b;b=b.GetNextNode()){var c=b.body,d=c.GetLinearVelocity();c.SetLinearVelocity(Box2D.Common.Math.b2Vec2.Get(d.x+a.x,d.y+a.y))}Box2D.Common.Math.b2Vec2.Free(a)};
Box2D.Dynamics.Controllers.b2ConstantForceController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.F=Box2D.Common.Math.b2Vec2.Get(0,0)};c2inherit(Box2D.Dynamics.Controllers.b2ConstantForceController,Box2D.Dynamics.Controllers.b2Controller);Box2D.Dynamics.Controllers.b2ConstantForceController.prototype.Step=function(a){for(a=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);a;a=a.GetNextNode()){var b=a.body;b.ApplyForce(this.F,b.GetWorldCenter())}};Box2D.Dynamics.Controllers.b2ControllerList=
function(){this.controllerLastNode=this.controllerFirstNode=null;this.controllerNodeLookup={};this.controllerCount=0};Box2D.Dynamics.Controllers.b2ControllerList.prototype.GetFirstNode=function(){return this.controllerFirstNode};Box2D.Dynamics.Controllers.b2ControllerList.prototype.AddController=function(a){var b=a.ID;if(null==this.controllerNodeLookup[b]){a=new Box2D.Dynamics.Controllers.b2ControllerListNode(a);var c=this.controllerLastNode;null!=c?c.SetNextNode(a):this.controllerFirstNode=a;a.SetPreviousNode(c);
this.controllerLastNode=a;this.controllerNodeLookup[b]=a;this.controllerCount++}};Box2D.Dynamics.Controllers.b2ControllerList.prototype.RemoveController=function(a){a=a.ID;var b=this.controllerNodeLookup[a];if(null!=b){var c=b.GetPreviousNode(),b=b.GetNextNode();null==c?this.controllerFirstNode=b:c.SetNextNode(b);null==b?this.controllerLastNode=c:b.SetPreviousNode(c);delete this.controllerNodeLookup[a];this.controllerCount--}};Box2D.Dynamics.Controllers.b2ControllerList.prototype.GetControllerCount=
function(){return this.controllerCount};Box2D.Dynamics.Controllers.b2ControllerListNode=function(a){this.controller=a;this.previous=this.next=null};Box2D.Dynamics.Controllers.b2ControllerListNode.prototype.SetNextNode=function(a){this.next=a};Box2D.Dynamics.Controllers.b2ControllerListNode.prototype.SetPreviousNode=function(a){this.previous=a};Box2D.Dynamics.Controllers.b2ControllerListNode.prototype.GetNextNode=function(){return this.next};Box2D.Dynamics.Controllers.b2ControllerListNode.prototype.GetPreviousNode=
function(){return this.previous};Box2D.Dynamics.Controllers.b2GravityController=function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.G=1;this.invSqr=!0};c2inherit(Box2D.Dynamics.Controllers.b2GravityController,Box2D.Dynamics.Controllers.b2Controller);Box2D.Dynamics.Controllers.b2GravityController.prototype.Step=function(a){var b=a=null,c=0,d=null,e=null,g=0,f=0,l=0,g=null;if(this.invSqr)for(var k=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);k;k=k.GetNextNode()){a=
k.body;for(var b=a.GetWorldCenter(),c=a.GetMass(),h=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);h;h=h.GetNextNode())if(d=h.body,a.IsAwake()||d.IsAwake())e=d.GetWorldCenter(),g=e.x-b.x,f=e.y-b.y,l=g*g+f*f,l<Number.MIN_VALUE||(g=Box2D.Common.Math.b2Vec2.Get(g,f),g.Multiply(this.G/l/Math.sqrt(l)*c*d.GetMass()),a.IsAwake()&&a.ApplyForce(g,b),g.Multiply(-1),d.IsAwake()&&d.ApplyForce(g,e),Box2D.Common.Math.b2Vec2.Free(g))}else for(k=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);k;k=
k.GetNextNode()){a=bodyNode.body;b=a.GetWorldCenter();c=a.GetMass();for(h=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.allBodies);h;h=h.GetNextNode())if(d=bodyNode.body,a.IsAwake()||d.IsAwake())e=d.GetWorldCenter(),g=e.x-b.x,f=e.y-b.y,l=g*g+f*f,l<Number.MIN_VALUE||(g=Box2D.Common.Math.b2Vec2.Get(g,f),g.Multiply(this.G/l*c*d.GetMass()),a.IsAwake()&&a.ApplyForce(g,b),g.Multiply(-1),d.IsAwake()&&d.ApplyForce(g,e),Box2D.Common.Math.b2Vec2.Free(g))}};Box2D.Dynamics.Controllers.b2TensorDampingController=
function(){Box2D.Dynamics.Controllers.b2Controller.call(this);this.T=new Box2D.Common.Math.b2Mat22;this.maxTimestep=0};c2inherit(Box2D.Dynamics.Controllers.b2TensorDampingController,Box2D.Dynamics.Controllers.b2Controller);Box2D.Dynamics.Controllers.b2TensorDampingController.prototype.SetAxisAligned=function(a,b){this.T.col1.x=-a;this.T.col1.y=0;this.T.col2.x=0;this.T.col2.y=-b;this.maxTimestep=0<a||0<b?1/Math.max(a,b):0};Box2D.Dynamics.Controllers.b2TensorDampingController.prototype.Step=function(a){a=
a.dt;if(!(a<=Number.MIN_VALUE)){a>this.maxTimestep&&0<this.maxTimestep&&(a=this.maxTimestep);for(var b=this.bodyList.GetFirstNode(Box2D.Dynamics.b2BodyList.TYPES.awakeBodies);b;b=b.GetNextNode()){var c=b.body,d=c.GetWorldVector(Box2D.Common.Math.b2Math.MulMV(this.T,c.GetLocalVector(c.GetLinearVelocity())));c.SetLinearVelocity(Box2D.Common.Math.b2Vec2.Get(c.GetLinearVelocity().x+d.x*a,c.GetLinearVelocity().y+d.y*a))}}};Box2D.Dynamics.Joints.b2Joint=function(a){this.m_edgeA=new Box2D.Dynamics.Joints.b2JointEdge;
this.m_edgeB=new Box2D.Dynamics.Joints.b2JointEdge;this.m_localCenterA=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localCenterB=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_type=a.type;this.m_next=this.m_prev=null;this.m_bodyA=a.bodyA;this.m_bodyB=a.bodyB;this.m_collideConnected=a.collideConnected};Box2D.Dynamics.Joints.b2Joint.prototype.GetType=function(){return this.m_type};Box2D.Dynamics.Joints.b2Joint.prototype.GetAnchorA=function(){return null};Box2D.Dynamics.Joints.b2Joint.prototype.GetAnchorB=function(){return null};
Box2D.Dynamics.Joints.b2Joint.prototype.GetReactionForce=function(a){return null};Box2D.Dynamics.Joints.b2Joint.prototype.GetReactionTorque=function(a){return 0};Box2D.Dynamics.Joints.b2Joint.prototype.GetBodyA=function(){return this.m_bodyA};Box2D.Dynamics.Joints.b2Joint.prototype.GetBodyB=function(){return this.m_bodyB};Box2D.Dynamics.Joints.b2Joint.prototype.GetNext=function(){return this.m_next};Box2D.Dynamics.Joints.b2Joint.prototype.IsActive=function(){return this.m_bodyA.IsActive()&&this.m_bodyB.IsActive()};
Box2D.Dynamics.Joints.b2Joint.Create=function(a){return a.Create()};Box2D.Dynamics.Joints.b2Joint.prototype.InitVelocityConstraints=function(a){};Box2D.Dynamics.Joints.b2Joint.prototype.SolveVelocityConstraints=function(a){};Box2D.Dynamics.Joints.b2Joint.prototype.FinalizeVelocityConstraints=function(){};Box2D.Dynamics.Joints.b2Joint.prototype.SolvePositionConstraints=function(a){return!1};Box2D.Dynamics.Joints.b2Joint.e_unknownJoint=0;Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint=1;Box2D.Dynamics.Joints.b2Joint.e_prismaticJoint=
2;Box2D.Dynamics.Joints.b2Joint.e_distanceJoint=3;Box2D.Dynamics.Joints.b2Joint.e_pulleyJoint=4;Box2D.Dynamics.Joints.b2Joint.e_mouseJoint=5;Box2D.Dynamics.Joints.b2Joint.e_gearJoint=6;Box2D.Dynamics.Joints.b2Joint.e_lineJoint=7;Box2D.Dynamics.Joints.b2Joint.e_weldJoint=8;Box2D.Dynamics.Joints.b2Joint.e_frictionJoint=9;Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit=0;Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit=1;Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit=2;Box2D.Dynamics.Joints.b2Joint.e_equalLimits=
3;Box2D.Dynamics.Joints.b2JointDef=function(){this.type=Box2D.Dynamics.Joints.b2Joint.e_unknownJoint;this.bodyB=this.bodyA=null;this.collideConnected=!1};Box2D.Dynamics.Joints.b2JointEdge=function(){};Box2D.Dynamics.Joints.b2DistanceJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_u=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);
this.m_length=a.length;this.m_frequencyHz=a.frequencyHz;this.m_dampingRatio=a.dampingRatio;this.m_bias=this.m_gamma=this.m_impulse=0};c2inherit(Box2D.Dynamics.Joints.b2DistanceJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetReactionForce=
function(a){return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse*this.m_u.x,a*this.m_impulse*this.m_u.y)};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetReactionTorque=function(a){return 0};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetLength=function(){return this.m_length};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SetLength=function(a){this.m_length=a};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetFrequency=function(){return this.m_frequencyHz};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SetFrequency=
function(a){this.m_frequencyHz=a};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.GetDampingRatio=function(){return this.m_dampingRatio};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SetDampingRatio=function(a){this.m_dampingRatio=a};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.InitVelocityConstraints=function(a){var b,c=0,d=this.m_bodyA,e=this.m_bodyB;b=d.m_xf.R;var g=this.m_localAnchor1.x-d.m_sweep.localCenter.x,f=this.m_localAnchor1.y-d.m_sweep.localCenter.y,c=b.col1.x*g+b.col2.x*f,f=b.col1.y*
g+b.col2.y*f,g=c;b=e.m_xf.R;var l=this.m_localAnchor2.x-e.m_sweep.localCenter.x,k=this.m_localAnchor2.y-e.m_sweep.localCenter.y,c=b.col1.x*l+b.col2.x*k,k=b.col1.y*l+b.col2.y*k,l=c;this.m_u.x=e.m_sweep.c.x+l-d.m_sweep.c.x-g;this.m_u.y=e.m_sweep.c.y+k-d.m_sweep.c.y-f;c=Math.sqrt(this.m_u.x*this.m_u.x+this.m_u.y*this.m_u.y);c>Box2D.Common.b2Settings.b2_linearSlop?this.m_u.Multiply(1/c):this.m_u.SetZero();b=g*this.m_u.y-f*this.m_u.x;var h=l*this.m_u.y-k*this.m_u.x;b=d.m_invMass+d.m_invI*b*b+e.m_invMass+
e.m_invI*h*h;this.m_mass=0!=b?1/b:0;if(0<this.m_frequencyHz){var c=c-this.m_length,h=2*Math.PI*this.m_frequencyHz,m=this.m_mass*h*h;this.m_gamma=a.dt*(2*this.m_mass*this.m_dampingRatio*h+a.dt*m);this.m_gamma=0!=this.m_gamma?1/this.m_gamma:0;this.m_bias=c*a.dt*m*this.m_gamma;this.m_mass=b+this.m_gamma;this.m_mass=0!=this.m_mass?1/this.m_mass:0}a.warmStarting?(this.m_impulse*=a.dtRatio,a=this.m_impulse*this.m_u.x,b=this.m_impulse*this.m_u.y,d.m_linearVelocity.x-=d.m_invMass*a,d.m_linearVelocity.y-=
d.m_invMass*b,d.m_angularVelocity-=d.m_invI*(g*b-f*a),e.m_linearVelocity.x+=e.m_invMass*a,e.m_linearVelocity.y+=e.m_invMass*b,e.m_angularVelocity+=e.m_invI*(l*b-k*a)):this.m_impulse=0};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SolveVelocityConstraints=function(a){a=this.m_localAnchor1.x-this.m_bodyA.m_sweep.localCenter.x;var b=this.m_localAnchor1.y-this.m_bodyA.m_sweep.localCenter.y,c=this.m_bodyA.m_xf.R.col1.x*a+this.m_bodyA.m_xf.R.col2.x*b,b=this.m_bodyA.m_xf.R.col1.y*a+this.m_bodyA.m_xf.R.col2.y*
b;a=c;var d=this.m_localAnchor2.x-this.m_bodyB.m_sweep.localCenter.x,e=this.m_localAnchor2.y-this.m_bodyB.m_sweep.localCenter.y,c=this.m_bodyB.m_xf.R.col1.x*d+this.m_bodyB.m_xf.R.col2.x*e,e=this.m_bodyB.m_xf.R.col1.y*d+this.m_bodyB.m_xf.R.col2.y*e,d=c,g=-this.m_mass*(this.m_u.x*(this.m_bodyB.m_linearVelocity.x-this.m_bodyB.m_angularVelocity*e-(this.m_bodyA.m_linearVelocity.x-this.m_bodyA.m_angularVelocity*b))+this.m_u.y*(this.m_bodyB.m_linearVelocity.y+this.m_bodyB.m_angularVelocity*d-(this.m_bodyA.m_linearVelocity.y+
this.m_bodyA.m_angularVelocity*a))+this.m_bias+this.m_gamma*this.m_impulse);this.m_impulse+=g;c=g*this.m_u.x;g*=this.m_u.y;this.m_bodyA.m_linearVelocity.x-=this.m_bodyA.m_invMass*c;this.m_bodyA.m_linearVelocity.y-=this.m_bodyA.m_invMass*g;this.m_bodyA.m_angularVelocity-=this.m_bodyA.m_invI*(a*g-b*c);this.m_bodyB.m_linearVelocity.x+=this.m_bodyB.m_invMass*c;this.m_bodyB.m_linearVelocity.y+=this.m_bodyB.m_invMass*g;this.m_bodyB.m_angularVelocity+=this.m_bodyB.m_invI*(d*g-e*c)};Box2D.Dynamics.Joints.b2DistanceJoint.prototype.SolvePositionConstraints=
function(a){if(0<this.m_frequencyHz)return!0;a=this.m_localAnchor1.x-this.m_bodyA.m_sweep.localCenter.x;var b=this.m_localAnchor1.y-this.m_bodyA.m_sweep.localCenter.y,c=this.m_bodyA.m_xf.R.col1.x*a+this.m_bodyA.m_xf.R.col2.x*b,b=this.m_bodyA.m_xf.R.col1.y*a+this.m_bodyA.m_xf.R.col2.y*b;a=c;var d=this.m_localAnchor2.x-this.m_bodyB.m_sweep.localCenter.x,e=this.m_localAnchor2.y-this.m_bodyB.m_sweep.localCenter.y,c=this.m_bodyB.m_xf.R.col1.x*d+this.m_bodyB.m_xf.R.col2.x*e,e=this.m_bodyB.m_xf.R.col1.y*
d+this.m_bodyB.m_xf.R.col2.y*e,d=c,g=this.m_bodyB.m_sweep.c.x+d-this.m_bodyA.m_sweep.c.x-a,f=this.m_bodyB.m_sweep.c.y+e-this.m_bodyA.m_sweep.c.y-b,c=Math.sqrt(g*g+f*f),g=g/c,f=f/c,c=Box2D.Common.Math.b2Math.Clamp(c-this.m_length,-Box2D.Common.b2Settings.b2_maxLinearCorrection,Box2D.Common.b2Settings.b2_maxLinearCorrection),l=-this.m_mass*c;this.m_u.Set(g,f);g=l*this.m_u.x;f=l*this.m_u.y;this.m_bodyA.m_sweep.c.x-=this.m_bodyA.m_invMass*g;this.m_bodyA.m_sweep.c.y-=this.m_bodyA.m_invMass*f;this.m_bodyA.m_sweep.a-=
this.m_bodyA.m_invI*(a*f-b*g);this.m_bodyB.m_sweep.c.x+=this.m_bodyB.m_invMass*g;this.m_bodyB.m_sweep.c.y+=this.m_bodyB.m_invMass*f;this.m_bodyB.m_sweep.a+=this.m_bodyB.m_invI*(d*f-e*g);this.m_bodyA.SynchronizeTransform();this.m_bodyB.SynchronizeTransform();return Math.abs(c)<Box2D.Common.b2Settings.b2_linearSlop};Box2D.Dynamics.Joints.b2DistanceJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,
0);this.type=Box2D.Dynamics.Joints.b2Joint.e_distanceJoint;this.length=1;this.dampingRatio=this.frequencyHz=0};c2inherit(Box2D.Dynamics.Joints.b2DistanceJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2DistanceJointDef.prototype.Initialize=function(a,b,c,d){this.bodyA=a;this.bodyB=b;this.localAnchorA.SetV(this.bodyA.GetLocalPoint(c));this.localAnchorB.SetV(this.bodyB.GetLocalPoint(d));a=d.x-c.x;c=d.y-c.y;this.length=Math.sqrt(a*a+c*c);this.dampingRatio=this.frequencyHz=0};Box2D.Dynamics.Joints.b2DistanceJointDef.prototype.Create=
function(){return new Box2D.Dynamics.Joints.b2DistanceJoint(this)};Box2D.Dynamics.Joints.b2FrictionJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_linearMass=new Box2D.Common.Math.b2Mat22;this.m_linearImpulse=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchorA.SetV(a.localAnchorA);this.m_localAnchorB.SetV(a.localAnchorB);this.m_linearMass.SetZero();this.m_angularMass=0;
this.m_linearImpulse.SetZero();this.m_angularImpulse=0;this.m_maxForce=a.maxForce;this.m_maxTorque=a.maxTorque};c2inherit(Box2D.Dynamics.Joints.b2FrictionJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetReactionForce=
function(a){void 0===a&&(a=0);return new b2Vec2(a*this.m_linearImpulse.x,a*this.m_linearImpulse.y)};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetReactionTorque=function(a){void 0===a&&(a=0);return a*this.m_angularImpulse};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.SetMaxForce=function(a){void 0===a&&(a=0);this.m_maxForce=a};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetMaxForce=function(){return this.m_maxForce};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.SetMaxTorque=function(a){void 0===
a&&(a=0);this.m_maxTorque=a};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.GetMaxTorque=function(){return this.m_maxTorque};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.InitVelocityConstraints=function(a){var b,c=0,d=this.m_bodyA,e=this.m_bodyB;b=d.m_xf.R;var g=this.m_localAnchorA.x-d.m_sweep.localCenter.x,f=this.m_localAnchorA.y-d.m_sweep.localCenter.y,c=b.col1.x*g+b.col2.x*f,f=b.col1.y*g+b.col2.y*f,g=c;b=e.m_xf.R;var l=this.m_localAnchorB.x-e.m_sweep.localCenter.x,k=this.m_localAnchorB.y-e.m_sweep.localCenter.y,
c=b.col1.x*l+b.col2.x*k,k=b.col1.y*l+b.col2.y*k,l=c;b=d.m_invMass;var c=e.m_invMass,h=d.m_invI,m=e.m_invI,n=new Box2D.Common.Math.b2Mat22;n.col1.x=b+c;n.col2.x=0;n.col1.y=0;n.col2.y=b+c;n.col1.x+=h*f*f;n.col2.x+=-h*g*f;n.col1.y+=-h*g*f;n.col2.y+=h*g*g;n.col1.x+=m*k*k;n.col2.x+=-m*l*k;n.col1.y+=-m*l*k;n.col2.y+=m*l*l;n.GetInverse(this.m_linearMass);this.m_angularMass=h+m;0<this.m_angularMass&&(this.m_angularMass=1/this.m_angularMass);a.warmStarting?(this.m_linearImpulse.x*=a.dtRatio,this.m_linearImpulse.y*=
a.dtRatio,this.m_angularImpulse*=a.dtRatio,a=this.m_linearImpulse,d.m_linearVelocity.x-=b*a.x,d.m_linearVelocity.y-=b*a.y,d.m_angularVelocity-=h*(g*a.y-f*a.x+this.m_angularImpulse),e.m_linearVelocity.x+=c*a.x,e.m_linearVelocity.y+=c*a.y,e.m_angularVelocity+=m*(l*a.y-k*a.x+this.m_angularImpulse)):(this.m_linearImpulse.SetZero(),this.m_angularImpulse=0)};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.SolveVelocityConstraints=function(a){var b,c=0,d=this.m_bodyA,e=this.m_bodyB,g=d.m_linearVelocity,
f=d.m_angularVelocity,l=e.m_linearVelocity,k=e.m_angularVelocity,h=d.m_invMass,m=e.m_invMass,n=d.m_invI,q=e.m_invI;b=d.m_xf.R;var p=this.m_localAnchorA.x-d.m_sweep.localCenter.x,r=this.m_localAnchorA.y-d.m_sweep.localCenter.y,c=b.col1.x*p+b.col2.x*r,r=b.col1.y*p+b.col2.y*r,p=c;b=e.m_xf.R;var s=this.m_localAnchorB.x-e.m_sweep.localCenter.x,t=this.m_localAnchorB.y-e.m_sweep.localCenter.y,c=b.col1.x*s+b.col2.x*t,t=b.col1.y*s+b.col2.y*t,s=c;b=0;var c=-this.m_angularMass*(k-f),v=this.m_angularImpulse;
b=a.dt*this.m_maxTorque;this.m_angularImpulse=Box2D.Common.Math.b2Math.Clamp(this.m_angularImpulse+c,-b,b);c=this.m_angularImpulse-v;f-=n*c;k+=q*c;b=Box2D.Common.Math.b2Math.MulMV(this.m_linearMass,Box2D.Common.Math.b2Vec2.Get(-(l.x-k*t-g.x+f*r),-(l.y+k*s-g.y-f*p)));c=this.m_linearImpulse.Copy();this.m_linearImpulse.Add(b);b=a.dt*this.m_maxForce;this.m_linearImpulse.LengthSquared()>b*b&&(this.m_linearImpulse.Normalize(),this.m_linearImpulse.Multiply(b));b=Box2D.Common.Math.b2Math.SubtractVV(this.m_linearImpulse,
c);g.x-=h*b.x;g.y-=h*b.y;f-=n*(p*b.y-r*b.x);l.x+=m*b.x;l.y+=m*b.y;k+=q*(s*b.y-t*b.x);d.m_angularVelocity=f;e.m_angularVelocity=k};Box2D.Dynamics.Joints.b2FrictionJoint.prototype.SolvePositionConstraints=function(a){return!0};Box2D.Dynamics.Joints.b2FrictionJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_frictionJoint;this.maxTorque=this.maxForce=
0};c2inherit(Box2D.Dynamics.Joints.b2FrictionJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2FrictionJointDef.prototype.Initialize=function(a,b,c){this.bodyA=a;this.bodyB=b;this.localAnchorA.SetV(this.bodyA.GetLocalPoint(c));this.localAnchorB.SetV(this.bodyB.GetLocalPoint(c))};Box2D.Dynamics.Joints.b2FrictionJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2FrictionJoint(this)};Box2D.Dynamics.Joints.b2GearJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,
a);this.m_groundAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_groundAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_J=new Box2D.Dynamics.Joints.b2Jacobian;var b=a.joint1.m_type,c=a.joint2.m_type;this.m_prismatic2=this.m_revolute2=this.m_prismatic1=this.m_revolute1=null;var d=0,e=0;this.m_ground1=a.joint1.GetBodyA();this.m_bodyA=a.joint1.GetBodyB();b==Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint?
(this.m_revolute1=a.joint1,this.m_groundAnchor1.SetV(this.m_revolute1.m_localAnchor1),this.m_localAnchor1.SetV(this.m_revolute1.m_localAnchor2),d=this.m_revolute1.GetJointAngle()):(this.m_prismatic1=a.joint1,this.m_groundAnchor1.SetV(this.m_prismatic1.m_localAnchor1),this.m_localAnchor1.SetV(this.m_prismatic1.m_localAnchor2),d=this.m_prismatic1.GetJointTranslation());this.m_ground2=a.joint2.GetBodyA();this.m_bodyB=a.joint2.GetBodyB();c==Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint?(this.m_revolute2=
a.joint2,this.m_groundAnchor2.SetV(this.m_revolute2.m_localAnchor1),this.m_localAnchor2.SetV(this.m_revolute2.m_localAnchor2),e=this.m_revolute2.GetJointAngle()):(this.m_prismatic2=a.joint2,this.m_groundAnchor2.SetV(this.m_prismatic2.m_localAnchor1),this.m_localAnchor2.SetV(this.m_prismatic2.m_localAnchor2),e=this.m_prismatic2.GetJointTranslation());this.m_ratio=a.ratio;this.m_constant=d+this.m_ratio*e;this.m_impulse=0};c2inherit(Box2D.Dynamics.Joints.b2GearJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2GearJoint.prototype.GetAnchorA=
function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2GearJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};Box2D.Dynamics.Joints.b2GearJoint.prototype.GetReactionForce=function(a){void 0===a&&(a=0);return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse*this.m_J.linearB.x,a*this.m_impulse*this.m_J.linearB.y)};Box2D.Dynamics.Joints.b2GearJoint.prototype.GetReactionTorque=function(a){void 0===a&&(a=0);var b=this.m_bodyB.m_xf.R,
c=this.m_localAnchor1.x-this.m_bodyB.m_sweep.localCenter.x,d=this.m_localAnchor1.y-this.m_bodyB.m_sweep.localCenter.y,e=b.col1.x*c+b.col2.x*d,d=b.col1.y*c+b.col2.y*d;return a*(this.m_impulse*this.m_J.angularB-e*this.m_impulse*this.m_J.linearB.y+d*this.m_impulse*this.m_J.linearB.x)};Box2D.Dynamics.Joints.b2GearJoint.prototype.GetRatio=function(){return this.m_ratio};Box2D.Dynamics.Joints.b2GearJoint.prototype.SetRatio=function(a){void 0===a&&(a=0);this.m_ratio=a};Box2D.Dynamics.Joints.b2GearJoint.prototype.InitVelocityConstraints=
function(a){var b=this.m_ground1,c=this.m_ground2,d=this.m_bodyA,e=this.m_bodyB,g=0,f=0,l=0,k=0,h=l=0,m=0;this.m_J.SetZero();this.m_revolute1?(this.m_J.angularA=-1,m+=d.m_invI):(b=b.m_xf.R,f=this.m_prismatic1.m_localXAxis1,g=b.col1.x*f.x+b.col2.x*f.y,f=b.col1.y*f.x+b.col2.y*f.y,b=d.m_xf.R,l=this.m_localAnchor1.x-d.m_sweep.localCenter.x,k=this.m_localAnchor1.y-d.m_sweep.localCenter.y,h=b.col1.x*l+b.col2.x*k,k=b.col1.y*l+b.col2.y*k,l=h*f-k*g,this.m_J.linearA.Set(-g,-f),this.m_J.angularA=-l,m+=d.m_invMass+
d.m_invI*l*l);this.m_revolute2?(this.m_J.angularB=-this.m_ratio,m+=this.m_ratio*this.m_ratio*e.m_invI):(b=c.m_xf.R,f=this.m_prismatic2.m_localXAxis1,g=b.col1.x*f.x+b.col2.x*f.y,f=b.col1.y*f.x+b.col2.y*f.y,b=e.m_xf.R,l=this.m_localAnchor2.x-e.m_sweep.localCenter.x,k=this.m_localAnchor2.y-e.m_sweep.localCenter.y,h=b.col1.x*l+b.col2.x*k,k=b.col1.y*l+b.col2.y*k,l=h*f-k*g,this.m_J.linearB.Set(-this.m_ratio*g,-this.m_ratio*f),this.m_J.angularB=-this.m_ratio*l,m+=this.m_ratio*this.m_ratio*(e.m_invMass+e.m_invI*
l*l));this.m_mass=0<m?1/m:0;a.warmStarting?(d.m_linearVelocity.x+=d.m_invMass*this.m_impulse*this.m_J.linearA.x,d.m_linearVelocity.y+=d.m_invMass*this.m_impulse*this.m_J.linearA.y,d.m_angularVelocity+=d.m_invI*this.m_impulse*this.m_J.angularA,e.m_linearVelocity.x+=e.m_invMass*this.m_impulse*this.m_J.linearB.x,e.m_linearVelocity.y+=e.m_invMass*this.m_impulse*this.m_J.linearB.y,e.m_angularVelocity+=e.m_invI*this.m_impulse*this.m_J.angularB):this.m_impulse=0};Box2D.Dynamics.Joints.b2GearJoint.prototype.SolveVelocityConstraints=
function(a){a=this.m_bodyA;var b=this.m_bodyB,c=this.m_J.Compute(a.m_linearVelocity,a.m_angularVelocity,b.m_linearVelocity,b.m_angularVelocity),c=-this.m_mass*c;this.m_impulse+=c;a.m_linearVelocity.x+=a.m_invMass*c*this.m_J.linearA.x;a.m_linearVelocity.y+=a.m_invMass*c*this.m_J.linearA.y;a.m_angularVelocity+=a.m_invI*c*this.m_J.angularA;b.m_linearVelocity.x+=b.m_invMass*c*this.m_J.linearB.x;b.m_linearVelocity.y+=b.m_invMass*c*this.m_J.linearB.y;b.m_angularVelocity+=b.m_invI*c*this.m_J.angularB};Box2D.Dynamics.Joints.b2GearJoint.prototype.SolvePositionConstraints=
function(a){a=this.m_bodyA;var b=this.m_bodyB,c=0,d=0,c=this.m_revolute1?this.m_revolute1.GetJointAngle():this.m_prismatic1.GetJointTranslation(),d=this.m_revolute2?this.m_revolute2.GetJointAngle():this.m_prismatic2.GetJointTranslation(),c=-this.m_mass*(this.m_constant-(c+this.m_ratio*d));a.m_sweep.c.x+=a.m_invMass*c*this.m_J.linearA.x;a.m_sweep.c.y+=a.m_invMass*c*this.m_J.linearA.y;a.m_sweep.a+=a.m_invI*c*this.m_J.angularA;b.m_sweep.c.x+=b.m_invMass*c*this.m_J.linearB.x;b.m_sweep.c.y+=b.m_invMass*
c*this.m_J.linearB.y;b.m_sweep.a+=b.m_invI*c*this.m_J.angularB;a.SynchronizeTransform();b.SynchronizeTransform();return 0<Box2D.Common.b2Settings.b2_linearSlop};Box2D.Dynamics.Joints.b2GearJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.type=Box2D.Dynamics.Joints.b2Joint.e_gearJoint;this.joint2=this.joint1=null;this.ratio=1};c2inherit(Box2D.Dynamics.Joints.b2GearJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2GearJointDef.prototype.Initialize=function(a,b,c){this.joint1=
a;this.bodyA=a.GetBodyA();this.joint2=b;this.bodyB=b.GetBodyA();this.ratio=c};Box2D.Dynamics.Joints.b2GearJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2GearJoint(this)};Box2D.Dynamics.Joints.b2Jacobian=function(){this.linearA=Box2D.Common.Math.b2Vec2.Get(0,0);this.linearB=Box2D.Common.Math.b2Vec2.Get(0,0)};Box2D.Dynamics.Joints.b2Jacobian.prototype.SetZero=function(){this.linearA.SetZero();this.angularA=0;this.linearB.SetZero();this.angularB=0};Box2D.Dynamics.Joints.b2Jacobian.prototype.Set=
function(a,b,c,d){void 0===b&&(b=0);void 0===d&&(d=0);this.linearA.SetV(a);this.angularA=b;this.linearB.SetV(c);this.angularB=d};Box2D.Dynamics.Joints.b2Jacobian.prototype.Compute=function(a,b,c,d){void 0===b&&(b=0);void 0===d&&(d=0);return this.linearA.x*a.x+this.linearA.y*a.y+this.angularA*b+(this.linearB.x*c.x+this.linearB.y*c.y)+this.angularB*d};Box2D.Dynamics.Joints.b2LineJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=
Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localXAxis1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localYAxis1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_axis=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_perp=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_K=new Box2D.Common.Math.b2Mat22;this.m_impulse=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_localXAxis1.SetV(a.localAxisA);this.m_localYAxis1.x=-this.m_localXAxis1.y;this.m_localYAxis1.y=
this.m_localXAxis1.x;this.m_impulse.SetZero();this.m_motorImpulse=this.m_motorMass=0;this.m_lowerTranslation=a.lowerTranslation;this.m_upperTranslation=a.upperTranslation;this.m_maxMotorForce=a.maxMotorForce;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor;this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;this.m_axis.SetZero();this.m_perp.SetZero()};c2inherit(Box2D.Dynamics.Joints.b2LineJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2LineJoint.prototype.GetAnchorA=
function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetReactionForce=function(a){void 0===a&&(a=0);return Box2D.Common.Math.b2Vec2.Get(a*(this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.x),a*(this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.y))};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetReactionTorque=
function(a){void 0===a&&(a=0);return a*this.m_impulse.y};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetJointTranslation=function(){var a=this.m_bodyA,b=this.m_bodyB,c=a.GetWorldPoint(this.m_localAnchor1),d=b.GetWorldPoint(this.m_localAnchor2),b=d.x-c.x,c=d.y-c.y,a=a.GetWorldVector(this.m_localXAxis1);return a.x*b+a.y*c};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetJointSpeed=function(){var a=this.m_bodyA,b=this.m_bodyB,c;c=a.m_xf.R;var d=this.m_localAnchor1.x-a.m_sweep.localCenter.x,e=this.m_localAnchor1.y-
a.m_sweep.localCenter.y,g=c.col1.x*d+c.col2.x*e,e=c.col1.y*d+c.col2.y*e,d=g;c=b.m_xf.R;var f=this.m_localAnchor2.x-b.m_sweep.localCenter.x,l=this.m_localAnchor2.y-b.m_sweep.localCenter.y,g=c.col1.x*f+c.col2.x*l,l=c.col1.y*f+c.col2.y*l,f=g;c=b.m_sweep.c.x+f-(a.m_sweep.c.x+d);var g=b.m_sweep.c.y+l-(a.m_sweep.c.y+e),k=a.GetWorldVector(this.m_localXAxis1),h=a.m_linearVelocity,m=b.m_linearVelocity,a=a.m_angularVelocity,b=b.m_angularVelocity;return c*-a*k.y+g*a*k.x+(k.x*(m.x+-b*l-h.x- -a*e)+k.y*(m.y+b*
f-h.y-a*d))};Box2D.Dynamics.Joints.b2LineJoint.prototype.IsLimitEnabled=function(){return this.m_enableLimit};Box2D.Dynamics.Joints.b2LineJoint.prototype.EnableLimit=function(a){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_enableLimit=a};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetLowerLimit=function(){return this.m_lowerTranslation};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetUpperLimit=function(){return this.m_upperTranslation};Box2D.Dynamics.Joints.b2LineJoint.prototype.SetLimits=
function(a,b){void 0===a&&(a=0);void 0===b&&(b=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_lowerTranslation=a;this.m_upperTranslation=b};Box2D.Dynamics.Joints.b2LineJoint.prototype.IsMotorEnabled=function(){return this.m_enableMotor};Box2D.Dynamics.Joints.b2LineJoint.prototype.EnableMotor=function(a){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_enableMotor=a};Box2D.Dynamics.Joints.b2LineJoint.prototype.SetMotorSpeed=function(a){void 0===a&&(a=0);this.m_bodyA.SetAwake(!0);
this.m_bodyB.SetAwake(!0);this.m_motorSpeed=a};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetMotorSpeed=function(){return this.m_motorSpeed};Box2D.Dynamics.Joints.b2LineJoint.prototype.SetMaxMotorForce=function(a){void 0===a&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_maxMotorForce=a};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetMaxMotorForce=function(){return this.m_maxMotorForce};Box2D.Dynamics.Joints.b2LineJoint.prototype.GetMotorForce=function(){return this.m_motorImpulse};
Box2D.Dynamics.Joints.b2LineJoint.prototype.InitVelocityConstraints=function(a){var b=this.m_bodyA,c=this.m_bodyB,d,e=0;this.m_localCenterA.SetV(b.GetLocalCenter());this.m_localCenterB.SetV(c.GetLocalCenter());var g=b.GetTransform();c.GetTransform();d=b.m_xf.R;var f=this.m_localAnchor1.x-this.m_localCenterA.x,l=this.m_localAnchor1.y-this.m_localCenterA.y,e=d.col1.x*f+d.col2.x*l,l=d.col1.y*f+d.col2.y*l,f=e;d=c.m_xf.R;var k=this.m_localAnchor2.x-this.m_localCenterB.x,h=this.m_localAnchor2.y-this.m_localCenterB.y,
e=d.col1.x*k+d.col2.x*h,h=d.col1.y*k+d.col2.y*h,k=e;d=c.m_sweep.c.x+k-b.m_sweep.c.x-f;e=c.m_sweep.c.y+h-b.m_sweep.c.y-l;this.m_invMassA=b.m_invMass;this.m_invMassB=c.m_invMass;this.m_invIA=b.m_invI;this.m_invIB=c.m_invI;this.m_axis.SetV(Box2D.Common.Math.b2Math.MulMV(g.R,this.m_localXAxis1));this.m_a1=(d+f)*this.m_axis.y-(e+l)*this.m_axis.x;this.m_a2=k*this.m_axis.y-h*this.m_axis.x;this.m_motorMass=this.m_invMassA+this.m_invMassB+this.m_invIA*this.m_a1*this.m_a1+this.m_invIB*this.m_a2*this.m_a2;this.m_motorMass=
this.m_motorMass>Number.MIN_VALUE?1/this.m_motorMass:0;this.m_perp.SetV(Box2D.Common.Math.b2Math.MulMV(g.R,this.m_localYAxis1));this.m_s1=(d+f)*this.m_perp.y-(e+l)*this.m_perp.x;this.m_s2=k*this.m_perp.y-h*this.m_perp.x;g=this.m_invMassA;f=this.m_invMassB;l=this.m_invIA;k=this.m_invIB;this.m_K.col1.x=g+f+l*this.m_s1*this.m_s1+k*this.m_s2*this.m_s2;this.m_K.col1.y=l*this.m_s1*this.m_a1+k*this.m_s2*this.m_a2;this.m_K.col2.x=this.m_K.col1.y;this.m_K.col2.y=g+f+l*this.m_a1*this.m_a1+k*this.m_a2*this.m_a2;
this.m_enableLimit?(d=this.m_axis.x*d+this.m_axis.y*e,Math.abs(this.m_upperTranslation-this.m_lowerTranslation)<2*Box2D.Common.b2Settings.b2_linearSlop?this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_equalLimits:d<=this.m_lowerTranslation?this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit&&(this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit,this.m_impulse.y=0):d>=this.m_upperTranslation?this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&(this.m_limitState=
Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit,this.m_impulse.y=0):(this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit,this.m_impulse.y=0)):this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;!1==this.m_enableMotor&&(this.m_motorImpulse=0);a.warmStarting?(this.m_impulse.x*=a.dtRatio,this.m_impulse.y*=a.dtRatio,this.m_motorImpulse*=a.dtRatio,a=this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.y)*this.m_axis.x,d=this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+
this.m_impulse.y)*this.m_axis.y,e=this.m_impulse.x*this.m_s1+(this.m_motorImpulse+this.m_impulse.y)*this.m_a1,g=this.m_impulse.x*this.m_s2+(this.m_motorImpulse+this.m_impulse.y)*this.m_a2,b.m_linearVelocity.x-=this.m_invMassA*a,b.m_linearVelocity.y-=this.m_invMassA*d,b.m_angularVelocity-=this.m_invIA*e,c.m_linearVelocity.x+=this.m_invMassB*a,c.m_linearVelocity.y+=this.m_invMassB*d,c.m_angularVelocity+=this.m_invIB*g):(this.m_impulse.SetZero(),this.m_motorImpulse=0)};Box2D.Dynamics.Joints.b2LineJoint.prototype.SolveVelocityConstraints=
function(a){var b=this.m_bodyA,c=this.m_bodyB,d=b.m_linearVelocity,e=b.m_angularVelocity,g=c.m_linearVelocity,f=c.m_angularVelocity,l=0,k=0,h=0,m=0;this.m_enableMotor&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_equalLimits&&(m=this.m_motorMass*(this.m_motorSpeed-(this.m_axis.x*(g.x-d.x)+this.m_axis.y*(g.y-d.y)+this.m_a2*f-this.m_a1*e)),l=this.m_motorImpulse,k=a.dt*this.m_maxMotorForce,this.m_motorImpulse=Box2D.Common.Math.b2Math.Clamp(this.m_motorImpulse+m,-k,k),m=this.m_motorImpulse-l,l=
m*this.m_axis.x,k=m*this.m_axis.y,h=m*this.m_a1,m*=this.m_a2,d.x-=this.m_invMassA*l,d.y-=this.m_invMassA*k,e-=this.m_invIA*h,g.x+=this.m_invMassB*l,g.y+=this.m_invMassB*k,f+=this.m_invIB*m);k=this.m_perp.x*(g.x-d.x)+this.m_perp.y*(g.y-d.y)+this.m_s2*f-this.m_s1*e;this.m_enableLimit&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit?(h=this.m_axis.x*(g.x-d.x)+this.m_axis.y*(g.y-d.y)+this.m_a2*f-this.m_a1*e,l=this.m_impulse.Copy(),a=this.m_K.Solve(Box2D.Common.Math.b2Vec2.Get(0,0),-k,
-h),this.m_impulse.Add(a),this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit?this.m_impulse.y=Math.max(this.m_impulse.y,0):this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&(this.m_impulse.y=Math.min(this.m_impulse.y,0)),k=-k-(this.m_impulse.y-l.y)*this.m_K.col2.x,h=0,h=0!=this.m_K.col1.x?k/this.m_K.col1.x+l.x:l.x,this.m_impulse.x=h,a.x=this.m_impulse.x-l.x,a.y=this.m_impulse.y-l.y,l=a.x*this.m_perp.x+a.y*this.m_axis.x,k=a.x*this.m_perp.y+a.y*this.m_axis.y,h=a.x*this.m_s1+
a.y*this.m_a1,m=a.x*this.m_s2+a.y*this.m_a2):(a=0,a=0!=this.m_K.col1.x?-k/this.m_K.col1.x:0,this.m_impulse.x+=a,l=a*this.m_perp.x,k=a*this.m_perp.y,h=a*this.m_s1,m=a*this.m_s2);d.x-=this.m_invMassA*l;d.y-=this.m_invMassA*k;e-=this.m_invIA*h;g.x+=this.m_invMassB*l;g.y+=this.m_invMassB*k;f+=this.m_invIB*m;b.m_linearVelocity.SetV(d);b.m_angularVelocity=e;c.m_linearVelocity.SetV(g);c.m_angularVelocity=f};Box2D.Dynamics.Joints.b2LineJoint.prototype.SolvePositionConstraints=function(a){a=this.m_bodyA;var b=
this.m_bodyB,c=a.m_sweep.c,d=a.m_sweep.a,e=b.m_sweep.c,g=b.m_sweep.a,f,l=0,k=0,h=0,m=0,n=f=0,q=0,k=!1,p=0,r=Box2D.Common.Math.b2Mat22.FromAngle(d),h=Box2D.Common.Math.b2Mat22.FromAngle(g);f=r;var q=this.m_localAnchor1.x-this.m_localCenterA.x,s=this.m_localAnchor1.y-this.m_localCenterA.y,l=f.col1.x*q+f.col2.x*s,s=f.col1.y*q+f.col2.y*s,q=l;f=h;h=this.m_localAnchor2.x-this.m_localCenterB.x;m=this.m_localAnchor2.y-this.m_localCenterB.y;l=f.col1.x*h+f.col2.x*m;m=f.col1.y*h+f.col2.y*m;h=l;f=e.x+h-c.x-q;
l=e.y+m-c.y-s;if(this.m_enableLimit){this.m_axis=Box2D.Common.Math.b2Math.MulMV(r,this.m_localXAxis1);this.m_a1=(f+q)*this.m_axis.y-(l+s)*this.m_axis.x;this.m_a2=h*this.m_axis.y-m*this.m_axis.x;var t=this.m_axis.x*f+this.m_axis.y*l;Math.abs(this.m_upperTranslation-this.m_lowerTranslation)<2*Box2D.Common.b2Settings.b2_linearSlop?(p=Box2D.Common.Math.b2Math.Clamp(t,-Box2D.Common.b2Settings.b2_maxLinearCorrection,Box2D.Common.b2Settings.b2_maxLinearCorrection),n=Math.abs(t),k=!0):t<=this.m_lowerTranslation?
(p=Box2D.Common.Math.b2Math.Clamp(t-this.m_lowerTranslation+Box2D.Common.b2Settings.b2_linearSlop,-Box2D.Common.b2Settings.b2_maxLinearCorrection,0),n=this.m_lowerTranslation-t,k=!0):t>=this.m_upperTranslation&&(p=Box2D.Common.Math.b2Math.Clamp(t-this.m_upperTranslation+Box2D.Common.b2Settings.b2_linearSlop,0,Box2D.Common.b2Settings.b2_maxLinearCorrection),n=t-this.m_upperTranslation,k=!0)}this.m_perp=Box2D.Common.Math.b2Math.MulMV(r,this.m_localYAxis1);this.m_s1=(f+q)*this.m_perp.y-(l+s)*this.m_perp.x;
this.m_s2=h*this.m_perp.y-m*this.m_perp.x;r=Box2D.Common.Math.b2Vec2.Get(0,0);s=this.m_perp.x*f+this.m_perp.y*l;n=Math.max(n,Math.abs(s));q=0;k?(k=this.m_invMassA,h=this.m_invMassB,m=this.m_invIA,f=this.m_invIB,this.m_K.col1.x=k+h+m*this.m_s1*this.m_s1+f*this.m_s2*this.m_s2,this.m_K.col1.y=m*this.m_s1*this.m_a1+f*this.m_s2*this.m_a2,this.m_K.col2.x=this.m_K.col1.y,this.m_K.col2.y=k+h+m*this.m_a1*this.m_a1+f*this.m_a2*this.m_a2,this.m_K.Solve(r,-s,-p)):(k=this.m_invMassA,h=this.m_invMassB,m=this.m_invIA,
f=this.m_invIB,p=k+h+m*this.m_s1*this.m_s1+f*this.m_s2*this.m_s2,r.x=0!=p?-s/p:0,r.y=0);p=r.x*this.m_perp.x+r.y*this.m_axis.x;k=r.x*this.m_perp.y+r.y*this.m_axis.y;s=r.x*this.m_s1+r.y*this.m_a1;r=r.x*this.m_s2+r.y*this.m_a2;c.x-=this.m_invMassA*p;c.y-=this.m_invMassA*k;d-=this.m_invIA*s;e.x+=this.m_invMassB*p;e.y+=this.m_invMassB*k;g+=this.m_invIB*r;a.m_sweep.a=d;b.m_sweep.a=g;a.SynchronizeTransform();b.SynchronizeTransform();return n<=Box2D.Common.b2Settings.b2_linearSlop&&q<=Box2D.Common.b2Settings.b2_angularSlop};
Box2D.Dynamics.Joints.b2LineJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAxisA=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_lineJoint;this.localAxisA.Set(1,0);this.enableLimit=!1;this.upperTranslation=this.lowerTranslation=0;this.enableMotor=!1;this.motorSpeed=this.maxMotorForce=0};c2inherit(Box2D.Dynamics.Joints.b2LineJointDef,Box2D.Dynamics.Joints.b2JointDef);
Box2D.Dynamics.Joints.b2LineJointDef.prototype.Initialize=function(a,b,c,d){this.bodyA=a;this.bodyB=b;this.localAnchorA=this.bodyA.GetLocalPoint(c);this.localAnchorB=this.bodyB.GetLocalPoint(c);this.localAxisA=this.bodyA.GetLocalVector(d)};Box2D.Dynamics.Joints.b2LineJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2LineJoint(this)};Box2D.Dynamics.Joints.b2PrismaticJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,
0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localXAxis1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localYAxis1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_axis=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_perp=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_K=new Box2D.Common.Math.b2Mat33;this.m_impulse=new Box2D.Common.Math.b2Vec3(0,0,0);this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);this.m_localXAxis1.SetV(a.localAxisA);this.m_localYAxis1.x=-this.m_localXAxis1.y;
this.m_localYAxis1.y=this.m_localXAxis1.x;this.m_refAngle=a.referenceAngle;this.m_impulse.SetZero();this.m_motorImpulse=this.m_motorMass=0;this.m_lowerTranslation=a.lowerTranslation;this.m_upperTranslation=a.upperTranslation;this.m_maxMotorForce=a.maxMotorForce;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor;this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;this.m_axis.SetZero();this.m_perp.SetZero()};c2inherit(Box2D.Dynamics.Joints.b2PrismaticJoint,
Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetReactionForce=function(a){void 0===a&&(a=0);return Box2D.Common.Math.b2Vec2.Get(a*(this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.x),
a*(this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.y))};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetReactionTorque=function(a){void 0===a&&(a=0);return a*this.m_impulse.y};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetJointTranslation=function(){var a=this.m_bodyA,b=this.m_bodyB,c=a.GetWorldPoint(this.m_localAnchor1),d=b.GetWorldPoint(this.m_localAnchor2),b=d.x-c.x,c=d.y-c.y,a=a.GetWorldVector(this.m_localXAxis1);return a.x*b+a.y*c};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetJointSpeed=
function(){var a=this.m_bodyA,b=this.m_bodyB,c;c=a.m_xf.R;var d=this.m_localAnchor1.x-a.m_sweep.localCenter.x,e=this.m_localAnchor1.y-a.m_sweep.localCenter.y,g=c.col1.x*d+c.col2.x*e,e=c.col1.y*d+c.col2.y*e,d=g;c=b.m_xf.R;var f=this.m_localAnchor2.x-b.m_sweep.localCenter.x,l=this.m_localAnchor2.y-b.m_sweep.localCenter.y,g=c.col1.x*f+c.col2.x*l,l=c.col1.y*f+c.col2.y*l,f=g;c=b.m_sweep.c.x+f-(a.m_sweep.c.x+d);var g=b.m_sweep.c.y+l-(a.m_sweep.c.y+e),k=a.GetWorldVector(this.m_localXAxis1),h=a.m_linearVelocity,
m=b.m_linearVelocity,a=a.m_angularVelocity,b=b.m_angularVelocity;return c*-a*k.y+g*a*k.x+(k.x*(m.x+-b*l-h.x- -a*e)+k.y*(m.y+b*f-h.y-a*d))};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.IsLimitEnabled=function(){return this.m_enableLimit};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.EnableLimit=function(a){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_enableLimit=a};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetLowerLimit=function(){return this.m_lowerTranslation};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetUpperLimit=
function(){return this.m_upperTranslation};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SetLimits=function(a,b){void 0===a&&(a=0);void 0===b&&(b=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_lowerTranslation=a;this.m_upperTranslation=b};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.IsMotorEnabled=function(){return this.m_enableMotor};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.EnableMotor=function(a){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_enableMotor=
a};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SetMotorSpeed=function(a){void 0===a&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_motorSpeed=a};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetMotorSpeed=function(){return this.m_motorSpeed};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SetMaxMotorForce=function(a){void 0===a&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_maxMotorForce=a};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.GetMotorForce=
function(){return this.m_motorImpulse};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.InitVelocityConstraints=function(a){var b=this.m_bodyA,c=this.m_bodyB,d,e=0;this.m_localCenterA.SetV(b.GetLocalCenter());this.m_localCenterB.SetV(c.GetLocalCenter());var g=b.GetTransform();c.GetTransform();d=b.m_xf.R;var f=this.m_localAnchor1.x-this.m_localCenterA.x,l=this.m_localAnchor1.y-this.m_localCenterA.y,e=d.col1.x*f+d.col2.x*l,l=d.col1.y*f+d.col2.y*l,f=e;d=c.m_xf.R;var k=this.m_localAnchor2.x-this.m_localCenterB.x,
h=this.m_localAnchor2.y-this.m_localCenterB.y,e=d.col1.x*k+d.col2.x*h,h=d.col1.y*k+d.col2.y*h,k=e;d=c.m_sweep.c.x+k-b.m_sweep.c.x-f;e=c.m_sweep.c.y+h-b.m_sweep.c.y-l;this.m_invMassA=b.m_invMass;this.m_invMassB=c.m_invMass;this.m_invIA=b.m_invI;this.m_invIB=c.m_invI;this.m_axis.SetV(Box2D.Common.Math.b2Math.MulMV(g.R,this.m_localXAxis1));this.m_a1=(d+f)*this.m_axis.y-(e+l)*this.m_axis.x;this.m_a2=k*this.m_axis.y-h*this.m_axis.x;this.m_motorMass=this.m_invMassA+this.m_invMassB+this.m_invIA*this.m_a1*
this.m_a1+this.m_invIB*this.m_a2*this.m_a2;this.m_motorMass>Number.MIN_VALUE&&(this.m_motorMass=1/this.m_motorMass);this.m_perp.SetV(Box2D.Common.Math.b2Math.MulMV(g.R,this.m_localYAxis1));this.m_s1=(d+f)*this.m_perp.y-(e+l)*this.m_perp.x;this.m_s2=k*this.m_perp.y-h*this.m_perp.x;g=this.m_invMassA;f=this.m_invMassB;l=this.m_invIA;k=this.m_invIB;this.m_K.col1.x=g+f+l*this.m_s1*this.m_s1+k*this.m_s2*this.m_s2;this.m_K.col1.y=l*this.m_s1+k*this.m_s2;this.m_K.col1.z=l*this.m_s1*this.m_a1+k*this.m_s2*
this.m_a2;this.m_K.col2.x=this.m_K.col1.y;this.m_K.col2.y=l+k;this.m_K.col2.z=l*this.m_a1+k*this.m_a2;this.m_K.col3.x=this.m_K.col1.z;this.m_K.col3.y=this.m_K.col2.z;this.m_K.col3.z=g+f+l*this.m_a1*this.m_a1+k*this.m_a2*this.m_a2;this.m_enableLimit?(d=this.m_axis.x*d+this.m_axis.y*e,Math.abs(this.m_upperTranslation-this.m_lowerTranslation)<2*Box2D.Common.b2Settings.b2_linearSlop?this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_equalLimits:d<=this.m_lowerTranslation?this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit&&
(this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit,this.m_impulse.z=0):d>=this.m_upperTranslation?this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&(this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit,this.m_impulse.z=0):(this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit,this.m_impulse.z=0)):this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;!1==this.m_enableMotor&&(this.m_motorImpulse=0);a.warmStarting?(this.m_impulse.x*=a.dtRatio,
this.m_impulse.y*=a.dtRatio,this.m_motorImpulse*=a.dtRatio,a=this.m_impulse.x*this.m_perp.x+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.x,d=this.m_impulse.x*this.m_perp.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_axis.y,e=this.m_impulse.x*this.m_s1+this.m_impulse.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_a1,g=this.m_impulse.x*this.m_s2+this.m_impulse.y+(this.m_motorImpulse+this.m_impulse.z)*this.m_a2,b.m_linearVelocity.x-=this.m_invMassA*a,b.m_linearVelocity.y-=this.m_invMassA*d,
b.m_angularVelocity-=this.m_invIA*e,c.m_linearVelocity.x+=this.m_invMassB*a,c.m_linearVelocity.y+=this.m_invMassB*d,c.m_angularVelocity+=this.m_invIB*g):(this.m_impulse.SetZero(),this.m_motorImpulse=0)};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SolveVelocityConstraints=function(a){var b=this.m_bodyA,c=this.m_bodyB,d=b.m_linearVelocity,e=b.m_angularVelocity,g=c.m_linearVelocity,f=c.m_angularVelocity,l=0,k=0,h=0,m=0;this.m_enableMotor&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_equalLimits&&
(m=this.m_motorMass*(this.m_motorSpeed-(this.m_axis.x*(g.x-d.x)+this.m_axis.y*(g.y-d.y)+this.m_a2*f-this.m_a1*e)),l=this.m_motorImpulse,a=a.dt*this.m_maxMotorForce,this.m_motorImpulse=Box2D.Common.Math.b2Math.Clamp(this.m_motorImpulse+m,-a,a),m=this.m_motorImpulse-l,l=m*this.m_axis.x,k=m*this.m_axis.y,h=m*this.m_a1,m*=this.m_a2,d.x-=this.m_invMassA*l,d.y-=this.m_invMassA*k,e-=this.m_invIA*h,g.x+=this.m_invMassB*l,g.y+=this.m_invMassB*k,f+=this.m_invIB*m);h=this.m_perp.x*(g.x-d.x)+this.m_perp.y*(g.y-
d.y)+this.m_s2*f-this.m_s1*e;k=f-e;this.m_enableLimit&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit?(a=this.m_axis.x*(g.x-d.x)+this.m_axis.y*(g.y-d.y)+this.m_a2*f-this.m_a1*e,l=this.m_impulse.Copy(),a=this.m_K.Solve33(new Box2D.Common.Math.b2Vec3(0,0,0),-h,-k,-a),this.m_impulse.Add(a),this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit?this.m_impulse.z=Math.max(this.m_impulse.z,0):this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&(this.m_impulse.z=Math.min(this.m_impulse.z,
0)),h=-h-(this.m_impulse.z-l.z)*this.m_K.col3.x,k=-k-(this.m_impulse.z-l.z)*this.m_K.col3.y,k=this.m_K.Solve22(Box2D.Common.Math.b2Vec2.Get(0,0),h,k),k.x+=l.x,k.y+=l.y,this.m_impulse.x=k.x,this.m_impulse.y=k.y,a.x=this.m_impulse.x-l.x,a.y=this.m_impulse.y-l.y,a.z=this.m_impulse.z-l.z,l=a.x*this.m_perp.x+a.z*this.m_axis.x,k=a.x*this.m_perp.y+a.z*this.m_axis.y,h=a.x*this.m_s1+a.y+a.z*this.m_a1,m=a.x*this.m_s2+a.y+a.z*this.m_a2):(a=this.m_K.Solve22(Box2D.Common.Math.b2Vec2.Get(0,0),-h,-k),this.m_impulse.x+=
a.x,this.m_impulse.y+=a.y,l=a.x*this.m_perp.x,k=a.x*this.m_perp.y,h=a.x*this.m_s1+a.y,m=a.x*this.m_s2+a.y);d.x-=this.m_invMassA*l;d.y-=this.m_invMassA*k;e-=this.m_invIA*h;g.x+=this.m_invMassB*l;g.y+=this.m_invMassB*k;f+=this.m_invIB*m;b.m_linearVelocity.SetV(d);b.m_angularVelocity=e;c.m_linearVelocity.SetV(g);c.m_angularVelocity=f};Box2D.Dynamics.Joints.b2PrismaticJoint.prototype.SolvePositionConstraints=function(a){a=this.m_bodyA;var b=this.m_bodyB,c=a.m_sweep.c,d=a.m_sweep.a,e=b.m_sweep.c,g=b.m_sweep.a,
f,l=0,k=0,h=0,m=l=f=0,n=0,k=!1,q=0,p=Box2D.Common.Math.b2Mat22.FromAngle(d),r=Box2D.Common.Math.b2Mat22.FromAngle(g);f=p;var n=this.m_localAnchor1.x-this.m_localCenterA.x,s=this.m_localAnchor1.y-this.m_localCenterA.y,l=f.col1.x*n+f.col2.x*s,s=f.col1.y*n+f.col2.y*s,n=l;f=r;r=this.m_localAnchor2.x-this.m_localCenterB.x;h=this.m_localAnchor2.y-this.m_localCenterB.y;l=f.col1.x*r+f.col2.x*h;h=f.col1.y*r+f.col2.y*h;r=l;f=e.x+r-c.x-n;l=e.y+h-c.y-s;if(this.m_enableLimit){this.m_axis=Box2D.Common.Math.b2Math.MulMV(p,
this.m_localXAxis1);this.m_a1=(f+n)*this.m_axis.y-(l+s)*this.m_axis.x;this.m_a2=r*this.m_axis.y-h*this.m_axis.x;var t=this.m_axis.x*f+this.m_axis.y*l;Math.abs(this.m_upperTranslation-this.m_lowerTranslation)<2*Box2D.Common.b2Settings.b2_linearSlop?(q=Box2D.Common.Math.b2Math.Clamp(t,-Box2D.Common.b2Settings.b2_maxLinearCorrection,Box2D.Common.b2Settings.b2_maxLinearCorrection),m=Math.abs(t),k=!0):t<=this.m_lowerTranslation?(q=Box2D.Common.Math.b2Math.Clamp(t-this.m_lowerTranslation+Box2D.Common.b2Settings.b2_linearSlop,
-Box2D.Common.b2Settings.b2_maxLinearCorrection,0),m=this.m_lowerTranslation-t,k=!0):t>=this.m_upperTranslation&&(q=Box2D.Common.Math.b2Math.Clamp(t-this.m_upperTranslation+Box2D.Common.b2Settings.b2_linearSlop,0,Box2D.Common.b2Settings.b2_maxLinearCorrection),m=t-this.m_upperTranslation,k=!0)}this.m_perp=Box2D.Common.Math.b2Math.MulMV(p,this.m_localYAxis1);this.m_s1=(f+n)*this.m_perp.y-(l+s)*this.m_perp.x;this.m_s2=r*this.m_perp.y-h*this.m_perp.x;p=new Box2D.Common.Math.b2Vec3(0,0,0);s=this.m_perp.x*
f+this.m_perp.y*l;r=g-d-this.m_refAngle;m=Math.max(m,Math.abs(s));n=Math.abs(r);k?(k=this.m_invMassA,h=this.m_invMassB,f=this.m_invIA,l=this.m_invIB,this.m_K.col1.x=k+h+f*this.m_s1*this.m_s1+l*this.m_s2*this.m_s2,this.m_K.col1.y=f*this.m_s1+l*this.m_s2,this.m_K.col1.z=f*this.m_s1*this.m_a1+l*this.m_s2*this.m_a2,this.m_K.col2.x=this.m_K.col1.y,this.m_K.col2.y=f+l,this.m_K.col2.z=f*this.m_a1+l*this.m_a2,this.m_K.col3.x=this.m_K.col1.z,this.m_K.col3.y=this.m_K.col2.z,this.m_K.col3.z=k+h+f*this.m_a1*
this.m_a1+l*this.m_a2*this.m_a2,this.m_K.Solve33(p,-s,-r,-q)):(k=this.m_invMassA,h=this.m_invMassB,f=this.m_invIA,l=this.m_invIB,q=f*this.m_s1+l*this.m_s2,t=f+l,this.m_K.col1.Set(k+h+f*this.m_s1*this.m_s1+l*this.m_s2*this.m_s2,q,0),this.m_K.col2.Set(q,t,0),q=this.m_K.Solve22(Box2D.Common.Math.b2Vec2.Get(0,0),-s,-r),p.x=q.x,p.y=q.y,p.z=0);q=p.x*this.m_perp.x+p.z*this.m_axis.x;k=p.x*this.m_perp.y+p.z*this.m_axis.y;s=p.x*this.m_s1+p.y+p.z*this.m_a1;p=p.x*this.m_s2+p.y+p.z*this.m_a2;c.x-=this.m_invMassA*
q;c.y-=this.m_invMassA*k;d-=this.m_invIA*s;e.x+=this.m_invMassB*q;e.y+=this.m_invMassB*k;g+=this.m_invIB*p;a.m_sweep.a=d;b.m_sweep.a=g;a.SynchronizeTransform();b.SynchronizeTransform();return m<=Box2D.Common.b2Settings.b2_linearSlop&&n<=Box2D.Common.b2Settings.b2_angularSlop};Box2D.Dynamics.Joints.b2PrismaticJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAxisA=Box2D.Common.Math.b2Vec2.Get(0,
0);this.type=Box2D.Dynamics.Joints.b2Joint.e_prismaticJoint;this.localAxisA.Set(1,0);this.referenceAngle=0;this.enableLimit=!1;this.upperTranslation=this.lowerTranslation=0;this.enableMotor=!1;this.motorSpeed=this.maxMotorForce=0};c2inherit(Box2D.Dynamics.Joints.b2PrismaticJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2PrismaticJointDef.prototype.Initialize=function(a,b,c,d){this.bodyA=a;this.bodyB=b;this.localAnchorA=this.bodyA.GetLocalPoint(c);this.localAnchorB=this.bodyB.GetLocalPoint(c);
this.localAxisA=this.bodyA.GetLocalVector(d);this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()};Box2D.Dynamics.Joints.b2PrismaticJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2PrismaticJoint(this)};Box2D.Dynamics.Joints.b2PulleyJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_groundAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_groundAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=
Box2D.Common.Math.b2Vec2.Get(0,0);this.m_u1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_u2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_ground=this.m_bodyA.m_world.m_groundBody;this.m_groundAnchor1.x=a.groundAnchorA.x-this.m_ground.m_xf.position.x;this.m_groundAnchor1.y=a.groundAnchorA.y-this.m_ground.m_xf.position.y;this.m_groundAnchor2.x=a.groundAnchorB.x-this.m_ground.m_xf.position.x;this.m_groundAnchor2.y=a.groundAnchorB.y-this.m_ground.m_xf.position.y;this.m_localAnchor1.SetV(a.localAnchorA);this.m_localAnchor2.SetV(a.localAnchorB);
this.m_ratio=a.ratio;this.m_constant=a.lengthA+this.m_ratio*a.lengthB;this.m_maxLength1=Math.min(a.maxLengthA,this.m_constant-this.m_ratio*Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength);this.m_maxLength2=Math.min(a.maxLengthB,(this.m_constant-Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength)/this.m_ratio);this.m_limitImpulse2=this.m_limitImpulse1=this.m_impulse=0};c2inherit(Box2D.Dynamics.Joints.b2PulleyJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetAnchorA=
function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetReactionForce=function(a){void 0===a&&(a=0);return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse*this.m_u2.x,a*this.m_impulse*this.m_u2.y)};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetReactionTorque=function(a){return 0};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetGroundAnchorA=
function(){var a=this.m_ground.m_xf.position.Copy();a.Add(this.m_groundAnchor1);return a};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetGroundAnchorB=function(){var a=this.m_ground.m_xf.position.Copy();a.Add(this.m_groundAnchor2);return a};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetLength1=function(){var a=this.m_bodyA.GetWorldPoint(this.m_localAnchor1),b=a.x-(this.m_ground.m_xf.position.x+this.m_groundAnchor1.x),a=a.y-(this.m_ground.m_xf.position.y+this.m_groundAnchor1.y);return Math.sqrt(b*
b+a*a)};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetLength2=function(){var a=this.m_bodyB.GetWorldPoint(this.m_localAnchor2),b=a.x-(this.m_ground.m_xf.position.x+this.m_groundAnchor2.x),a=a.y-(this.m_ground.m_xf.position.y+this.m_groundAnchor2.y);return Math.sqrt(b*b+a*a)};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.GetRatio=function(){return this.m_ratio};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.InitVelocityConstraints=function(a){var b=this.m_bodyA,c=this.m_bodyB,d;d=b.m_xf.R;var e=
this.m_localAnchor1.x-b.m_sweep.localCenter.x,g=this.m_localAnchor1.y-b.m_sweep.localCenter.y,f=d.col1.x*e+d.col2.x*g,g=d.col1.y*e+d.col2.y*g,e=f;d=c.m_xf.R;var l=this.m_localAnchor2.x-c.m_sweep.localCenter.x,k=this.m_localAnchor2.y-c.m_sweep.localCenter.y,f=d.col1.x*l+d.col2.x*k,k=d.col1.y*l+d.col2.y*k,l=f;d=c.m_sweep.c.x+l;var f=c.m_sweep.c.y+k,h=this.m_ground.m_xf.position.x+this.m_groundAnchor2.x,m=this.m_ground.m_xf.position.y+this.m_groundAnchor2.y;this.m_u1.Set(b.m_sweep.c.x+e-(this.m_ground.m_xf.position.x+
this.m_groundAnchor1.x),b.m_sweep.c.y+g-(this.m_ground.m_xf.position.y+this.m_groundAnchor1.y));this.m_u2.Set(d-h,f-m);d=this.m_u1.Length();f=this.m_u2.Length();d>Box2D.Common.b2Settings.b2_linearSlop?this.m_u1.Multiply(1/d):this.m_u1.SetZero();f>Box2D.Common.b2Settings.b2_linearSlop?this.m_u2.Multiply(1/f):this.m_u2.SetZero();0<this.m_constant-d-this.m_ratio*f?(this.m_state=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit,this.m_impulse=0):this.m_state=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit;d<
this.m_maxLength1?(this.m_limitState1=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit,this.m_limitImpulse1=0):this.m_limitState1=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit;f<this.m_maxLength2?(this.m_limitState2=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit,this.m_limitImpulse2=0):this.m_limitState2=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit;d=e*this.m_u1.y-g*this.m_u1.x;f=l*this.m_u2.y-k*this.m_u2.x;this.m_limitMass1=b.m_invMass+b.m_invI*d*d;this.m_limitMass2=c.m_invMass+c.m_invI*f*f;this.m_pulleyMass=
this.m_limitMass1+this.m_ratio*this.m_ratio*this.m_limitMass2;this.m_limitMass1=1/this.m_limitMass1;this.m_limitMass2=1/this.m_limitMass2;this.m_pulleyMass=1/this.m_pulleyMass;a.warmStarting?(this.m_impulse*=a.dtRatio,this.m_limitImpulse1*=a.dtRatio,this.m_limitImpulse2*=a.dtRatio,a=(-this.m_impulse-this.m_limitImpulse1)*this.m_u1.x,d=(-this.m_impulse-this.m_limitImpulse1)*this.m_u1.y,f=(-this.m_ratio*this.m_impulse-this.m_limitImpulse2)*this.m_u2.x,h=(-this.m_ratio*this.m_impulse-this.m_limitImpulse2)*
this.m_u2.y,b.m_linearVelocity.x+=b.m_invMass*a,b.m_linearVelocity.y+=b.m_invMass*d,b.m_angularVelocity+=b.m_invI*(e*d-g*a),c.m_linearVelocity.x+=c.m_invMass*f,c.m_linearVelocity.y+=c.m_invMass*h,c.m_angularVelocity+=c.m_invI*(l*h-k*f)):this.m_limitImpulse2=this.m_limitImpulse1=this.m_impulse=0};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.SolveVelocityConstraints=function(a){a=this.m_bodyA;var b=this.m_bodyB,c;c=a.m_xf.R;var d=this.m_localAnchor1.x-a.m_sweep.localCenter.x,e=this.m_localAnchor1.y-
a.m_sweep.localCenter.y,g=c.col1.x*d+c.col2.x*e,e=c.col1.y*d+c.col2.y*e,d=g;c=b.m_xf.R;var f=this.m_localAnchor2.x-b.m_sweep.localCenter.x,l=this.m_localAnchor2.y-b.m_sweep.localCenter.y,g=c.col1.x*f+c.col2.x*l,l=c.col1.y*f+c.col2.y*l,f=g,k=g=c=0,h=0;c=h=c=h=k=g=c=0;this.m_state==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&(c=a.m_linearVelocity.x+-a.m_angularVelocity*e,g=a.m_linearVelocity.y+a.m_angularVelocity*d,k=b.m_linearVelocity.x+-b.m_angularVelocity*l,h=b.m_linearVelocity.y+b.m_angularVelocity*
f,c=-(this.m_u1.x*c+this.m_u1.y*g)-this.m_ratio*(this.m_u2.x*k+this.m_u2.y*h),h=this.m_pulleyMass*-c,c=this.m_impulse,this.m_impulse=Math.max(0,this.m_impulse+h),h=this.m_impulse-c,c=-h*this.m_u1.x,g=-h*this.m_u1.y,k=-this.m_ratio*h*this.m_u2.x,h=-this.m_ratio*h*this.m_u2.y,a.m_linearVelocity.x+=a.m_invMass*c,a.m_linearVelocity.y+=a.m_invMass*g,a.m_angularVelocity+=a.m_invI*(d*g-e*c),b.m_linearVelocity.x+=b.m_invMass*k,b.m_linearVelocity.y+=b.m_invMass*h,b.m_angularVelocity+=b.m_invI*(f*h-l*k));this.m_limitState1==
Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&(c=a.m_linearVelocity.x+-a.m_angularVelocity*e,g=a.m_linearVelocity.y+a.m_angularVelocity*d,c=-(this.m_u1.x*c+this.m_u1.y*g),h=-this.m_limitMass1*c,c=this.m_limitImpulse1,this.m_limitImpulse1=Math.max(0,this.m_limitImpulse1+h),h=this.m_limitImpulse1-c,c=-h*this.m_u1.x,g=-h*this.m_u1.y,a.m_linearVelocity.x+=a.m_invMass*c,a.m_linearVelocity.y+=a.m_invMass*g,a.m_angularVelocity+=a.m_invI*(d*g-e*c));this.m_limitState2==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&
(k=b.m_linearVelocity.x+-b.m_angularVelocity*l,h=b.m_linearVelocity.y+b.m_angularVelocity*f,c=-(this.m_u2.x*k+this.m_u2.y*h),h=-this.m_limitMass2*c,c=this.m_limitImpulse2,this.m_limitImpulse2=Math.max(0,this.m_limitImpulse2+h),h=this.m_limitImpulse2-c,k=-h*this.m_u2.x,h=-h*this.m_u2.y,b.m_linearVelocity.x+=b.m_invMass*k,b.m_linearVelocity.y+=b.m_invMass*h,b.m_angularVelocity+=b.m_invI*(f*h-l*k))};Box2D.Dynamics.Joints.b2PulleyJoint.prototype.SolvePositionConstraints=function(a){a=this.m_bodyA;var b=
this.m_bodyB,c,d=this.m_ground.m_xf.position.x+this.m_groundAnchor1.x,e=this.m_ground.m_xf.position.y+this.m_groundAnchor1.y,g=this.m_ground.m_xf.position.x+this.m_groundAnchor2.x,f=this.m_ground.m_xf.position.y+this.m_groundAnchor2.y,l=0,k=0,h=0,m=0,n=c=0,q=0,p=0,r=n=p=c=n=c=0;this.m_state==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&(c=a.m_xf.R,l=this.m_localAnchor1.x-a.m_sweep.localCenter.x,k=this.m_localAnchor1.y-a.m_sweep.localCenter.y,n=c.col1.x*l+c.col2.x*k,k=c.col1.y*l+c.col2.y*k,l=n,c=
b.m_xf.R,h=this.m_localAnchor2.x-b.m_sweep.localCenter.x,m=this.m_localAnchor2.y-b.m_sweep.localCenter.y,n=c.col1.x*h+c.col2.x*m,m=c.col1.y*h+c.col2.y*m,h=n,c=a.m_sweep.c.x+l,n=a.m_sweep.c.y+k,q=b.m_sweep.c.x+h,p=b.m_sweep.c.y+m,this.m_u1.Set(c-d,n-e),this.m_u2.Set(q-g,p-f),c=this.m_u1.Length(),n=this.m_u2.Length(),c>Box2D.Common.b2Settings.b2_linearSlop?this.m_u1.Multiply(1/c):this.m_u1.SetZero(),n>Box2D.Common.b2Settings.b2_linearSlop?this.m_u2.Multiply(1/n):this.m_u2.SetZero(),c=this.m_constant-
c-this.m_ratio*n,r=Math.max(r,-c),c=Box2D.Common.Math.b2Math.Clamp(c+Box2D.Common.b2Settings.b2_linearSlop,-Box2D.Common.b2Settings.b2_maxLinearCorrection,0),p=-this.m_pulleyMass*c,c=-p*this.m_u1.x,n=-p*this.m_u1.y,q=-this.m_ratio*p*this.m_u2.x,p=-this.m_ratio*p*this.m_u2.y,a.m_sweep.c.x+=a.m_invMass*c,a.m_sweep.c.y+=a.m_invMass*n,a.m_sweep.a+=a.m_invI*(l*n-k*c),b.m_sweep.c.x+=b.m_invMass*q,b.m_sweep.c.y+=b.m_invMass*p,b.m_sweep.a+=b.m_invI*(h*p-m*q),a.SynchronizeTransform(),b.SynchronizeTransform());
this.m_limitState1==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&(c=a.m_xf.R,l=this.m_localAnchor1.x-a.m_sweep.localCenter.x,k=this.m_localAnchor1.y-a.m_sweep.localCenter.y,n=c.col1.x*l+c.col2.x*k,k=c.col1.y*l+c.col2.y*k,l=n,c=a.m_sweep.c.x+l,n=a.m_sweep.c.y+k,this.m_u1.Set(c-d,n-e),c=this.m_u1.Length(),c>Box2D.Common.b2Settings.b2_linearSlop?(this.m_u1.x*=1/c,this.m_u1.y*=1/c):this.m_u1.SetZero(),c=this.m_maxLength1-c,r=Math.max(r,-c),c=Box2D.Common.Math.b2Math.Clamp(c+Box2D.Common.b2Settings.b2_linearSlop,
-Box2D.Common.b2Settings.b2_maxLinearCorrection,0),p=-this.m_limitMass1*c,c=-p*this.m_u1.x,n=-p*this.m_u1.y,a.m_sweep.c.x+=a.m_invMass*c,a.m_sweep.c.y+=a.m_invMass*n,a.m_sweep.a+=a.m_invI*(l*n-k*c),a.SynchronizeTransform());this.m_limitState2==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&(c=b.m_xf.R,h=this.m_localAnchor2.x-b.m_sweep.localCenter.x,m=this.m_localAnchor2.y-b.m_sweep.localCenter.y,n=c.col1.x*h+c.col2.x*m,m=c.col1.y*h+c.col2.y*m,h=n,q=b.m_sweep.c.x+h,p=b.m_sweep.c.y+m,this.m_u2.Set(q-
g,p-f),n=this.m_u2.Length(),n>Box2D.Common.b2Settings.b2_linearSlop?(this.m_u2.x*=1/n,this.m_u2.y*=1/n):this.m_u2.SetZero(),c=this.m_maxLength2-n,r=Math.max(r,-c),c=Box2D.Common.Math.b2Math.Clamp(c+Box2D.Common.b2Settings.b2_linearSlop,-Box2D.Common.b2Settings.b2_maxLinearCorrection,0),p=-this.m_limitMass2*c,q=-p*this.m_u2.x,p=-p*this.m_u2.y,b.m_sweep.c.x+=b.m_invMass*q,b.m_sweep.c.y+=b.m_invMass*p,b.m_sweep.a+=b.m_invI*(h*p-m*q),b.SynchronizeTransform());return r<Box2D.Common.b2Settings.b2_linearSlop};
Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength=1;Box2D.Dynamics.Joints.b2PulleyJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.groundAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.groundAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_pulleyJoint;this.groundAnchorA.Set(-1,1);this.groundAnchorB.Set(1,1);this.localAnchorA.Set(-1,0);this.localAnchorB.Set(1,
0);this.maxLengthB=this.lengthB=this.maxLengthA=this.lengthA=0;this.ratio=1;this.collideConnected=!0};c2inherit(Box2D.Dynamics.Joints.b2PulleyJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2PulleyJointDef.prototype.Initialize=function(a,b,c,d,e,g,f){void 0===f&&(f=0);this.bodyA=a;this.bodyB=b;this.groundAnchorA.SetV(c);this.groundAnchorB.SetV(d);this.localAnchorA=this.bodyA.GetLocalPoint(e);this.localAnchorB=this.bodyB.GetLocalPoint(g);a=e.x-c.x;c=e.y-c.y;this.lengthA=Math.sqrt(a*
a+c*c);c=g.x-d.x;d=g.y-d.y;this.lengthB=Math.sqrt(c*c+d*d);this.ratio=f;f=this.lengthA+this.ratio*this.lengthB;this.maxLengthA=f-this.ratio*Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength;this.maxLengthB=(f-Box2D.Dynamics.Joints.b2PulleyJoint.b2_minPulleyLength)/this.ratio};Box2D.Dynamics.Joints.b2PulleyJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2PulleyJoint(this)};Box2D.Dynamics.Joints.b2RevoluteJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.K=
new Box2D.Common.Math.b2Mat22;this.K1=new Box2D.Common.Math.b2Mat22;this.K2=new Box2D.Common.Math.b2Mat22;this.K3=new Box2D.Common.Math.b2Mat22;this.impulse3=new Box2D.Common.Math.b2Vec3(0,0,0);this.impulse2=Box2D.Common.Math.b2Vec2.Get(0,0);this.reduced=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor1=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchor2=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_impulse=new Box2D.Common.Math.b2Vec3(0,0,0);this.m_mass=new Box2D.Common.Math.b2Mat33;this.m_localAnchor1.SetV(a.localAnchorA);
this.m_localAnchor2.SetV(a.localAnchorB);this.m_referenceAngle=a.referenceAngle;this.m_impulse.SetZero();this.m_motorImpulse=0;this.m_lowerAngle=a.lowerAngle;this.m_upperAngle=a.upperAngle;this.m_maxMotorTorque=a.maxMotorTorque;this.m_motorSpeed=a.motorSpeed;this.m_enableLimit=a.enableLimit;this.m_enableMotor=a.enableMotor;this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit};c2inherit(Box2D.Dynamics.Joints.b2RevoluteJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetAnchorA=
function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchor1)};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchor2)};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetReactionForce=function(a){void 0===a&&(a=0);return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse.x,a*this.m_impulse.y)};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetReactionTorque=function(a){void 0===a&&(a=0);return a*this.m_impulse.z};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetJointAngle=
function(){return this.m_bodyB.m_sweep.a-this.m_bodyA.m_sweep.a-this.m_referenceAngle};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetJointSpeed=function(){return this.m_bodyB.m_angularVelocity-this.m_bodyA.m_angularVelocity};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.IsLimitEnabled=function(){return this.m_enableLimit};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.EnableLimit=function(a){this.m_enableLimit=a};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetLowerLimit=function(){return this.m_lowerAngle};
Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetUpperLimit=function(){return this.m_upperAngle};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SetLimits=function(a,b){void 0===a&&(a=0);void 0===b&&(b=0);this.m_lowerAngle=a;this.m_upperAngle=b};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.IsMotorEnabled=function(){this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);return this.m_enableMotor};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.EnableMotor=function(a){this.m_enableMotor=a};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SetMotorSpeed=
function(a){void 0===a&&(a=0);this.m_bodyA.SetAwake(!0);this.m_bodyB.SetAwake(!0);this.m_motorSpeed=a};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetMotorSpeed=function(){return this.m_motorSpeed};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SetMaxMotorTorque=function(a){void 0===a&&(a=0);this.m_maxMotorTorque=a};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.GetMotorTorque=function(){return this.m_maxMotorTorque};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.InitVelocityConstraints=function(a){var b=
this.m_bodyA,c=this.m_bodyB,d,e=0;d=b.m_xf.R;var g=this.m_localAnchor1.x-b.m_sweep.localCenter.x,f=this.m_localAnchor1.y-b.m_sweep.localCenter.y,e=d.col1.x*g+d.col2.x*f,f=d.col1.y*g+d.col2.y*f,g=e;d=c.m_xf.R;var l=this.m_localAnchor2.x-c.m_sweep.localCenter.x,k=this.m_localAnchor2.y-c.m_sweep.localCenter.y,e=d.col1.x*l+d.col2.x*k,k=d.col1.y*l+d.col2.y*k,l=e;d=b.m_invMass;var e=c.m_invMass,h=b.m_invI,m=c.m_invI;this.m_mass.col1.x=d+e+f*f*h+k*k*m;this.m_mass.col2.x=-f*g*h-k*l*m;this.m_mass.col3.x=-f*
h-k*m;this.m_mass.col1.y=this.m_mass.col2.x;this.m_mass.col2.y=d+e+g*g*h+l*l*m;this.m_mass.col3.y=g*h+l*m;this.m_mass.col1.z=this.m_mass.col3.x;this.m_mass.col2.z=this.m_mass.col3.y;this.m_mass.col3.z=h+m;this.m_motorMass=1/(h+m);this.m_enableMotor||(this.m_motorImpulse=0);if(this.m_enableLimit){var n=c.m_sweep.a-b.m_sweep.a-this.m_referenceAngle;Math.abs(this.m_upperAngle-this.m_lowerAngle)<2*Box2D.Common.b2Settings.b2_angularSlop?this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_equalLimits:n<=
this.m_lowerAngle?(this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit&&(this.m_impulse.z=0),this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit):n>=this.m_upperAngle?(this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&(this.m_impulse.z=0),this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit):(this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit,this.m_impulse.z=0)}else this.m_limitState=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit;a.warmStarting?
(this.m_impulse.x*=a.dtRatio,this.m_impulse.y*=a.dtRatio,this.m_motorImpulse*=a.dtRatio,a=this.m_impulse.x,n=this.m_impulse.y,b.m_linearVelocity.x-=d*a,b.m_linearVelocity.y-=d*n,b.m_angularVelocity-=h*(g*n-f*a+this.m_motorImpulse+this.m_impulse.z),c.m_linearVelocity.x+=e*a,c.m_linearVelocity.y+=e*n,c.m_angularVelocity+=m*(l*n-k*a+this.m_motorImpulse+this.m_impulse.z)):(this.m_impulse.SetZero(),this.m_motorImpulse=0)};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SolveVelocityConstraints=function(a){var b=
this.m_bodyA,c=this.m_bodyB,d=0,e=d=0,g=0,f=0,l=0,k=b.m_linearVelocity,h=b.m_angularVelocity,m=c.m_linearVelocity,n=c.m_angularVelocity,q=b.m_invMass,p=c.m_invMass,r=b.m_invI,s=c.m_invI;this.m_enableMotor&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_equalLimits&&(e=this.m_motorMass*-(n-h-this.m_motorSpeed),g=this.m_motorImpulse,f=a.dt*this.m_maxMotorTorque,this.m_motorImpulse=Box2D.Common.Math.b2Math.Clamp(this.m_motorImpulse+e,-f,f),e=this.m_motorImpulse-g,h-=r*e,n+=s*e);if(this.m_enableLimit&&
this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit){a=b.m_xf.R;e=this.m_localAnchor1.x-b.m_sweep.localCenter.x;g=this.m_localAnchor1.y-b.m_sweep.localCenter.y;d=a.col1.x*e+a.col2.x*g;g=a.col1.y*e+a.col2.y*g;e=d;a=c.m_xf.R;f=this.m_localAnchor2.x-c.m_sweep.localCenter.x;l=this.m_localAnchor2.y-c.m_sweep.localCenter.y;d=a.col1.x*f+a.col2.x*l;l=a.col1.y*f+a.col2.y*l;f=d;a=m.x+-n*l-k.x- -h*g;var t=m.y+n*f-k.y-h*e;this.m_mass.Solve33(this.impulse3,-a,-t,-(n-h));this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_equalLimits?
this.m_impulse.Add(this.impulse3):this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit?(d=this.m_impulse.z+this.impulse3.z,0>d&&(this.m_mass.Solve22(this.reduced,-a,-t),this.impulse3.x=this.reduced.x,this.impulse3.y=this.reduced.y,this.impulse3.z=-this.m_impulse.z,this.m_impulse.x+=this.reduced.x,this.m_impulse.y+=this.reduced.y,this.m_impulse.z=0)):this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&(d=this.m_impulse.z+this.impulse3.z,0<d&&(this.m_mass.Solve22(this.reduced,
-a,-t),this.impulse3.x=this.reduced.x,this.impulse3.y=this.reduced.y,this.impulse3.z=-this.m_impulse.z,this.m_impulse.x+=this.reduced.x,this.m_impulse.y+=this.reduced.y,this.m_impulse.z=0));k.x-=q*this.impulse3.x;k.y-=q*this.impulse3.y;h-=r*(e*this.impulse3.y-g*this.impulse3.x+this.impulse3.z);m.x+=p*this.impulse3.x;m.y+=p*this.impulse3.y;n+=s*(f*this.impulse3.y-l*this.impulse3.x+this.impulse3.z)}else a=b.m_xf.R,e=this.m_localAnchor1.x-b.m_sweep.localCenter.x,g=this.m_localAnchor1.y-b.m_sweep.localCenter.y,
d=a.col1.x*e+a.col2.x*g,g=a.col1.y*e+a.col2.y*g,e=d,a=c.m_xf.R,f=this.m_localAnchor2.x-c.m_sweep.localCenter.x,l=this.m_localAnchor2.y-c.m_sweep.localCenter.y,d=a.col1.x*f+a.col2.x*l,l=a.col1.y*f+a.col2.y*l,f=d,this.m_mass.Solve22(this.impulse2,-(m.x+-n*l-k.x- -h*g),-(m.y+n*f-k.y-h*e)),this.m_impulse.x+=this.impulse2.x,this.m_impulse.y+=this.impulse2.y,k.x-=q*this.impulse2.x,k.y-=q*this.impulse2.y,h-=r*(e*this.impulse2.y-g*this.impulse2.x),m.x+=p*this.impulse2.x,m.y+=p*this.impulse2.y,n+=s*(f*this.impulse2.y-
l*this.impulse2.x);b.m_linearVelocity.SetV(k);b.m_angularVelocity=h;c.m_linearVelocity.SetV(m);c.m_angularVelocity=n};Box2D.Dynamics.Joints.b2RevoluteJoint.prototype.SolvePositionConstraints=function(a){var b=0,c;a=this.m_bodyA;var d=this.m_bodyB,e=0,g=c=0,f=0,l=0;if(this.m_enableLimit&&this.m_limitState!=Box2D.Dynamics.Joints.b2Joint.e_inactiveLimit){var b=d.m_sweep.a-a.m_sweep.a-this.m_referenceAngle,k=0;this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_equalLimits?(b=Box2D.Common.Math.b2Math.Clamp(b-
this.m_lowerAngle,-Box2D.Common.b2Settings.b2_maxAngularCorrection,Box2D.Common.b2Settings.b2_maxAngularCorrection),k=-this.m_motorMass*b,e=Math.abs(b)):this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atLowerLimit?(b-=this.m_lowerAngle,e=-b,b=Box2D.Common.Math.b2Math.Clamp(b+Box2D.Common.b2Settings.b2_angularSlop,-Box2D.Common.b2Settings.b2_maxAngularCorrection,0),k=-this.m_motorMass*b):this.m_limitState==Box2D.Dynamics.Joints.b2Joint.e_atUpperLimit&&(e=b-=this.m_upperAngle,b=Box2D.Common.Math.b2Math.Clamp(b-
Box2D.Common.b2Settings.b2_angularSlop,0,Box2D.Common.b2Settings.b2_maxAngularCorrection),k=-this.m_motorMass*b);a.m_sweep.a-=a.m_invI*k;d.m_sweep.a+=d.m_invI*k;a.SynchronizeTransform();d.SynchronizeTransform()}c=a.m_xf.R;k=this.m_localAnchor1.x-a.m_sweep.localCenter.x;b=this.m_localAnchor1.y-a.m_sweep.localCenter.y;g=c.col1.x*k+c.col2.x*b;b=c.col1.y*k+c.col2.y*b;k=g;c=d.m_xf.R;var h=this.m_localAnchor2.x-d.m_sweep.localCenter.x,m=this.m_localAnchor2.y-d.m_sweep.localCenter.y,g=c.col1.x*h+c.col2.x*
m,m=c.col1.y*h+c.col2.y*m,h=g,f=d.m_sweep.c.x+h-a.m_sweep.c.x-k,l=d.m_sweep.c.y+m-a.m_sweep.c.y-b,n=f*f+l*l;c=Math.sqrt(n);var g=a.m_invMass,q=d.m_invMass,p=a.m_invI,r=d.m_invI,s=10*Box2D.Common.b2Settings.b2_linearSlop;n>s*s&&(n=1/(g+q),f=n*-f,l=n*-l,a.m_sweep.c.x-=0.5*g*f,a.m_sweep.c.y-=0.5*g*l,d.m_sweep.c.x+=0.5*q*f,d.m_sweep.c.y+=0.5*q*l,f=d.m_sweep.c.x+h-a.m_sweep.c.x-k,l=d.m_sweep.c.y+m-a.m_sweep.c.y-b);this.K1.col1.x=g+q;this.K1.col2.x=0;this.K1.col1.y=0;this.K1.col2.y=g+q;this.K2.col1.x=p*
b*b;this.K2.col2.x=-p*k*b;this.K2.col1.y=-p*k*b;this.K2.col2.y=p*k*k;this.K3.col1.x=r*m*m;this.K3.col2.x=-r*h*m;this.K3.col1.y=-r*h*m;this.K3.col2.y=r*h*h;this.K.SetM(this.K1);this.K.AddM(this.K2);this.K.AddM(this.K3);this.K.Solve(Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse,-f,-l);f=Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse.x;l=Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse.y;a.m_sweep.c.x-=a.m_invMass*f;a.m_sweep.c.y-=a.m_invMass*l;a.m_sweep.a-=a.m_invI*(k*l-b*f);d.m_sweep.c.x+=d.m_invMass*
f;d.m_sweep.c.y+=d.m_invMass*l;d.m_sweep.a+=d.m_invI*(h*l-m*f);a.SynchronizeTransform();d.SynchronizeTransform();return c<=Box2D.Common.b2Settings.b2_linearSlop&&e<=Box2D.Common.b2Settings.b2_angularSlop};Box2D.Dynamics.Joints.b2RevoluteJoint.tImpulse=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Dynamics.Joints.b2RevoluteJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_revoluteJoint;
this.localAnchorA.SetZero();this.localAnchorB.SetZero();this.motorSpeed=this.maxMotorTorque=this.upperAngle=this.lowerAngle=this.referenceAngle=0;this.enableMotor=this.enableLimit=!1};c2inherit(Box2D.Dynamics.Joints.b2RevoluteJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2RevoluteJointDef.prototype.Initialize=function(a,b,c){this.bodyA=a;this.bodyB=b;this.localAnchorA=this.bodyA.GetLocalPoint(c);this.localAnchorB=this.bodyB.GetLocalPoint(c);this.referenceAngle=this.bodyB.GetAngle()-
this.bodyA.GetAngle()};Box2D.Dynamics.Joints.b2RevoluteJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2RevoluteJoint(this)};Box2D.Dynamics.Joints.b2WeldJoint=function(a){Box2D.Dynamics.Joints.b2Joint.call(this,a);this.m_localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.m_impulse=new Box2D.Common.Math.b2Vec3(0,0,0);this.m_mass=new Box2D.Common.Math.b2Mat33;this.m_localAnchorA.SetV(a.localAnchorA);this.m_localAnchorB.SetV(a.localAnchorB);
this.m_referenceAngle=a.referenceAngle};c2inherit(Box2D.Dynamics.Joints.b2WeldJoint,Box2D.Dynamics.Joints.b2Joint);Box2D.Dynamics.Joints.b2WeldJoint.prototype.GetAnchorA=function(){return this.m_bodyA.GetWorldPoint(this.m_localAnchorA)};Box2D.Dynamics.Joints.b2WeldJoint.prototype.GetAnchorB=function(){return this.m_bodyB.GetWorldPoint(this.m_localAnchorB)};Box2D.Dynamics.Joints.b2WeldJoint.prototype.GetReactionForce=function(a){return Box2D.Common.Math.b2Vec2.Get(a*this.m_impulse.x,a*this.m_impulse.y)};
Box2D.Dynamics.Joints.b2WeldJoint.prototype.GetReactionTorque=function(a){return a*this.m_impulse.z};Box2D.Dynamics.Joints.b2WeldJoint.prototype.InitVelocityConstraints=function(a){var b,c=0,d=this.m_bodyA,e=this.m_bodyB;b=d.m_xf.R;var g=this.m_localAnchorA.x-d.m_sweep.localCenter.x,f=this.m_localAnchorA.y-d.m_sweep.localCenter.y,c=b.col1.x*g+b.col2.x*f,f=b.col1.y*g+b.col2.y*f,g=c;b=e.m_xf.R;var l=this.m_localAnchorB.x-e.m_sweep.localCenter.x,k=this.m_localAnchorB.y-e.m_sweep.localCenter.y,c=b.col1.x*
l+b.col2.x*k,k=b.col1.y*l+b.col2.y*k,l=c;b=d.m_invMass;var c=e.m_invMass,h=d.m_invI,m=e.m_invI;this.m_mass.col1.x=b+c+f*f*h+k*k*m;this.m_mass.col2.x=-f*g*h-k*l*m;this.m_mass.col3.x=-f*h-k*m;this.m_mass.col1.y=this.m_mass.col2.x;this.m_mass.col2.y=b+c+g*g*h+l*l*m;this.m_mass.col3.y=g*h+l*m;this.m_mass.col1.z=this.m_mass.col3.x;this.m_mass.col2.z=this.m_mass.col3.y;this.m_mass.col3.z=h+m;a.warmStarting?(this.m_impulse.x*=a.dtRatio,this.m_impulse.y*=a.dtRatio,this.m_impulse.z*=a.dtRatio,d.m_linearVelocity.x-=
b*this.m_impulse.x,d.m_linearVelocity.y-=b*this.m_impulse.y,d.m_angularVelocity-=h*(g*this.m_impulse.y-f*this.m_impulse.x+this.m_impulse.z),e.m_linearVelocity.x+=c*this.m_impulse.x,e.m_linearVelocity.y+=c*this.m_impulse.y,e.m_angularVelocity+=m*(l*this.m_impulse.y-k*this.m_impulse.x+this.m_impulse.z)):this.m_impulse.SetZero()};Box2D.Dynamics.Joints.b2WeldJoint.prototype.SolveVelocityConstraints=function(a){var b,c=0;a=this.m_bodyA;var d=this.m_bodyB,e=a.m_linearVelocity,g=a.m_angularVelocity,f=d.m_linearVelocity,
l=d.m_angularVelocity,k=a.m_invMass,h=d.m_invMass,m=a.m_invI,n=d.m_invI;b=a.m_xf.R;var q=this.m_localAnchorA.x-a.m_sweep.localCenter.x,p=this.m_localAnchorA.y-a.m_sweep.localCenter.y,c=b.col1.x*q+b.col2.x*p,p=b.col1.y*q+b.col2.y*p,q=c;b=d.m_xf.R;var r=this.m_localAnchorB.x-d.m_sweep.localCenter.x,s=this.m_localAnchorB.y-d.m_sweep.localCenter.y,c=b.col1.x*r+b.col2.x*s,s=b.col1.y*r+b.col2.y*s,r=c;b=f.x-l*s-e.x+g*p;var c=f.y+l*r-e.y-g*q,t=l-g,v=new Box2D.Common.Math.b2Vec3(0,0,0);this.m_mass.Solve33(v,
-b,-c,-t);this.m_impulse.Add(v);e.x-=k*v.x;e.y-=k*v.y;g-=m*(q*v.y-p*v.x+v.z);f.x+=h*v.x;f.y+=h*v.y;l+=n*(r*v.y-s*v.x+v.z);a.m_angularVelocity=g;d.m_angularVelocity=l};Box2D.Dynamics.Joints.b2WeldJoint.prototype.SolvePositionConstraints=function(a){var b,c=0;a=this.m_bodyA;var d=this.m_bodyB;b=a.m_xf.R;var e=this.m_localAnchorA.x-a.m_sweep.localCenter.x,g=this.m_localAnchorA.y-a.m_sweep.localCenter.y,c=b.col1.x*e+b.col2.x*g,g=b.col1.y*e+b.col2.y*g,e=c;b=d.m_xf.R;var f=this.m_localAnchorB.x-d.m_sweep.localCenter.x,
l=this.m_localAnchorB.y-d.m_sweep.localCenter.y,c=b.col1.x*f+b.col2.x*l,l=b.col1.y*f+b.col2.y*l,f=c;b=a.m_invMass;var c=d.m_invMass,k=a.m_invI,h=d.m_invI,m=d.m_sweep.c.x+f-a.m_sweep.c.x-e,n=d.m_sweep.c.y+l-a.m_sweep.c.y-g,q=d.m_sweep.a-a.m_sweep.a-this.m_referenceAngle,p=10*Box2D.Common.b2Settings.b2_linearSlop,r=Math.sqrt(m*m+n*n),s=Math.abs(q);r>p&&(k*=1,h*=1);this.m_mass.col1.x=b+c+g*g*k+l*l*h;this.m_mass.col2.x=-g*e*k-l*f*h;this.m_mass.col3.x=-g*k-l*h;this.m_mass.col1.y=this.m_mass.col2.x;this.m_mass.col2.y=
b+c+e*e*k+f*f*h;this.m_mass.col3.y=e*k+f*h;this.m_mass.col1.z=this.m_mass.col3.x;this.m_mass.col2.z=this.m_mass.col3.y;this.m_mass.col3.z=k+h;p=new Box2D.Common.Math.b2Vec3(0,0,0);this.m_mass.Solve33(p,-m,-n,-q);a.m_sweep.c.x-=b*p.x;a.m_sweep.c.y-=b*p.y;a.m_sweep.a-=k*(e*p.y-g*p.x+p.z);d.m_sweep.c.x+=c*p.x;d.m_sweep.c.y+=c*p.y;d.m_sweep.a+=h*(f*p.y-l*p.x+p.z);a.SynchronizeTransform();d.SynchronizeTransform();return r<=Box2D.Common.b2Settings.b2_linearSlop&&s<=Box2D.Common.b2Settings.b2_angularSlop};
Box2D.Dynamics.Joints.b2WeldJointDef=function(){Box2D.Dynamics.Joints.b2JointDef.call(this);this.localAnchorA=Box2D.Common.Math.b2Vec2.Get(0,0);this.localAnchorB=Box2D.Common.Math.b2Vec2.Get(0,0);this.type=Box2D.Dynamics.Joints.b2Joint.e_weldJoint;this.referenceAngle=0};c2inherit(Box2D.Dynamics.Joints.b2WeldJointDef,Box2D.Dynamics.Joints.b2JointDef);Box2D.Dynamics.Joints.b2WeldJointDef.prototype.Initialize=function(a,b,c){this.bodyA=a;this.bodyB=b;this.localAnchorA.SetV(this.bodyA.GetLocalPoint(c));
this.localAnchorB.SetV(this.bodyB.GetLocalPoint(c));this.referenceAngle=this.bodyB.GetAngle()-this.bodyA.GetAngle()};Box2D.Dynamics.Joints.b2WeldJointDef.prototype.Create=function(){return new Box2D.Dynamics.Joints.b2WeldJoint(this)};Box2D.Collision.b2Collision.s_incidentEdge=Box2D.Collision.b2Collision.MakeClipPointVector();Box2D.Collision.b2Collision.s_clipPoints1=Box2D.Collision.b2Collision.MakeClipPointVector();Box2D.Collision.b2Collision.s_clipPoints2=Box2D.Collision.b2Collision.MakeClipPointVector();
Box2D.Collision.b2Collision.s_localTangent=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_localNormal=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_planePoint=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_normal=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_tangent=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_tangent2=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2Collision.s_v11=Box2D.Common.Math.b2Vec2.Get(0,
0);Box2D.Collision.b2Collision.s_v12=Box2D.Common.Math.b2Vec2.Get(0,0);Box2D.Collision.b2TimeOfImpact.b2_toiCalls=0;Box2D.Collision.b2TimeOfImpact.b2_toiIters=0;Box2D.Collision.b2TimeOfImpact.b2_toiMaxIters=0;Box2D.Collision.b2TimeOfImpact.b2_toiRootIters=0;Box2D.Collision.b2TimeOfImpact.b2_toiMaxRootIters=0;Box2D.Collision.b2TimeOfImpact.s_cache=new Box2D.Collision.b2SimplexCache;Box2D.Collision.b2TimeOfImpact.s_distanceInput=new Box2D.Collision.b2DistanceInput;Box2D.Collision.b2TimeOfImpact.s_xfA=
new Box2D.Common.Math.b2Transform;Box2D.Collision.b2TimeOfImpact.s_xfB=new Box2D.Common.Math.b2Transform;Box2D.Collision.b2TimeOfImpact.s_fcn=new Box2D.Collision.b2SeparationFunction;Box2D.Collision.b2TimeOfImpact.s_distanceOutput=new Box2D.Collision.b2DistanceOutput;Box2D.Dynamics.b2Body.s_xf1=new Box2D.Common.Math.b2Transform;Box2D.Dynamics.b2ContactListener.b2_defaultListener=new Box2D.Dynamics.b2ContactListener;Box2D.Dynamics.b2ContactManager.s_evalCP=new Box2D.Collision.b2ContactPoint;Box2D.Dynamics.b2World.s_xf=
new Box2D.Common.Math.b2Transform;Box2D.Dynamics.b2World.s_backupA=new Box2D.Common.Math.b2Sweep;Box2D.Dynamics.b2World.s_backupB=new Box2D.Common.Math.b2Sweep;Box2D.Dynamics.Contacts.b2Contact.s_input=new Box2D.Collision.b2TOIInput;Box2D.Dynamics.Contacts.b2ContactSolver.s_worldManifold=new Box2D.Collision.b2WorldManifold;Box2D.Dynamics.Contacts.b2ContactSolver.s_psm=new Box2D.Dynamics.Contacts.b2PositionSolverManifold}cr.b2Separator=function(){};
cr.b2Separator.det=function(a,b,c,d,e,g){return a*d+c*g+e*b-b*c-d*e-g*a};cr.b2Separator.hitRay=function(a,b,c,d,e,g,f,l){var k=c-a,h=d-b,m=f-e,n=l-g,m=(m*(g-b)-n*(e-a))/(h*m-k*n),k=a+m*k,h=b+m*h;a=cr.b2Separator.isOnSegment(c,d,a,b,k,h);e=cr.b2Separator.isOnSegment(k,h,e,g,f,l);return a&&e?Box2D.Common.Math.b2Vec2.Get(k,h):null};
cr.b2Separator.isOnSegment=function(a,b,c,d,e,g){return(c+0.1>=a&&a>=e-0.1||c-0.1<=a&&a<=e+0.1)&&(d+0.1>=b&&b>=g-0.1||d-0.1<=b&&b<=g+0.1)&&cr.b2Separator.isOnLine(a,b,c,d,e,g)};cr.b2Separator.isOnLine=function(a,b,c,d,e,g){return 0.1<Math.abs(e-c)?0.1>Math.abs((g-d)/(e-c)*(a-c)+d-b):0.1>Math.abs(a-c)};cr.b2Separator.pointsMatch=function(a,b,c,d){return 0.1>Math.abs(c-a)&&0.1>Math.abs(d-b)};
cr.b2Separator.Separate=function(a,b){var c=Box2D.Common.Math.b2Vec2,d=cr.b2Separator.calcShapes(a),e=[],g,f,l,k,h,m,n,q,p;h=0;for(m=d.length;h<m;h++){f=d[h];g=[];g.length=f.length;n=p=0;for(q=f.length;n<q;n++)l=f[n],k=f[(n+1)%q],p+=l.x*k.y-l.y*k.x,g[n]=c.Get(l.x,l.y);p=Math.abs(p/2);p>=0.001*b&&e.push(g)}return e};
cr.b2Separator.calcShapes=function(a){var b=[],c=0,d=0,e=0,g=0,f=0,l=f=0,k=0,h=0,m=0,g=0,n,q,p,r=g=c=0,s=0,e=[],k=[],t=!1,v=[],w=[];for(w.push(a);w.length;){b=w[0];d=b.length;t=!0;for(c=0;c<d;c++)if(h=c,m=c<d-1?c+1:c+1-d,g=c<d-2?c+2:c+2-d,a=b[h],n=b[m],g=b[g],g=cr.b2Separator.det(a.x,a.y,n.x,n.y,g.x,g.y),0>g){t=!1;k=1E9;for(e=0;e<d;e++)if(e!==h&&e!==m&&(c=e,g=e<d-1?e+1:0,f=b[c],l=b[g],q=cr.b2Separator.hitRay(a.x,a.y,n.x,n.y,f.x,f.y,l.x,l.y)))f=n.x-q.x,l=n.y-q.y,f=f*f+l*l,f<k&&(s=c,r=g,p=q,k=f);if(1E9===
k)return[];e=[];k=[];c=s;g=r;f=b[c];l=b[g];cr.b2Separator.pointsMatch(p.x,p.y,l.x,l.y)||e.push(p);cr.b2Separator.pointsMatch(p.x,p.y,f.x,f.y)||k.push(p);s=-1;for(r=h;;){if(r!==g)e.push(b[r]);else{if(0>s||s>=d)return[];cr.b2Separator.isOnSegment(l.x,l.y,b[s].x,b[s].y,a.x,a.y)||e.push(b[r]);break}s=r;0>r-1?r=d-1:r--}e.reverse();s=-1;for(r=m;;){if(r!==c)k.push(b[r]);else{if(0>s||s>=d)return[];r===c&&!cr.b2Separator.isOnSegment(f.x,f.y,b[s].x,b[s].y,n.x,n.y)&&k.push(b[r]);break}s=r;r+1>d-1?r=0:r++}w.push(e,
k);w.shift();break}t&&v.push(w.shift())}return v};
cr.behaviors.Physics=function(a){for(var b=0;4E3>b;b++)Box2D.Common.Math.b2Vec2._freeCache.push(new Box2D.Common.Math.b2Vec2(0,0));this.runtime=a;this.world=new Box2D.Dynamics.b2World(Box2D.Common.Math.b2Vec2.Get(0,10),!0);this.worldG=10;this.lastUpdateTick=-1;a=new Box2D.Dynamics.b2ContactListener;a.behavior=this;a.BeginContact=function(a){var b=a.m_fixtureA.GetBody().c2userdata;a=a.m_fixtureB.GetBody().c2userdata;this.behavior.runtime.registerCollision(b.inst,a.inst)};this.world.SetContactListener(a);
a=new Box2D.Dynamics.b2ContactFilter;a.behavior=this;a.ShouldCollide=function(a,b){if(this.behavior.allCollisionsEnabled)return!0;var e=a.GetBody().c2userdata.inst.type,g=b.GetBody().c2userdata.inst.type,f=e.extra.Physics_DisabledCollisions;return f&&f.contains(g)?!1:(f=g.extra.Physics_DisabledCollisions)&&f.contains(e)?!1:!0};this.world.SetContactFilter(a);this.steppingMode=0;this.velocityIterations=8;this.positionIterations=3;this.allCollisionsEnabled=!0};
(function(){function a(){}function b(){}function c(a,b,c){c?((c=a.extra.Physics_DisabledCollisions)&&c.remove(b),(c=b.extra.Physics_DisabledCollisions)&&c.remove(a)):(a.extra.Physics_DisabledCollisions||(a.extra.Physics_DisabledCollisions=new cr.ObjectSet),a.extra.Physics_DisabledCollisions.add(b),b.extra.Physics_DisabledCollisions||(b.extra.Physics_DisabledCollisions=new cr.ObjectSet),b.extra.Physics_DisabledCollisions.add(a))}function d(){}var e=Box2D.Common.Math.b2Vec2,g=Box2D.Dynamics.b2BodyDef,
f=Box2D.Dynamics.b2FixtureDef,l=Box2D.Collision.Shapes.b2PolygonShape,k=Box2D.Collision.Shapes.b2CircleShape,h=Box2D.Dynamics.Joints.b2DistanceJointDef,m=Box2D.Dynamics.Joints.b2RevoluteJointDef,n=cr.behaviors.Physics.prototype;n.Type=function(a,b){this.behavior=a;this.objtype=b;this.runtime=a.runtime};n.Type.prototype.onCreate=function(){};n.Instance=function(a,b){this.type=a;this.behavior=a.behavior;this.inst=b;this.runtime=a.runtime;this.world=this.behavior.world};var q=n.Instance.prototype;q.onCreate=
function(){this.immovable=0!==this.properties[0];this.collisionmask=this.properties[1];this.preventRotation=0!==this.properties[2];this.density=this.properties[3];this.friction=this.properties[4];this.restitution=this.properties[5];this.linearDamping=this.properties[6];this.angularDamping=this.properties[7];this.bullet=0!==this.properties[8];this.enabled=0!==this.properties[9];this.body=null;this.inst.update_bbox();this.lastKnownX=this.inst.x;this.lastKnownY=this.inst.y;this.lastKnownAngle=this.inst.angle;
this.lastHeight=this.lastWidth=0;this.recreateBody=this.lastTickOverride=!1;this.lastAnimation=null;this.lastAnimationFrame=-1;this.myJoints?(this.myJoints.length=0,this.myCreatedJoints.length=0,this.joiningMe.clear()):(this.myJoints=[],this.myCreatedJoints=[],this.joiningMe=new cr.ObjectSet);var a=this;this.recycled||(this.myDestroyCallback=function(b){a.onInstanceDestroyed(b)});this.runtime.addDestroyCallback(this.myDestroyCallback)};q.postCreate=function(){this.inst.update_bbox();this.createBody();
this.lastAnimation=this.inst.cur_animation;this.lastAnimationFrame=this.inst.cur_frame};q.onDestroy=function(){this.destroyMyJoints();this.myCreatedJoints.length=0;this.joiningMe.clear();this.body&&(this.world.DestroyBody(this.body),this.body=null);this.runtime.removeDestroyCallback(this.myDestroyCallback)};q.saveToJSON=function(){var a={e:this.enabled,im:this.immovable,pr:this.preventRotation,d:this.density,fr:this.friction,re:this.restitution,ld:this.linearDamping,ad:this.angularDamping,b:this.bullet,
mcj:this.myCreatedJoints};if(this.enabled){var b=e.Get(0,0);b.SetV(this.body.GetLinearVelocity());a.vx=b.x;a.vy=b.y;a.om=this.body.GetAngularVelocity()}return a};q.loadFromJSON=function(a){this.destroyMyJoints();this.myCreatedJoints.length=0;this.joiningMe.clear();this.body&&(this.world.DestroyBody(this.body),this.body=null);this.enabled=a.e;this.immovable=a.im;this.preventRotation=a.pr;this.density=a.d;this.friction=a.fr;this.restitution=a.re;this.linearDamping=a.ld;this.angularDamping=a.ad;this.bullet=
a.b;this.lastKnownX=this.inst.x;this.lastKnownY=this.inst.y;this.lastKnownAngle=this.inst.angle;this.lastWidth=this.inst.width;this.lastHeight=this.inst.height;this.enabled&&(this.createBody(),this.body.SetLinearVelocity(e.Get(a.vx,a.vy)),this.body.SetAngularVelocity(a.om),(0!==a.vx||0!==a.vy||0!==a.om)&&this.body.SetAwake(!0),this.myCreatedJoints=a.mcj)};q.afterLoad=function(){this.enabled&&this.recreateMyJoints();this.behavior.lastUpdateTick=this.runtime.tickcount-1};q.onInstanceDestroyed=function(a){var b,
c,d,e=a.uid;d=b=0;for(c=this.myCreatedJoints.length;b<c;b++)this.myCreatedJoints[d]=this.myCreatedJoints[b],d<this.myJoints.length&&(this.myJoints[d]=this.myJoints[b]),this.myCreatedJoints[b].params[1]==e?this.world.DestroyJoint(this.myJoints[b]):d++;this.myCreatedJoints.length=d;d<this.myJoints.length&&(this.myJoints.length=d);this.joiningMe.remove(a)};q.destroyMyJoints=function(){var a,b;a=0;for(b=this.myJoints.length;a<b;a++)this.world.DestroyJoint(this.myJoints[a]);this.myJoints.length=0};q.recreateMyJoints=
function(){var a,b,c;a=0;for(b=this.myCreatedJoints.length;a<b;a++)switch(c=this.myCreatedJoints[a],c.type){case 0:this.doCreateDistanceJoint(c.params[0],c.params[1],c.params[2],c.params[3],c.params[4]);break;case 1:this.doCreateRevoluteJoint(c.params[0],c.params[1]);break;case 2:this.doCreateLimitedRevoluteJoint(c.params[0],c.params[1],c.params[2],c.params[3])}};q.destroyBody=function(){this.body&&(this.destroyMyJoints(),this.world.DestroyBody(this.body),this.body=null,this.inst.extra.box2dbody=
null)};q.createBody=function(){if(this.enabled){var a=this.inst,b=!1,c=null,d=null,h,m,n,q,z,x;this.body&&(b=!0,c=e.Get(0,0),c.SetV(this.body.GetLinearVelocity()),d=this.body.GetAngularVelocity(),this.destroyBody());var A=new f;A.density=this.density;A.friction=this.friction;A.restitution=this.restitution;h=new g;h.type=this.immovable?0:2;a.update_bbox();h.position.x=0.02*a.bquad.midX();h.position.y=0.02*a.bquad.midY();h.angle=a.angle;h.fixedRotation=this.preventRotation;h.linearDamping=this.linearDamping;
h.angularDamping=this.angularDamping;h.bullet=this.bullet;x=this.inst.collision_poly&&!this.inst.collision_poly.is_empty();this.body=this.world.CreateBody(h);this.body.c2userdata=this;h=this.collisionmask;!x&&0===this.collisionmask&&(h=1);m=Math.max(Math.abs(a.width),1);n=Math.max(Math.abs(a.height),1);var D=0>a.width;q=0>a.height;if(0===h){h=a.angle;a.angle=0;a.set_bbox_changed();a.update_bbox();z=a.bquad.midX()-a.x;var G=a.bquad.midY()-a.y;a.angle=h;a.set_bbox_changed();a.collision_poly.cache_poly(D?
-m:m,q?-n:n,0);var F=a.collision_poly.pts_cache,u=a.collision_poly.pts_count;x=[];x.length=u;for(h=0;h<u;h++)x[h]=e.Get(F[2*h]-z,F[2*h+1]-G);D!==q&&x.reverse();D=cr.b2Separator.Separate(x,m*n);for(h=0;h<u;h++)e.Free(x[h]);if(D.length){h=0;for(m=D.length;h<m;h++){x=D[h];n=0;for(q=x.length;n<q;n++)z=x[n],z.x*=0.02,z.y*=0.02;A.shape=new l;A.shape.SetAsArray(x,x.length);this.body.CreateFixture(A);n=0;for(q=x.length;n<q;n++)e.Free(x[n])}}else A.shape=new l,A.shape.SetAsBox(0.01*m,0.01*n),this.body.CreateFixture(A)}else 1===
h?(A.shape=new l,A.shape.SetAsBox(0.01*m,0.01*n)):A.shape=new k(0.01*Math.min(m,n)),this.body.CreateFixture(A);a.extra.box2dbody=this.body;this.lastWidth=a.width;this.lastHeight=a.height;if(b){this.body.SetLinearVelocity(c);this.body.SetAngularVelocity(d);e.Free(c);this.recreateMyJoints();x=this.joiningMe.valuesRef();h=0;for(m=x.length;h<m;h++)a=x[h].extra.box2dbody.c2userdata,a.destroyMyJoints(),a.recreateMyJoints()}}};q.tick=function(){if(this.enabled){var a=this.inst,b;0===this.behavior.steppingMode?
b=this.runtime.timescale/60:(b=this.runtime.getDt(this.inst),b>1/30&&(b=1/30));this.runtime.tickcount>this.behavior.lastUpdateTick&&0<this.runtime.timescale&&(this.world.Step(b,this.behavior.velocityIterations,this.behavior.positionIterations),this.world.ClearForces(),this.behavior.lastUpdateTick=this.runtime.tickcount);if(this.recreateBody||a.width!==this.lastWidth||a.height!==this.lastHeight||a.cur_animation!==this.lastAnimation||a.cur_frame!==this.lastAnimationFrame)this.createBody(),this.recreateBody=
!1,this.lastAnimation=a.cur_animation,this.lastAnimationFrame=a.cur_frame;b=a.angle!==this.lastKnownAngle;if(a.x!==this.lastKnownX||a.y!==this.lastKnownY){a.update_bbox();var c=a.bquad.midX(),d=a.bquad.midY(),f=c-this.lastKnownX,g=d-this.lastKnownY;this.body.SetPosition(e.Get(0.02*c,0.02*d));this.body.SetLinearVelocity(e.Get(f,g));this.lastTickOverride=!0;this.body.SetAwake(!0)}else this.lastTickOverride&&(this.lastTickOverride=!1,this.body.SetLinearVelocity(e.Get(0,0)),this.body.SetPosition(e.Get(0.02*
a.bquad.midX(),0.02*a.bquad.midY())));b&&(this.body.SetAngle(a.angle),this.body.SetAwake(!0));c=this.body.GetPosition();b=c.x/0.02;c=c.y/0.02;d=this.body.GetAngle();if(b!==a.x||c!==a.y||d!==a.angle)if(a.x=b,a.y=c,a.angle=d,a.set_bbox_changed(),a.update_bbox(),b=a.bquad.midX()-a.x,c=a.bquad.midY()-a.y,0!==b||0!==c)a.x-=b,a.y-=c,a.set_bbox_changed();this.lastKnownX=a.x;this.lastKnownY=a.y;this.lastKnownAngle=a.angle}};q.getInstImgPointX=function(a){return-1===a||!this.inst.getImagePoint?this.inst.x:
0===a&&this.body?(this.body.GetPosition().x+this.body.GetLocalCenter().x)/0.02:this.inst.getImagePoint(a,!0)};q.getInstImgPointY=function(a){return-1===a||!this.inst.getImagePoint?this.inst.y:0===a&&this.body?(this.body.GetPosition().y+this.body.GetLocalCenter().y)/0.02:this.inst.getImagePoint(a,!1)};a.prototype.IsSleeping=function(){return!this.enabled?!1:!this.body.IsAwake()};a.prototype.CompareVelocity=function(a,b,c){if(!this.enabled)return!1;var d=this.body.GetLinearVelocity();0===a?d=d.x/0.02:
1===a?d=d.y/0.02:(a=d.x/0.02,d=d.y/0.02,d=cr.distanceTo(0,0,a,d));return cr.do_cmp(d,b,c)};a.prototype.CompareAngularVelocity=function(a,b){if(!this.enabled)return!1;var c=cr.to_degrees(this.body.GetAngularVelocity());return cr.do_cmp(c,a,b)};a.prototype.CompareMass=function(a,b){if(!this.enabled)return!1;var c=this.body.GetMass()/0.02;return cr.do_cmp(c,a,b)};a.prototype.IsEnabled=function(){return this.enabled};n.cnds=new a;b.prototype.ApplyForce=function(a,b,c){if(this.enabled){var d=this.getInstImgPointX(c);
c=this.getInstImgPointY(c);this.body.ApplyForce(e.Get(a,b),e.Get(0.02*d,0.02*c))}};b.prototype.ApplyForceToward=function(a,b,c,d){if(this.enabled){var f=this.getInstImgPointX(d);d=this.getInstImgPointY(d);b=cr.angleTo(f,d,b,c);this.body.ApplyForce(e.Get(Math.cos(b)*a,Math.sin(b)*a),e.Get(0.02*f,0.02*d))}};b.prototype.ApplyForceAtAngle=function(a,b,c){if(this.enabled){b=cr.to_radians(b);var d=this.getInstImgPointX(c);c=this.getInstImgPointY(c);this.body.ApplyForce(e.Get(Math.cos(b)*a,Math.sin(b)*a),
e.Get(0.02*d,0.02*c))}};b.prototype.ApplyImpulse=function(a,b,c){if(this.enabled){var d=this.getInstImgPointX(c);c=this.getInstImgPointY(c);this.body.ApplyImpulse(e.Get(a,b),e.Get(0.02*d,0.02*c));this.lastTickOverride=!1;this.lastKnownX=this.inst.x;this.lastKnownY=this.inst.y}};b.prototype.ApplyImpulseToward=function(a,b,c,d){if(this.enabled){var f=this.getInstImgPointX(d);d=this.getInstImgPointY(d);b=cr.angleTo(f,d,b,c);this.body.ApplyImpulse(e.Get(Math.cos(b)*a,Math.sin(b)*a),e.Get(0.02*f,0.02*
d));this.lastTickOverride=!1;this.lastKnownX=this.inst.x;this.lastKnownY=this.inst.y}};b.prototype.ApplyImpulseAtAngle=function(a,b,c){if(this.enabled){b=cr.to_radians(b);var d=this.getInstImgPointX(c);c=this.getInstImgPointY(c);this.body.ApplyImpulse(e.Get(Math.cos(b)*a,Math.sin(b)*a),e.Get(0.02*d,0.02*c));this.lastTickOverride=!1;this.lastKnownX=this.inst.x;this.lastKnownY=this.inst.y}};b.prototype.ApplyTorque=function(a){this.enabled&&this.body.ApplyTorque(cr.to_radians(a))};b.prototype.ApplyTorqueToAngle=
function(a,b){this.enabled&&(a=cr.to_radians(a),b=cr.to_radians(b),cr.angleClockwise(this.inst.angle,b)?this.body.ApplyTorque(-a):this.body.ApplyTorque(a))};b.prototype.ApplyTorqueToPosition=function(a,b,c){this.enabled&&(a=cr.to_radians(a),b=cr.angleTo(this.inst.x,this.inst.y,b,c),cr.angleClockwise(this.inst.angle,b)?this.body.ApplyTorque(-a):this.body.ApplyTorque(a))};b.prototype.SetAngularVelocity=function(a){this.enabled&&(this.body.SetAngularVelocity(cr.to_radians(a)),this.body.SetAwake(!0))};
b.prototype.CreateDistanceJoint=function(a,b,c,d,e){if(b&&this.enabled&&(b=b.getFirstPicked(this.inst))&&b!=this.inst&&b.extra.box2dbody)this.myCreatedJoints.push({type:0,params:[a,b.uid,c,d,e]}),this.doCreateDistanceJoint(a,b.uid,c,d,e)};q.doCreateDistanceJoint=function(a,b,c,d,f){if(this.enabled&&(b=this.runtime.getObjectByUID(b))&&b!=this.inst&&b.extra.box2dbody){b.extra.box2dbody.c2userdata.joiningMe.add(this.inst);var g=this.getInstImgPointX(a);a=this.getInstImgPointY(a);var k;b.getImagePoint?
(k=b.getImagePoint(c,!0),c=b.getImagePoint(c,!1)):(k=b.x,c=b.y);var l=g-k,m=a-c,n=new h;n.Initialize(this.body,b.extra.box2dbody,e.Get(0.02*g,0.02*a),e.Get(0.02*k,0.02*c));n.length=0.02*Math.sqrt(l*l+m*m);n.dampingRatio=d;n.frequencyHz=f;this.myJoints.push(this.world.CreateJoint(n))}};b.prototype.CreateRevoluteJoint=function(a,b){if(b&&this.enabled){var c=b.getFirstPicked(this.inst);c&&c!=this.inst&&c.extra.box2dbody&&(this.myCreatedJoints.push({type:1,params:[a,c.uid]}),this.doCreateRevoluteJoint(a,
c.uid))}};q.doCreateRevoluteJoint=function(a,b){if(this.enabled){var c=this.runtime.getObjectByUID(b);if(c&&c!=this.inst&&c.extra.box2dbody){c.extra.box2dbody.c2userdata.joiningMe.add(this.inst);var d=this.getInstImgPointX(a),f=this.getInstImgPointY(a),g=new m;g.Initialize(this.body,c.extra.box2dbody,e.Get(0.02*d,0.02*f));this.myJoints.push(this.world.CreateJoint(g))}}};b.prototype.CreateLimitedRevoluteJoint=function(a,b,c,d){if(b&&this.enabled&&(b=b.getFirstPicked(this.inst))&&b!=this.inst&&b.extra.box2dbody)this.myCreatedJoints.push({type:2,
params:[a,b.uid,c,d]}),this.doCreateLimitedRevoluteJoint(a,b.uid,c,d)};q.doCreateLimitedRevoluteJoint=function(a,b,c,d){if(this.enabled&&(b=this.runtime.getObjectByUID(b))&&b!=this.inst&&b.extra.box2dbody){b.extra.box2dbody.c2userdata.joiningMe.add(this.inst);var f=this.getInstImgPointX(a);a=this.getInstImgPointY(a);var g=new m;g.Initialize(this.body,b.extra.box2dbody,e.Get(0.02*f,0.02*a));g.enableLimit=!0;g.lowerAngle=cr.to_radians(c);g.upperAngle=cr.to_radians(d);this.myJoints.push(this.world.CreateJoint(g))}};
b.prototype.SetWorldGravity=function(a){if(a!==this.behavior.worldG){this.world.SetGravity(e.Get(0,a));this.behavior.worldG=a;var b,c=this.behavior.my_instances.valuesRef();a=0;for(b=c.length;a<b;a++)c[a].extra.box2dbody&&c[a].extra.box2dbody.SetAwake(!0)}};b.prototype.SetSteppingMode=function(a){this.behavior.steppingMode=a};b.prototype.SetIterations=function(a,b){1>a&&(a=1);1>b&&(b=1);this.behavior.velocityIterations=a;this.behavior.positionIterations=b};b.prototype.SetVelocity=function(a,b){this.enabled&&
(this.body.SetLinearVelocity(e.Get(0.02*a,0.02*b)),this.body.SetAwake(!0),this.lastTickOverride=!1,this.lastKnownX=this.inst.x,this.lastKnownY=this.inst.y)};b.prototype.SetDensity=function(a){this.enabled&&this.density!==a&&(this.density=a,this.recreateBody=!0)};b.prototype.SetFriction=function(a){this.enabled&&this.friction!==a&&(this.friction=a,this.recreateBody=!0)};b.prototype.SetElasticity=function(a){this.enabled&&this.restitution!==a&&(this.restitution=a,this.recreateBody=!0)};b.prototype.SetLinearDamping=
function(a){this.enabled&&this.linearDamping!==a&&(this.linearDamping=a,this.body.SetLinearDamping(a))};b.prototype.SetAngularDamping=function(a){this.enabled&&this.angularDamping!==a&&(this.angularDamping=a,this.body.SetAngularDamping(a))};b.prototype.SetImmovable=function(a){this.enabled&&this.immovable!==(0!==a)&&(this.immovable=0!==a,this.body.SetType(this.immovable?0:2),this.body.SetAwake(!0))};b.prototype.EnableCollisions=function(a,b){if(a&&this.enabled){var d,e;if(a.is_family){d=0;for(e=a.members.length;d<
e;d++)c(this.inst.type,a.members[d],0!==b)}else c(this.inst.type,a,0!==b);this.behavior.allCollisionsEnabled=!1}};b.prototype.SetPreventRotate=function(a){this.enabled&&this.preventRotation!==(0!==a)&&(this.preventRotation=0!==a,this.body.SetFixedRotation(this.preventRotation),this.body.m_torque=0,this.body.SetAngularVelocity(0),this.body.SetAwake(!0))};b.prototype.SetBullet=function(a){this.enabled&&this.bullet!==(0!==a)&&(this.bullet=0!==a,this.body.SetBullet(this.bullet),this.body.SetAwake(!0))};
b.prototype.RemoveJoints=function(){this.enabled&&(this.destroyMyJoints(),this.myCreatedJoints.length=0,this.joiningMe.clear())};b.prototype.SetEnabled=function(a){this.enabled&&0===a?(this.destroyBody(),this.enabled=!1):!this.enabled&&1===a&&(this.enabled=!0,this.createBody())};n.acts=new b;d.prototype.VelocityX=function(a){a.set_float(this.enabled?this.body.GetLinearVelocity().x/0.02:0)};d.prototype.VelocityY=function(a){a.set_float(this.enabled?this.body.GetLinearVelocity().y/0.02:0)};d.prototype.AngularVelocity=
function(a){a.set_float(this.enabled?cr.to_degrees(this.body.GetAngularVelocity()):0)};d.prototype.Mass=function(a){a.set_float(this.enabled?this.body.GetMass()/0.02:0)};d.prototype.CenterOfMassX=function(a){a.set_float(this.enabled?(this.body.GetPosition().x+this.body.GetLocalCenter().x)/0.02:0)};d.prototype.CenterOfMassY=function(a){a.set_float(this.enabled?(this.body.GetPosition().y+this.body.GetLocalCenter().y)/0.02:0)};d.prototype.Density=function(a){a.set_float(this.enabled?this.density:0)};
d.prototype.Friction=function(a){a.set_float(this.enabled?this.friction:0)};d.prototype.Elasticity=function(a){a.set_float(this.enabled?this.restitution:0)};d.prototype.LinearDamping=function(a){a.set_float(this.enabled?this.linearDamping:0)};d.prototype.AngularDamping=function(a){a.set_float(this.enabled?this.angularDamping:0)};n.exps=new d})();cr.behaviors.Pin=function(a){this.runtime=a};
(function(){function a(){}function b(){}function c(){}var d=cr.behaviors.Pin.prototype;d.Type=function(a,b){this.behavior=a;this.objtype=b;this.runtime=a.runtime};d.Type.prototype.onCreate=function(){};d.Instance=function(a,b){this.type=a;this.behavior=a.behavior;this.inst=b;this.runtime=a.runtime};var e=d.Instance.prototype;e.onCreate=function(){this.pinObject=null;this.pinObjectUid=-1;this.mode=this.lastKnownAngle=this.theirStartAngle=this.myStartAngle=this.pinDist=this.pinAngle=0;var a=this;this.recycled||
(this.myDestroyCallback=function(b){a.onInstanceDestroyed(b)});this.runtime.addDestroyCallback(this.myDestroyCallback)};e.saveToJSON=function(){return{uid:this.pinObject?this.pinObject.uid:-1,pa:this.pinAngle,pd:this.pinDist,msa:this.myStartAngle,tsa:this.theirStartAngle,lka:this.lastKnownAngle,m:this.mode}};e.loadFromJSON=function(a){this.pinObjectUid=a.uid;this.pinAngle=a.pa;this.pinDist=a.pd;this.myStartAngle=a.msa;this.theirStartAngle=a.tsa;this.lastKnownAngle=a.lka;this.mode=a.m};e.afterLoad=
function(){this.pinObject=-1===this.pinObjectUid?null:this.runtime.getObjectByUID(this.pinObjectUid);this.pinObjectUid=-1};e.onInstanceDestroyed=function(a){this.pinObject==a&&(this.pinObject=null)};e.onDestroy=function(){this.pinObject=null;this.runtime.removeDestroyCallback(this.myDestroyCallback)};e.tick=function(){};e.tick2=function(){if(this.pinObject){this.lastKnownAngle!==this.inst.angle&&(this.myStartAngle=cr.clamp_angle(this.myStartAngle+(this.inst.angle-this.lastKnownAngle)));var a=this.inst.x,
b=this.inst.y;if(3===this.mode||4===this.mode){var c=cr.distanceTo(this.inst.x,this.inst.y,this.pinObject.x,this.pinObject.y);if(c>this.pinDist||4===this.mode&&c<this.pinDist)b=cr.angleTo(this.pinObject.x,this.pinObject.y,this.inst.x,this.inst.y),a=this.pinObject.x+Math.cos(b)*this.pinDist,b=this.pinObject.y+Math.sin(b)*this.pinDist}else a=this.pinObject.x+Math.cos(this.pinObject.angle+this.pinAngle)*this.pinDist,b=this.pinObject.y+Math.sin(this.pinObject.angle+this.pinAngle)*this.pinDist;this.lastKnownAngle=
c=cr.clamp_angle(this.myStartAngle+(this.pinObject.angle-this.theirStartAngle));if((0===this.mode||1===this.mode||3===this.mode||4===this.mode)&&(this.inst.x!==a||this.inst.y!==b))this.inst.x=a,this.inst.y=b,this.inst.set_bbox_changed();if((0===this.mode||2===this.mode)&&this.inst.angle!==c)this.inst.angle=c,this.inst.set_bbox_changed()}};a.prototype.IsPinned=function(){return!!this.pinObject};d.cnds=new a;b.prototype.Pin=function(a,b){if(a){var c=a.getFirstPicked(this.inst);c&&(this.pinObject=c,
this.pinAngle=cr.angleTo(c.x,c.y,this.inst.x,this.inst.y)-c.angle,this.pinDist=cr.distanceTo(c.x,c.y,this.inst.x,this.inst.y),this.lastKnownAngle=this.myStartAngle=this.inst.angle,this.theirStartAngle=c.angle,this.mode=b)}};b.prototype.Unpin=function(){this.pinObject=null};d.acts=new b;c.prototype.PinnedUID=function(a){a.set_int(this.pinObject?this.pinObject.uid:-1)};d.exps=new c})();
cr.getProjectModel=function(){return[null,null,[[cr.plugins_.CJSAds,!0,!1,!1,!1,!1,!1,!1,!1,!1],[cr.plugins_.MagiCam,!0,!1,!1,!1,!1,!1,!1,!1,!1],[cr.plugins_.Mouse,!0,!1,!1,!1,!1,!1,!1,!1,!1],[cr.plugins_.Sprite,!1,!0,!0,!0,!0,!0,!0,!0,!1],[cr.plugins_.Text,!1,!0,!0,!0,!0,!0,!0,!0,!1],[cr.plugins_.TiledBg,!1,!0,!0,!0,!0,!0,!0,!0,!0],[cr.plugins_.Touch,!0,!1,!1,!1,!1,!1,!1,!1,!1],[cr.plugins_.win8,!0,!1,!1,!1,!1,!1,!1,!1,!1]],[["t0",cr.plugins_.Sprite,!1,[9816883905120594],1,0,null,[["Default",5,!1,
1,0,!1,6251837593672656,[["bbred_feet-sheet0.png",5996,0,0,100,100,1,0.5,0.5,[],[-0.35514,-0.350877,-0.004673,-0.5,0.341121,-0.350877,0.490654,0,0.350467,0.359649,-0.004673,0.5,-0.331776,0.342105,-0.481308,0],0]]]],[["Physics",cr.behaviors.Physics,356451810449049]],!1,!1,0xff2c0c2896c19,[]],["t1",cr.plugins_.Touch,!1,[],0,0,null,null,[],!1,!1,4704716961057398,[],[1]],["t2",cr.plugins_.Sprite,!1,[6073007353803292],2,0,null,[["Default",5,!1,1,0,!1,8956288237305852,[["bola-sheet0.png",3168,0,0,40,40,
1,0.5,0.5,[],[-0.252475,-0.252475,0,-0.356436,0.252475,-0.252475,0.361386,0,0.257426,0.257426,0,0.371287,-0.252475,0.252475,-0.356436,0],0]]]],[["Physics",cr.behaviors.Physics,0xf1136067e9980],["Pin",cr.behaviors.Pin,5237189368237962]],!1,!1,0x6e4e42ddad47a,[]],["t3",cr.plugins_.Sprite,!1,[],1,0,null,[["Default",5,!1,1,0,!1,0x6736e4acb744e,[["bolabolagreen-sheet0.png",7003,0,0,75,75,1,0.506667,0.506667,[],[-0.358402,-0.358402,-0.00824365,-0.506667,0.345068,-0.358402,0.493333,-0.00824365,0.345068,
0.345068,-0.00824365,0.493333,-0.358402,0.345068,-0.506667,-0.00824365],0]]]],[["Pin",cr.behaviors.Pin,0x9084ff5fe9fe]],!1,!1,8720319122684742,[]],["t4",cr.plugins_.Sprite,!1,[],1,0,null,[["Default",5,!1,1,0,!1,0xbc7c5453a2399,[["bbgreen_tshirt-sheet0.png",7809,0,0,70,70,1,0.5,0.471429,[],[-0.35833,-0.310471,-0.00753701,-0.453933,0.336098,-0.299974,0.450642,0.0324394,0.303882,0.33686,-0.00753701,0.462827,-0.326115,0.347357,-0.483614,0.0324394],0]]]],[["Pin",cr.behaviors.Pin,5961143490220467]],!1,
!1,5766637595366857,[]],["t5",cr.plugins_.Sprite,!1,[],1,0,null,[["risada",7,!1,1,0,!1,828205453458831,[["bbgreen_cabeca-sheet0.png",38129,1,1,144,144,1,0.5,0.506944,[],[-0.305556,-0.305555,0,-0.4375,0.305556,-0.305555,0.4375,-4.17233E-7,0.3125,0.3125,0,0.4375,-0.298611,0.298612,-0.430556,-4.17233E-7],0],["bbgreen_cabeca-sheet0.png",38129,146,1,144,144,1,0.5,0.506944,[],[-0.305556,-0.305555,0,-0.4375,0.305556,-0.305555,0.4375,-4.17233E-7,0.3125,0.3125,0,0.4375,-0.298611,0.298612,-0.430556,-4.17233E-7],
0],["bbgreen_cabeca-sheet0.png",38129,291,1,144,144,1,0.5,0.506944,[],[-0.305556,-0.305555,0,-0.4375,0.305556,-0.305555,0.4375,-4.17233E-7,0.3125,0.3125,0,0.4375,-0.298611,0.298612,-0.430556,-4.17233E-7],0],["bbgreen_cabeca-sheet0.png",38129,1,146,144,144,1,0.5,0.506944,[],[-0.305556,-0.305555,0,-0.4375,0.305556,-0.305555,0.4375,-4.17233E-7,0.3125,0.3125,0,0.4375,-0.298611,0.298612,-0.430556,-4.17233E-7],0]]]],[["Pin",cr.behaviors.Pin,5029879444790727]],!1,!1,603868194727147,[]],["t6",cr.plugins_.Sprite,
!1,[7393597438332646],1,0,null,[["Default",5,!1,1,0,!1,8683793547428679,[["bbgreen_feet-sheet0.png",5533,0,0,100,100,1,0.5,0.5,[],[-0.349642,-0.352804,-0.00119299,-0.5,0.340095,-0.343458,0.488067,0,0.347255,0.350467,-0.00119299,0.5,-0.340095,0.343458,-0.488067,0],0]]]],[["Physics",cr.behaviors.Physics,0x5475ba65d0688]],!1,!1,7662640226141122,[]],["t7",cr.plugins_.MagiCam,!1,[],0,0,null,null,[],!1,!1,7600530578897351,[],[]],["t8",cr.plugins_.Mouse,!1,[],0,0,null,null,[],!1,!1,686131878791257,[],[]],
["t9",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,7947583117825777,[["goalred-sheet0.png",156,0,0,256,256,1,0.996094,0.476563,[],[],1]]]],[],!1,!1,8039377186105165,[]],["t10",cr.plugins_.Sprite,!1,[],1,0,null,[["Default",5,!1,1,0,!1,8204428201823983,[["traves-sheet0.png",156,0,0,256,256,1,0.5,0.5,[],[],4]]]],[["Physics",cr.behaviors.Physics,8792935877594223]],!1,!1,8395089427354455,[]],["t11",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,8045395934708718,[["traves-sheet0.png",
156,0,0,256,256,1,0.5,0.5,[],[],4]]]],[],!1,!1,6017777457181217,[]],["t12",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,0x7a3bb61f4f148,[["goalgreen-sheet0.png",156,0,0,256,256,1,-0.00390625,0.484375,[],[],1]]]],[],!1,!1,8098106201868784,[]],["t13",cr.plugins_.Sprite,!1,[],1,0,null,[["Default",5,!1,1,0,!1,8187293867295795,[["sprite3-sheet0.png",24605,0,0,256,256,1,0.5,0.5,[],[-0.025026,-0.402549,-8.72999E-4,-0.258224,0.123289,-0.080592,0.286997,-0.027344,0.413988,0.00555098,0.417096,
0.465461,-0.4375,0.449219,-0.458531,-0.410156],0]]]],[["Physics",cr.behaviors.Physics,7581948427456586]],!1,!1,784485810982857,[]],["t14",cr.plugins_.TiledBg,!1,[],1,0,["tiledbackground2.png",1600,0],null,[["Physics",cr.behaviors.Physics,499167981827981]],!1,!1,6918591010656855,[]],["t15",cr.plugins_.Sprite,!1,[],1,0,null,[["risada",5,!1,1,0,!1,9714502299664424,[["bbred-sheet0.png",21212,1,1,74,74,1,0.5,0.5,[],[-0.349449,-0.335723,-0.00588199,-0.488095,0.341544,-0.33963,0.472794,0.015904,0.318382,
0.351903,-0.00588199,0.480833,-0.330147,0.351903,-0.480698,0.015904],0],["bbred-sheet0.png",21212,76,1,74,74,1,0.5,0.5,[],[-0.349449,-0.335723,-0.00588199,-0.488095,0.341544,-0.33963,0.472794,0.015904,0.318382,0.351903,-0.00588199,0.480833,-0.330147,0.351903,-0.480698,0.015904],0],["bbred-sheet0.png",21212,151,1,74,74,1,0.5,0.5,[],[-0.349449,-0.335723,-0.00588199,-0.488095,0.341544,-0.33963,0.472794,0.015904,0.318382,0.351903,-0.00588199,0.480833,-0.330147,0.351903,-0.480698,0.015904],0],["bbred-sheet0.png",
21212,1,76,74,74,1,0.5,0.5,[],[-0.349449,-0.335723,-0.00588199,-0.488095,0.341544,-0.33963,0.472794,0.015904,0.318382,0.351903,-0.00588199,0.480833,-0.330147,0.351903,-0.480698,0.015904],0]]]],[["Pin",cr.behaviors.Pin,0xa4a10f31a550d]],!1,!1,0xd5cd5ed7793f,[]],["t16",cr.plugins_.TiledBg,!1,[],0,0,["tiledbackground3.png",43789,1],null,[],!1,!1,0xfa6b34d03d2d,[]],["t17",cr.plugins_.TiledBg,!1,[],0,0,["linhacentral.png",92,4],null,[],!1,!1,0x8947c610bab18,[]],["t18",cr.plugins_.Sprite,!1,[],0,0,null,
[["Default",5,!1,1,0,!1,0x774869cd47d59,[["area-sheet0.png",1700,0,0,256,167,1,0.5,0.502994,[],[-0.375,-0.311377,0,-0.479042,0.375,-0.311377,0.484375,-0.005988,0.484375,0.473054,0,-0.275449,-0.480469,0.467066,-0.480469,-0.005988],0]]]],[],!1,!1,5732788968107162,[]],["t19",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,0x5a185f74f59c8,[["circulocentral-sheet0.png",5778,0,0,256,256,1,0.5,0.5,[],[-0.300781,-0.300781,0,-0.425781,0.300781,-0.300781,0.433594,0,0.308594,0.308594,0,0.4375,-0.304687,
0.304688,-0.429688,0],0]]]],[],!1,!1,5596677585445503,[]],["t20",cr.plugins_.Text,!1,[],0,0,null,null,[],!1,!1,7916221701654337,[]],["t21",cr.plugins_.Text,!1,[],0,0,null,null,[],!1,!1,5321675057128528,[]],["t22",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,506009820183932,[["sprite-sheet0.png",2583,0,0,32,32,1,0.5,0.53125,[],[-0.356574,-0.37125,-0.00199199,-0.52725,0.356574,-0.37525,0.492032,-0.01125,0.332669,0.33275,-0.00199199,0.46475,-0.336653,0.33275,-0.492032,-0.01125],0]]]],[],
!1,!1,4552263191912445,[]],["t23",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,7098732509675493,[["sprite2-sheet0.png",2327,0,0,32,34,1,0.5,0.5,[],[-0.355596,-0.346429,-0.00180501,-0.492857,0.344765,-0.335714,0.460289,0.00357097,0.312274,0.314286,-0.00180501,0.442857,-0.323105,0.325,-0.48195,0.00357097],0]]]],[],!1,!1,7610375339588324,[]],["t24",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,9902257019548948,[["sprite4-sheet0.png",107527,0,0,515,395,1,0.500971,0.501266,[],
[-0.299029,-0.237975,-0.00194189,-0.501266,0.283495,-0.220253,0.413592,-0.00253183,0.231068,0.149367,-0.00194189,0.301266,-0.405825,0.374683,-0.440777,-0.00253183],0]]]],[],!1,!1,0x8dd57adc1049b,[]],["t25",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,4822279779553662,[["sprite5-sheet0.png",101586,0,0,515,390,1,0.500971,0.5,[],[-0.299029,-0.233333,-0.00194189,-0.5,0.283495,-0.215385,0.363107,0,0.409709,0.382051,-0.00194189,0.425641,-0.421359,0.394872],0]]]],[],!1,!1,0xbb4f230904072,[]],
["t26",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,871714945929647,[["sprite6-sheet0.png",1387,0,0,42,64,1,0.5,0.5,[],[],1]]]],[],!1,!1,7600578015953442,[]],["t27",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,8523281986787549,[["playmobeasy-sheet0.png",6945,0,0,100,60,1,0.5,0.5,[],[-0.394737,-0.318182,0,-0.481818,0.410526,-0.345455,0.478947,0,0.384211,0.3,0,0.4,-0.373684,0.281818,-0.452632,0],0]]]],[],!1,!1,505129204832583,[]],["t28",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",
5,!1,1,0,!1,8898176789934281,[["sprite8-sheet0.png",19214,0,0,459,119,1,0.501089,0.504202,[],[-0.433551,-0.243698,-0.00217834,-0.268908,0.424837,-0.218488,0.442266,-0.00840372,0.416122,0.17647,-0.43573,0.243697,-0.459695,-0.00840372],0]]]],[],!1,!1,4688390444811772,[]],["t29",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,6938750391694749,[["sprite9-sheet0.png",932703,0,0,1200,683,1,0.5,0.500732,[],[],1]]]],[],!1,!1,857800481332911,[]],["t30",cr.plugins_.Sprite,!1,[],1,0,null,[["Default",
5,!1,1,0,!1,0xabd9f6c4cdfe7,[["finger-sheet0.png",156,0,0,256,256,1,0.5,0.5,[],[],1]]]],[["DragDrop",cr.behaviors.DragnDrop,0xd9bd18797e37a]],!1,!1,6812705782505404,[]],["t31",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,4939220448945338,[["sprite10-sheet0.png",1441,0,0,30,30,1,0.5,0.5,[],[-0.5,-0.5,0,-0.5,0.5,-0.5,0.5,0,0.5,0.5,0,0.5,-0.5,0.5,-0.5,0],0]]]],[],!1,!1,8113586605400796,[]],["t32",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,5860817408424346,[["playmobpro-sheet0.png",
6666,0,0,100,60,1,0.5,0.5,[],[-0.394737,-0.318182,0,-0.481818,0.410526,-0.345455,0.478947,0,0.384211,0.3,0,0.4,-0.373684,0.281818,-0.452632,0],0]]]],[],!1,!1,5645635241857369,[]],["t33",cr.plugins_.Sprite,!1,[],0,0,null,[["Default",5,!1,1,0,!1,0x8e5847abbd25d,[["playdesktop-sheet0.png",7056,0,0,100,60,1,0.5,0.5,[],[-0.394737,-0.318182,0,-0.481818,0.410526,-0.345455,0.478947,0,0.384211,0.3,0,0.4,-0.373684,0.281818,-0.452632,0],0]]]],[],!1,!1,8998658780215521,[]],["t34",cr.plugins_.Sprite,!1,[],0,0,
null,[["Default",5,!1,1,0,!1,8470011064888388,[["sprite13-sheet0.png",45972,0,0,656,106,1,0.5,0.5,[],[-0.452744,-0.207547,0,-0.433962,0.471037,-0.320755,0.484756,0,0.477134,0.358491,0,0.320755,-0.487805,0.424528],0]]]],[],!1,!1,0xdd1aecad3b0d5,[]],["t35",cr.plugins_.win8,!1,[],0,0,null,null,[],!1,!1,9789878635825848,[],[1,1,1,1]],["t36",cr.plugins_.CJSAds,!1,[],0,0,null,null,[],!1,!1,0xe873e80a8077d,[],[1,0,1]]],[],[["alemar games",1050,600,!1,"sheet alemargames",0xd6cef6fd96fa1,[["Layer 0",0,9061670476033876,
!0,[0,0,0],!1,1,1,1,!1,1,0,0,[[[508.801,281.495,0,513.601,82.9904,0,0,1,0.5,0.5,0,0,[]],34,46,[],[],[0,"Default",0,1]]],[]]],[],[]],["abertura",1050,600,!1,"Event sheet 2",5328820928110454,[["Layer 0",0,8853354608222283,!0,[255,255,255],!1,1,1,1,!1,1,0,0,[[[523,296.941,0,1060,603,0,0,1,0.5,0.500732,0,0,[]],29,42,[],[],[0,"Default",0,1]],[[463,221,0,100,60,0,0,1,0.5,0.5,0,0,[]],27,44,[],[],[0,"Default",0,1]],[[659,-55,0,30,30,0,0,1,0.5,0.5,0,0,[]],31,40,[],[],[0,"Default",0,1]],[[585,220,0,100,60,
0,0,1,0.5,0.5,0,0,[]],32,41,[],[],[0,"Default",0,1]],[[521,221,0,100,60,0,0,1,0.5,0.5,0,0,[]],33,45,[],[],[0,"Default",0,1]]],[]]],[],[]],["Layout 1",1050,600,!1,"Event sheet 1",0x4ab6c0187a899,[["Layer 0",0,24193975725636,!0,[255,255,255],!1,1,1,1,!1,1,0,0,[[[-36,643,0,688,1150,0,-1.5708,1,0,0,0,0,[]],16,5,[],[],[0,0]],[[957,305,0,341.5,169,0,-1.5708,1,0.5,0.502994,0,0,[]],18,35,[],[],[0,"Default",0,1]],[[91,304.5,0,341.5,169,0,1.5708,1,0.5,0.502994,0,0,[]],18,12,[],[],[0,"Default",0,1]],[[542,300,
0,256,256,0,0,1,0.5,0.5,0,0,[]],19,36,[],[],[0,"Default",0,1]],[[541,-40,0,7,680,0,0,1,0,0,0,0,[]],17,33,[],[],[0,0]],[[611,16,0,98,100,0,0,1,0,0,0,0,[]],21,37,[],[],["3",0,"bold 48pt Arial Narrow","rgb(255,255,255)",0,0,0,0,0]],[[416,17,0,99,96,0,0,1,0,0,0,0,[]],20,34,[],[],["7",0,"bold 48pt Arial Narrow","rgb(255,255,255)",0,0,0,0,0]],[[393,57,0,32,32,0,0,1,0.5,0.53125,0,0,[]],22,38,[],[],[0,"Default",0,1]],[[589,56,0,32,34,0,0,1,0.5,0.5,0,0,[]],23,39,[],[],[0,"Default",0,1]],[[9.09766,299,0,17,
92,0,0,1,0.996094,0.476563,0,0,[]],9,15,[],[],[0,"Default",0,1]],[[1038,298,0,18,94,0,0,1,-0.00390625,0.484375,0,0,[]],12,16,[],[],[0,"Default",0,1]],[[544.5,297,0,40,40,0,0,1,0.5,0.5,0,0,[]],2,2,[[0]],[[0,0,0,5,0.5,0.5,0,0.01,0,1],[]],[0,"Default",0,1]],[[715,834,0,100,100,0,0,1,0.5,0.5,0,0,[]],6,11,[[0]],[[0,0,0,1,0.5,0.2,0,0.01,0,1]],[0,"Default",0,1]],[[715,834,0,75,75,0,0,1,0.506667,0.506667,0,0,[]],3,8,[],[[]],[0,"Default",0,1]],[[717,834,0,39.2669,40.2164,0,0,1,0.5,0.506944,0,0,[]],5,10,[],
[[]],[0,"Default",0,0]],[[716,833,0,70,70,0,0,1,0.5,0.471429,0,0,[]],4,9,[],[[]],[0,"Default",0,0]],[[161,813,0,100,100,0,0,1,0.5,0.5,0,0,[]],0,23,[[0]],[[0,0,0,1,1,0.2,0,0.01,0,1]],[0,"Default",0,1]],[[356,293,0,100,100,0,0,1,0.5,0.5,0,0,[]],0,0,[[0]],[[0,0,0,1,1,0.2,0,0.01,0,1]],[0,"Default",0,1]],[[293,123,0,100,100,0,0,1,0.5,0.5,0,0,[]],0,3,[[0]],[[0,0,0,1,1,0.2,0,0.01,0,1]],[0,"Default",0,1]],[[328,475,0,100,100,0,0,1,0.5,0.5,0,0,[]],0,32,[[0]],[[0,0,0,1,1,0.2,0,0.01,0,1]],[0,"Default",0,1]],
[[161,815,0,74,74,0,0,1,0.5,0.5,0,0,[]],15,30,[],[[]],[0,"Default",0,1]],[[16.5,344.037,0,32.5,5.50002,0,0,1,0.5,0.5,0,0,[]],10,17,[],[[1,0,0,1,0.5,0.2,0,0.01,0,1]],[0,"Default",0,1]],[[14.75,255.787,0,32,5.50002,0,0,1,0.5,0.5,0,0,[]],10,18,[],[[1,0,0,1,0.5,0.2,0,0.01,0,1]],[0,"Default",0,1]],[[1032.82,253.787,0,32,5.50002,0,0,1,0.5,0.5,0,0,[]],10,19,[],[[1,0,0,1,0.5,0.2,0,0.01,0,1]],[0,"Default",0,1]],[[1020,476,0,131,65,0,-1.57074,1,0,0,0,0,[]],14,31,[],[[1,0,0,1,0.5,0.2,0,0.01,0,1]],[0,0]],[[1034.32,
343.787,0,32,5.50002,0,0,1,0.5,0.5,0,0,[]],10,20,[],[[1,0,0,1,0.5,0.2,0,0.01,0,1]],[0,"Default",0,1]],[[31,349,0,129,66,0,1.57079,1,0,0,0,0,[]],14,7,[],[[1,0,0,1,0.5,0.2,0,0.01,0,1]],[0,0]],[[1021,251,0,131,66,0,-1.57078,1,0,0,0,0,[]],14,27,[],[[1,0,0,1,0.5,0.2,0,0.01,0,1]],[0,0]],[[95,574,0,836,64,0,0,1,0,0,0,0,[]],14,29,[],[[1,0,0,1,0.5,0.2,0,0.01,0,1]],[0,0]],[[929,26,0,840,64,0,3.14159,1,0,0,0,0,[]],14,4,[],[[1,0,0,1,0.5,0.2,0,0.01,0,1]],[0,0]],[[28,121,0,131,66,0,1.55672,1,0,0,0,0,[]],14,6,[],
[[1,0,0,1,0.5,0.2,0,0.01,0,1]],[0,0]],[[29,585,0,226,256,0,0,1,0.5,0.5,0,0,[]],13,28,[],[[1,0,0,1,0.5,0.6,0,0.01,0,1]],[0,"Default",0,1]],[[1025,578,0,-246,256,0,0,1,0.5,0.5,0,0,[]],13,24,[],[[1,0,0,1,0.5,0.6,0,0.01,0,1]],[0,"Default",0,1]],[[32,16,0,226,-256,0,0,1,0.5,0.5,0,0,[]],13,25,[],[[1,0,0,1,0.5,0.6,0,0.01,0,1]],[0,"Default",0,1]],[[1020,17,0,-246,-256,0,0,1,0.5,0.5,0,0,[]],13,26,[],[[1,0,0,1,0.5,0.6,0,0.01,0,1]],[0,"Default",0,1]],[[1020.5,299.5,0,6,93,0,0,1,0.5,0.5,0,0,[]],11,22,[],[],[0,
"Default",0,1]],[[29.25,299.787,0,6,93,0,0,1,0.5,0.5,0,0,[]],11,21,[],[],[0,"Default",0,1]],[[501,756,0,25,28,0,0,1,0.5,0.5,0,0,[]],30,43,[],[[0,1]],[0,"Default",0,0]]],[]]],[],[]]],[["Event sheet 1",[[1,"touchobject",0,0,!1,!1,0xf348976784560],[1,"placar_red",0,0,!1,!1,0xb71206d35cae2],[1,"placar_green",0,0,!1,!1,521800154432711],[1,"player_green",0,1,!1,!1,6737244911434044],[1,"player_red",0,0,!1,!1,5761049950738278],[1,"tempodeseg",0,0,!1,!1,0xbf2535c8bc5db],[0,[!0,"cria os discos"],!1,5403771887446437,
[[-1,cr.system_object.prototype.cnds.IsGroupActive,null,0,!1,!1,!1,5403771887446437,[[1,[2,"cria os discos"]]]]],[],[[0,null,!1,8715611853772374,[[-1,cr.system_object.prototype.cnds.OnLayoutStart,null,1,!1,!1,!1,8745212673096883]],[[-1,cr.system_object.prototype.acts.CreateObject,null,4766590489195522,[[4,6],[5,[0,0]],[0,[0,697]],[0,[0,297]]]],[-1,cr.system_object.prototype.acts.CreateObject,null,5530373291321362,[[4,6],[5,[0,0]],[0,[0,723]],[0,[0,107]]]],[-1,cr.system_object.prototype.acts.CreateObject,
null,9144258332348224,[[4,6],[5,[0,0]],[0,[0,739]],[0,[0,491]]]],[0,cr.behaviors.Physics.prototype.acts.SetWorldGravity,"Physics",0x42506e8ee4065,[[0,[0,0]]]],[2,cr.behaviors.Physics.prototype.acts.SetWorldGravity,"Physics",8399374292225189,[[0,[0,0]]]],[6,cr.behaviors.Physics.prototype.acts.SetWorldGravity,"Physics",7251186245646517,[[0,[0,0]]]]]],[0,null,!1,6092994509165194,[[6,cr.plugins_.Sprite.prototype.cnds.OnCreated,null,1,!1,!1,!1,0x9a7ff236015d9]],[[5,cr.behaviors.Pin.prototype.acts.Pin,
"Pin",0xe2dbca080a4aa,[[4,6],[3,1]]],[4,cr.behaviors.Pin.prototype.acts.Pin,"Pin",6910767500499533,[[4,6],[3,1]]],[3,cr.behaviors.Pin.prototype.acts.Pin,"Pin",9931257004104238,[[4,6],[3,1]]],[3,cr.plugins_.Sprite.prototype.acts.ZMoveToObject,null,0x4157acf618741,[[3,1],[4,4]]],[4,cr.plugins_.Sprite.prototype.acts.ZMoveToObject,null,0x8bac8a57d8963,[[3,0],[4,5]]]]],[0,null,!1,6271533553711332,[[0,cr.plugins_.Sprite.prototype.cnds.OnCreated,null,1,!1,!1,!1,9717872014287364]],[[15,cr.behaviors.Pin.prototype.acts.Pin,
"Pin",7810966008631017,[[4,0],[3,1]]]]]]],[0,[!0,"score gol "],!1,4553382140987094,[[-1,cr.system_object.prototype.cnds.IsGroupActive,null,0,!1,!1,!1,4553382140987094,[[1,[2,"score gol "]]]]],[],[[0,null,!1,9299109291088328,[[-1,cr.system_object.prototype.cnds.EveryTick,null,0,!1,!1,!1,5277522155284359]],[[21,cr.plugins_.Text.prototype.acts.SetText,null,4587497917947808,[[7,[10,[2,""],[23,"placar_green"]]]]],[20,cr.plugins_.Text.prototype.acts.SetText,null,0x3b7f4e8579465,[[7,[10,[2,""],[23,"placar_red"]]]]]]],
[0,null,!1,5742758239647457,[[2,cr.plugins_.Sprite.prototype.cnds.OnCollision,null,0,!1,!1,!0,7704014962340078,[[4,6]]]],[[2,cr.plugins_.Sprite.prototype.acts.SetInstanceVar,null,926602743617619,[[10,0],[7,[0,0]]]]]],[0,null,!1,0xe00613b184928,[[2,cr.plugins_.Sprite.prototype.cnds.OnCollision,null,0,!1,!1,!0,5401593775418032,[[4,0]]]],[[2,cr.plugins_.Sprite.prototype.acts.SetInstanceVar,null,0x7170c834b1c4e,[[10,0],[7,[0,1]]]]]],[0,null,!1,0xe8e5f2f5d7952,[[2,cr.plugins_.Sprite.prototype.cnds.CompareInstanceVar,
null,0,!1,!1,!1,8072525068325739,[[10,0],[8,0],[7,[0,0]]]],[9,cr.plugins_.Sprite.prototype.cnds.IsOverlapping,null,0,!1,!1,!1,5033840629408295,[[4,2]]]],[[-1,cr.system_object.prototype.acts.AddVar,null,6876711494146596,[[11,"placar_green"],[7,[0,2]]]],[2,cr.plugins_.Sprite.prototype.acts.SetPos,null,8566764114230978,[[0,[0,544]],[0,[0,297]]]],[0,cr.behaviors.Physics.prototype.acts.ApplyImpulseToward,"Physics",0x63f933f02f9e0,[[0,[0,2]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.X,!1,null]],[0,[20,
2,cr.plugins_.Sprite.prototype.exps.Y,!1,null]],[7,[0,0]]]]]],[0,null,!1,9787257451503404,[[2,cr.plugins_.Sprite.prototype.cnds.CompareInstanceVar,null,0,!1,!1,!1,0xd918d1936481,[[10,0],[8,0],[7,[0,0]]]],[12,cr.plugins_.Sprite.prototype.cnds.IsOverlapping,null,0,!1,!1,!1,7409658705475597,[[4,2]]]],[[-1,cr.system_object.prototype.acts.AddVar,null,0x9c7f3aa173203,[[11,"placar_green"],[7,[0,1]]]],[2,cr.plugins_.Sprite.prototype.acts.SetPos,null,8998464793599458,[[0,[0,544]],[0,[0,297]]]],[0,cr.behaviors.Physics.prototype.acts.ApplyImpulseToward,
"Physics",0xd1a35de0ed075,[[0,[0,2]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.X,!1,null]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.Y,!1,null]],[7,[0,0]]]]]],[0,null,!1,287565384036128,[[2,cr.plugins_.Sprite.prototype.cnds.CompareInstanceVar,null,0,!1,!1,!1,0xb8d7933eab647,[[10,0],[8,0],[7,[0,1]]]],[9,cr.plugins_.Sprite.prototype.cnds.IsOverlapping,null,0,!1,!1,!1,8014363348783775,[[4,2]]]],[[-1,cr.system_object.prototype.acts.AddVar,null,8662447912167158,[[11,"placar_red"],[7,[0,1]]]],[2,cr.plugins_.Sprite.prototype.acts.SetPos,
null,7655061489993559,[[0,[0,544]],[0,[0,297]]]],[0,cr.behaviors.Physics.prototype.acts.ApplyImpulseToward,"Physics",6021957340121854,[[0,[0,2]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.X,!1,null]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.Y,!1,null]],[7,[0,0]]]]]],[0,null,!1,0x716181895fd4e,[[2,cr.plugins_.Sprite.prototype.cnds.CompareInstanceVar,null,0,!1,!1,!1,5008263679724306,[[10,0],[8,0],[7,[0,1]]]],[12,cr.plugins_.Sprite.prototype.cnds.IsOverlapping,null,0,!1,!1,!1,7790700847867603,[[4,
2]]]],[[-1,cr.system_object.prototype.acts.AddVar,null,5507575197221816,[[11,"placar_red"],[7,[0,2]]]],[2,cr.plugins_.Sprite.prototype.acts.SetPos,null,0xfdd38f413b3be,[[0,[0,544]],[0,[0,297]]]],[0,cr.behaviors.Physics.prototype.acts.ApplyImpulseToward,"Physics",0x5b773c5ee289c,[[0,[0,2]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.X,!1,null]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.Y,!1,null]],[7,[0,0]]]]]]]],[0,[!0,"controle DESKTOP"],!1,0xe4cbb7dd79505,[[-1,cr.system_object.prototype.cnds.IsGroupActive,
null,0,!1,!1,!1,0xe4cbb7dd79505,[[1,[2,"controle DESKTOP"]]]]],[],[[0,null,!1,0xbf07a74d8e300,[[8,cr.plugins_.Mouse.prototype.cnds.OnObjectClicked,null,1,!1,!1,!1,4881697074256518,[[3,0],[3,0],[4,6]]],[3,cr.plugins_.Sprite.prototype.cnds.PickDistance,null,0,!1,!1,!0,0x4acb9a9b234d7,[[3,0],[0,[20,8,cr.plugins_.Mouse.prototype.exps.X,!1,null]],[0,[20,8,cr.plugins_.Mouse.prototype.exps.Y,!1,null]]]],[-1,cr.system_object.prototype.cnds.CompareVar,null,0,!1,!1,!1,7719606139625191,[[11,"player_green"],
[8,0],[7,[0,1]]]],[-1,cr.system_object.prototype.cnds.CompareVar,null,0,!1,!1,!1,4552253898890685,[[11,"player_red"],[8,0],[7,[0,0]]]]],[[6,cr.behaviors.Physics.prototype.acts.ApplyImpulseToward,"Physics",9382941967692306,[[0,[0,10]],[0,[20,8,cr.plugins_.Mouse.prototype.exps.X,!1,null]],[0,[20,8,cr.plugins_.Mouse.prototype.exps.Y,!1,null]],[7,[0,0]]]],[6,cr.behaviors.Physics.prototype.acts.ApplyTorqueToAngle,"Physics",0x9fea897cad9eb,[[0,[0,5E4]],[0,[0,0]]]],[6,cr.behaviors.Physics.prototype.acts.ApplyImpulseToward,
"Physics",0xd97e9670388c2,[[0,[0,50]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.X,!1,null]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.Y,!1,null]],[7,[0,0]]]],[-1,cr.system_object.prototype.acts.SetVar,null,8344895438807336,[[11,"player_green"],[7,[0,0]]]],[-1,cr.system_object.prototype.acts.SetVar,null,0x55a51da7b11de,[[11,"player_red"],[7,[0,1]]]]]],[0,null,!1,0xdd850e013865d,[[8,cr.plugins_.Mouse.prototype.cnds.OnObjectClicked,null,1,!1,!1,!1,9240068487121940,[[3,0],[3,0],[4,6]]],[-1,cr.system_object.prototype.cnds.CompareVar,
null,0,!1,!1,!1,7741145062190797,[[11,"player_green"],[8,0],[7,[0,0]]]],[-1,cr.system_object.prototype.cnds.CompareVar,null,0,!1,!1,!1,6819175486064525,[[11,"player_red"],[8,0],[7,[0,1]]]],[-1,cr.system_object.prototype.cnds.PickRandom,null,0,!1,!1,!1,5795296497817643,[[4,0]]]],[[-1,cr.system_object.prototype.acts.Wait,null,0x9da3f8f07bb5,[[0,[1,0.3]]]],[0,cr.behaviors.Physics.prototype.acts.ApplyImpulseToward,"Physics",0x409557fb8ca65,[[0,[0,60]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.X,!1,null]],
[0,[20,2,cr.plugins_.Sprite.prototype.exps.Y,!1,null]],[7,[0,0]]]],[-1,cr.system_object.prototype.acts.SetVar,null,0xce0f390ebea57,[[11,"player_green"],[7,[0,1]]]],[-1,cr.system_object.prototype.acts.SetVar,null,7656267877184193,[[11,"player_red"],[7,[0,0]]]]]]]],[0,[!0,"controle EASY"],!1,0xc2bf75db65f5a,[[-1,cr.system_object.prototype.cnds.IsGroupActive,null,0,!1,!1,!1,0xc2bf75db65f5a,[[1,[2,"controle EASY"]]]]],[],[[0,null,!1,8765523119006308,[[1,cr.plugins_.Touch.prototype.cnds.IsInTouch,null,
0,!1,!1,!1,8829834276668238]],[]],[0,null,!1,7914493647337085,[[1,cr.plugins_.Touch.prototype.cnds.IsTouchingObject,null,0,!1,!1,!1,8928358717036835,[[4,6]]],[3,cr.plugins_.Sprite.prototype.cnds.PickDistance,null,0,!1,!1,!0,5069068346306523,[[3,0],[0,[20,1,cr.plugins_.Touch.prototype.exps.X,!1,null]],[0,[20,1,cr.plugins_.Touch.prototype.exps.Y,!1,null]]]],[-1,cr.system_object.prototype.cnds.CompareVar,null,0,!1,!1,!1,9129640797188472,[[11,"player_green"],[8,0],[7,[0,1]]]],[-1,cr.system_object.prototype.cnds.CompareVar,
null,0,!1,!1,!1,7261881909486562,[[11,"player_red"],[8,0],[7,[0,0]]]]],[[6,cr.plugins_.Sprite.prototype.acts.SetTowardPosition,null,0xa1ae909819968,[[0,[20,2,cr.plugins_.Sprite.prototype.exps.X,!1,null]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.Y,!1,null]]]],[6,cr.behaviors.Physics.prototype.acts.ApplyTorqueToAngle,"Physics",0x8e4b88b5b75ac,[[0,[0,5E4]],[0,[0,0]]]],[6,cr.behaviors.Physics.prototype.acts.ApplyImpulseToward,"Physics",4512986065036569,[[0,[0,50]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.X,
!1,null]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.Y,!1,null]],[7,[0,0]]]],[-1,cr.system_object.prototype.acts.SetVar,null,7774386049039575,[[11,"player_green"],[7,[0,0]]]],[-1,cr.system_object.prototype.acts.SetVar,null,0x9948193e65602,[[11,"player_red"],[7,[0,1]]]]]],[0,null,!1,7161964991468308,[[1,cr.plugins_.Touch.prototype.cnds.OnTouchObject,null,1,!1,!1,!1,0x66fa7b4543c63,[[4,0]]],[15,cr.plugins_.Sprite.prototype.cnds.PickDistance,null,0,!1,!1,!0,5044560253322335,[[3,0],[0,[20,1,cr.plugins_.Touch.prototype.exps.X,
!1,null]],[0,[20,1,cr.plugins_.Touch.prototype.exps.Y,!1,null]]]],[-1,cr.system_object.prototype.cnds.CompareVar,null,0,!1,!1,!1,0x7fcc99d25248d,[[11,"player_green"],[8,0],[7,[0,0]]]],[-1,cr.system_object.prototype.cnds.CompareVar,null,0,!1,!1,!1,8088992749529876,[[11,"player_red"],[8,0],[7,[0,1]]]]],[[0,cr.behaviors.Physics.prototype.acts.ApplyTorqueToAngle,"Physics",0xdf981d2a51523,[[0,[0,5E4]],[0,[0,0]]]],[0,cr.behaviors.Physics.prototype.acts.ApplyImpulseToward,"Physics",6637097479063187,[[0,
[0,50]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.X,!1,null]],[0,[20,2,cr.plugins_.Sprite.prototype.exps.Y,!1,null]],[7,[0,0]]]],[-1,cr.system_object.prototype.acts.SetVar,null,0x8fc83d71b4d51,[[11,"player_green"],[7,[0,1]]]],[-1,cr.system_object.prototype.acts.SetVar,null,62266602482125,[[11,"player_red"],[7,[0,0]]]]]]]],[0,[!0,"controle PRO"],!1,9778486617040512,[[-1,cr.system_object.prototype.cnds.IsGroupActive,null,0,!1,!1,!1,9778486617040512,[[1,[2,"controle PRO"]]]]],[],[[0,[!0,"greendisc"],
!1,4673019576209826,[[-1,cr.system_object.prototype.cnds.IsGroupActive,null,0,!1,!1,!1,4673019576209826,[[1,[2,"greendisc"]]]]],[],[[0,null,!1,0x9f7b5db5daae8,[[1,cr.plugins_.Touch.prototype.cnds.IsTouchingObject,null,0,!1,!1,!1,0x77e5e3031bf3f,[[4,6]]]],[[6,cr.plugins_.Sprite.prototype.acts.SetPos,null,6673077695692429,[[0,[20,1,cr.plugins_.Touch.prototype.exps.X,!1,null]],[0,[20,1,cr.plugins_.Touch.prototype.exps.Y,!1,null]]]],[5,cr.plugins_.Sprite.prototype.acts.SetAnim,null,8037122026445194,[[1,
[2,"risada"]],[3,1]]],[6,cr.plugins_.Sprite.prototype.acts.SetInstanceVar,null,8877068600564911,[[10,0],[7,[0,1]]]]]]]],[0,[!0,"greendiscdispara"],!1,0x6eee5ec6db023,[[-1,cr.system_object.prototype.cnds.IsGroupActive,null,0,!1,!1,!1,0x6eee5ec6db023,[[1,[2,"greendiscdispara"]]]]],[],[[0,null,!1,7559466008585638,[[1,cr.plugins_.Touch.prototype.cnds.OnTouchEnd,null,1,!1,!1,!1,6901018176878672],[-1,cr.system_object.prototype.cnds.CompareVar,null,0,!1,!1,!1,0x9955ff5aefc59,[[11,"tempodeseg"],[8,2],[7,
[0,3]]]],[6,cr.plugins_.Sprite.prototype.cnds.CompareInstanceVar,null,0,!1,!1,!1,7955188530658416,[[10,0],[8,0],[7,[0,1]]]],[1,cr.plugins_.Touch.prototype.cnds.CompareTouchSpeed,null,0,!1,!1,!1,8389377518438891,[[0,[0,0]],[8,4],[0,[0,2]]]]],[[6,cr.behaviors.Physics.prototype.acts.ApplyTorqueToAngle,"Physics",8327639623169509,[[0,[0,5E4]],[0,[0,0]]]],[6,cr.behaviors.Physics.prototype.acts.ApplyImpulseToward,"Physics",4580891335918028,[[0,[0,5]],[0,[20,1,cr.plugins_.Touch.prototype.exps.X,!1,null]],
[0,[20,1,cr.plugins_.Touch.prototype.exps.Y,!1,null]],[7,[0,0]]]],[6,cr.plugins_.Sprite.prototype.acts.SetInstanceVar,null,0xe2d62863448a9,[[10,0],[7,[0,0]]]],[-1,cr.system_object.prototype.acts.SetVar,null,0x95b87f897ea,[[11,"player_green"],[7,[0,0]]]],[-1,cr.system_object.prototype.acts.SetVar,null,520020135583051,[[11,"player_red"],[7,[0,1]]]]]]]],[0,[!0,"reddisc"],!1,8143049459449611,[[-1,cr.system_object.prototype.cnds.IsGroupActive,null,0,!1,!1,!1,8143049459449611,[[1,[2,"reddisc"]]]]],[],[[0,
null,!1,0xbf625bc18aee0,[[1,cr.plugins_.Touch.prototype.cnds.IsTouchingObject,null,0,!1,!1,!1,443257936725134,[[4,0]]]],[[0,cr.plugins_.Sprite.prototype.acts.SetPos,null,0x3c528d5762517,[[0,[20,1,cr.plugins_.Touch.prototype.exps.X,!1,null]],[0,[20,1,cr.plugins_.Touch.prototype.exps.Y,!1,null]]]],[15,cr.plugins_.Sprite.prototype.acts.SetAnim,null,7802558997819677,[[1,[2,"risada"]],[3,1]]],[0,cr.plugins_.Sprite.prototype.acts.SetInstanceVar,null,6218060648682686,[[10,0],[7,[0,1]]]]]]]],[0,[!0,"reddiscdispara"],
!1,4831872637293407,[[-1,cr.system_object.prototype.cnds.IsGroupActive,null,0,!1,!1,!1,4831872637293407,[[1,[2,"reddiscdispara"]]]]],[],[[0,null,!1,0xaa99996d3ecfa,[[1,cr.plugins_.Touch.prototype.cnds.OnTouchEnd,null,1,!1,!1,!1,5775775408155725],[-1,cr.system_object.prototype.cnds.CompareVar,null,0,!1,!1,!1,9360520839281308,[[11,"tempodeseg"],[8,2],[7,[0,3]]]],[0,cr.plugins_.Sprite.prototype.cnds.CompareInstanceVar,null,0,!1,!1,!1,0xbd8d8e1d8c0a8,[[10,0],[8,0],[7,[0,1]]]],[1,cr.plugins_.Touch.prototype.cnds.CompareTouchSpeed,
null,0,!1,!1,!1,5081943692564155,[[0,[0,0]],[8,4],[0,[0,2]]]]],[[0,cr.behaviors.Physics.prototype.acts.ApplyTorqueToAngle,"Physics",5986893132235007,[[0,[0,5E4]],[0,[0,0]]]],[0,cr.behaviors.Physics.prototype.acts.ApplyImpulseToward,"Physics",0x90f2d7a21c8b,[[0,[0,5]],[0,[20,1,cr.plugins_.Touch.prototype.exps.X,!1,null]],[0,[20,1,cr.plugins_.Touch.prototype.exps.Y,!1,null]],[7,[0,0]]]],[0,cr.plugins_.Sprite.prototype.acts.SetInstanceVar,null,0x3b41f03502e25,[[10,0],[7,[0,0]]]],[-1,cr.system_object.prototype.acts.SetVar,
null,0x98771dd86b1fa,[[11,"player_green"],[7,[0,1]]]],[-1,cr.system_object.prototype.acts.SetVar,null,5131848837810286,[[11,"player_red"],[7,[0,0]]]]]]]]]],[0,null,!1,5788455215522456,[[1,cr.plugins_.Touch.prototype.cnds.IsInTouch,null,0,!1,!1,!1,5170713633244246],[-1,cr.system_object.prototype.cnds.EveryTick,null,0,!1,!1,!1,0xbbf2fbe65a6de]],[[-1,cr.system_object.prototype.acts.AddVar,null,810176589918858,[[11,"tempodeseg"],[7,[0,1]]]]]],[0,null,!1,7742839055641483,[[-1,cr.system_object.prototype.cnds.CompareVar,
null,0,!1,!1,!1,9032535002439408,[[11,"tempodeseg"],[8,0],[7,[0,3]]]]],[[-1,cr.system_object.prototype.acts.SetVar,null,8981203607469298,[[11,"tempodeseg"],[7,[0,0]]]]]],[0,null,!1,84507680065751,[[5,cr.plugins_.Sprite.prototype.cnds.OnAnimFinished,null,1,!1,!1,!1,6852614300823502,[[1,[2,"risada"]]]]],[[-1,cr.system_object.prototype.acts.SetGroupActive,null,0xde7edea3a2efc,[[1,[2,"greendisc"]],[3,0]]],[6,cr.plugins_.Sprite.prototype.acts.SetInstanceVar,null,8706536226830993,[[10,0],[7,[0,0]]]],[-1,
cr.system_object.prototype.acts.SetGroupActive,null,5200242304406692,[[1,[2,"reddisc"]],[3,1]]]]],[0,null,!1,6457720975750396,[[15,cr.plugins_.Sprite.prototype.cnds.OnAnimFinished,null,1,!1,!1,!1,0xb27b3565ac212,[[1,[2,"risada"]]]]],[[-1,cr.system_object.prototype.acts.SetGroupActive,null,4858809431730801,[[1,[2,"reddisc"]],[3,0]]],[0,cr.plugins_.Sprite.prototype.acts.SetInstanceVar,null,784686243652962,[[10,0],[7,[0,0]]]],[-1,cr.system_object.prototype.acts.SetGroupActive,null,0xb10a0f7dbea31,[[1,
[2,"greendisc"]],[3,1]]]]],[0,null,!1,0x3cd80dbd96ede,[[-1,cr.system_object.prototype.cnds.OnLayoutStart,null,1,!1,!1,!1,0x5f37fc1c1c283]],[[5,cr.plugins_.Sprite.prototype.acts.StopAnim,null,0x948cb1cb9b3fa],[15,cr.plugins_.Sprite.prototype.acts.StopAnim,null,8819363285740351]]],[0,[!0,"escolha de controles"],!1,4631093469158204,[[-1,cr.system_object.prototype.cnds.IsGroupActive,null,0,!1,!1,!1,4631093469158204,[[1,[2,"escolha de controles"]]]]],[],[[0,null,!1,9483500377829486,[[-1,cr.system_object.prototype.cnds.OnLayoutStart,
null,1,!1,!1,!1,0x8f65782f2d4fc],[-1,cr.system_object.prototype.cnds.CompareVar,null,0,!1,!1,!1,8848703807065996,[[11,"playdesktop"],[8,0],[7,[0,1]]]]],[[-1,cr.system_object.prototype.acts.SetGroupActive,null,0xbb01925fedb4,[[1,[2,"controle DESKTOP"]],[3,1]]],[-1,cr.system_object.prototype.acts.SetGroupActive,null,7950151730586281,[[1,[2,"controle EASY"]],[3,0]]],[-1,cr.system_object.prototype.acts.SetGroupActive,null,7297757565433656,[[1,[2,"controle PRO"]],[3,0]]]]],[0,null,!1,6981143627002967,
[[-1,cr.system_object.prototype.cnds.OnLayoutStart,null,1,!1,!1,!1,0x9a7891f0654a1],[-1,cr.system_object.prototype.cnds.CompareVar,null,0,!1,!1,!1,6877810979974682,[[11,"playpro"],[8,0],[7,[0,1]]]]],[[-1,cr.system_object.prototype.acts.SetGroupActive,null,4891087572831406,[[1,[2,"controle PRO"]],[3,1]]],[-1,cr.system_object.prototype.acts.SetGroupActive,null,0xfa9c069cb9a1,[[1,[2,"controle DESKTOP"]],[3,0]]],[-1,cr.system_object.prototype.acts.SetGroupActive,null,614891477009925,[[1,[2,"controle EASY"]],
[3,0]]]]],[0,null,!1,611682241694112,[[-1,cr.system_object.prototype.cnds.OnLayoutStart,null,1,!1,!1,!1,9984267678998812],[-1,cr.system_object.prototype.cnds.CompareVar,null,0,!1,!1,!1,9379340370347552,[[11,"playeasy"],[8,0],[7,[0,1]]]]],[[-1,cr.system_object.prototype.acts.SetGroupActive,null,0xf8f15a6e58a4c,[[1,[2,"controle EASY"]],[3,1]]],[-1,cr.system_object.prototype.acts.SetGroupActive,null,5697075372435602,[[1,[2,"controle PRO"]],[3,0]]],[-1,cr.system_object.prototype.acts.SetGroupActive,null,
6340274823313066,[[1,[2,"controle DESKTOP"]],[3,0]]]]]]]]],["Event sheet 2",[[1,"playpro",0,0,!1,!1,5701865023687374],[1,"playeasy",0,0,!1,!1,0x6be72d5505c66],[1,"playdesktop",0,0,!1,!1,7184784821548394],[1,"playmobile",0,0,!1,!1,0x805d6f713e02f],[0,null,!1,5775784725383624,[[-1,cr.system_object.prototype.cnds.IsMobile,null,0,!1,!0,!1,0xfd1e957f62585]],[[27,cr.plugins_.Sprite.prototype.acts.Destroy,null,0x53c3912deee56],[32,cr.plugins_.Sprite.prototype.acts.Destroy,null,0x41fcb1e89fa91]]],[0,null,
!1,0x7121af5985eb,[[-1,cr.system_object.prototype.cnds.IsMobile,null,0,!1,!1,!1,0xb033b0b50e7ea]],[[33,cr.plugins_.Sprite.prototype.acts.Destroy,null,5560164794792321]]],[0,null,!0,0xe35927f3ff6a8,[[1,cr.plugins_.Touch.prototype.cnds.OnTouchObject,null,1,!1,!1,!1,9675067995259304,[[4,27]]],[1,cr.plugins_.Touch.prototype.cnds.OnTouchObject,null,1,!1,!1,!1,8581862303152923,[[4,32]]],[1,cr.plugins_.Touch.prototype.cnds.OnTouchObject,null,1,!1,!1,!1,8708095952363304,[[4,33]]]],[[-1,cr.system_object.prototype.acts.GoToLayout,
null,0x44908159cfb2d,[[6,"Layout 1"]]]]],[0,null,!1,9206959766186464,[[1,cr.plugins_.Touch.prototype.cnds.OnTouchObject,null,1,!1,!1,!1,6023466963268577,[[4,27]]]],[[-1,cr.system_object.prototype.acts.SetVar,null,7023145463167621,[[11,"playeasy"],[7,[0,1]]]]]],[0,null,!1,0xa5deeac683e45,[[1,cr.plugins_.Touch.prototype.cnds.OnTouchObject,null,1,!1,!1,!1,6658100427921627,[[4,32]]]],[[-1,cr.system_object.prototype.acts.SetVar,null,5459998835111487,[[11,"playpro"],[7,[0,1]]]]]],[0,null,!1,0x465a35fb54cf2,
[[1,cr.plugins_.Touch.prototype.cnds.OnTouchObject,null,1,!1,!1,!1,8572180937252619,[[4,33]]]],[[-1,cr.system_object.prototype.acts.SetVar,null,7186302554429984,[[11,"playdesktop"],[7,[0,1]]]]]]]],["sheet alemargames",[[0,null,!1,5513275554623707,[[-1,cr.system_object.prototype.cnds.OnLayoutStart,null,1,!1,!1,!1,8459455492729346]],[[-1,cr.system_object.prototype.acts.Wait,null,474565539757281,[[0,[0,4]]]],[-1,cr.system_object.prototype.acts.GoToLayout,null,0x80bbbb98558a,[[6,"abertura"]]]]]]]],"",
!1,1050,600,3,!0,!0,!0,"1.0.0.0",2,!1,1,!0,49,!1,[[0,15],[3,4,5,6]]]};

createCocoonJSRuntime();

})();
