text: var Utilities;!function(Utilities){function shuffle(array){if(!Utilities.isArray(array))throw new Error("Utilities.shuffle() -> Invalid 'array' argument. Not an array.");for(var temporaryValue,randomIndex,currentIndex=array.length;0!==currentIndex;)randomIndex=Math.floor(Math.random()*currentIndex),currentIndex--,temporaryValue=array[currentIndex],array[currentIndex]=array[randomIndex],array[randomIndex]=temporaryValue;return array}function boxBoxCollision(oneX,oneY,oneWidth,oneHeight,twoX,twoY,twoWidth,twoHeight){return!(twoY>oneY+oneHeight||oneY>twoY+twoHeight||oneX>twoX+twoWidth||twoX>oneX+oneWidth)}function circleCircleCollision(x1,y1,radius1,x2,y2,radius2){var distX=x1-x2,distY=y1-y2;return Math.pow(distX,2)+Math.pow(distY,2)<=Math.pow(radius1+radius2,2)?!0:!1}function circlePointCollision(circleX,circleY,circleRadius,pointX,pointY){var distanceX=circleX-pointX,distanceY=circleY-pointY,squareDistance=distanceX*distanceX+distanceY*distanceY;return circleRadius*circleRadius>=squareDistance?!0:!1}function pointBoxCollision(pointX,pointY,boxX,boxY,boxWidth,boxHeight){return boxX>pointX||pointX>boxX+boxWidth||boxY>pointY||pointY>boxY+boxHeight?!1:!0}function getObject(key){if(!Utilities.isString(key))throw new Error("Utilities.getObject() -> Invalid 'key' argument. Not a string.");var value=localStorage.getItem(key);return value&&JSON.parse(value)}function saveObject(key,value){if(!Utilities.isString(key))throw new Error("Utilities.saveObject() -> Invalid 'key' argument. Not a string.");localStorage.setItem(key,JSON.stringify(value))}function isArray(element){return"[object Array]"===Object.prototype.toString.call(element)}function isBoolean(element){return element===!0||element===!1||"[object Boolean]"===Object.prototype.toString.call(element)}function isFunction(element){return"function"==typeof element&&"[object Function]"===Object.prototype.toString.call(element)}function isInteger(value){return Utilities.isNumber(value)&&value%1===0}function isNumber(element){return"number"==typeof element&&!isNaN(parseFloat(element))&&isFinite(element)}function isString(element){return"string"==typeof element||element instanceof String}function getRandomFloat(min,max){if(!Utilities.isNumber(min)||!Utilities.isNumber(max)||min>max)throw new Error("Utilities.getRandomFloat() -> Invalid arguments. Either 'min'/'max' are not numbers, or 'min' > 'max'.");return Math.random()*(max-min)+min}function getRandomInt(min,max){if(!Utilities.isInteger(min)||!Utilities.isInteger(max)||min>max)throw new Error("Utilities.getRandomInt() -> Invalid arguments. Either 'min'/'max' are not integers, or 'min > 'max'.");return Math.floor(Math.random()*(max-min+1))+min}function getSeveralRandomInts(min,max,howMany){if(!Utilities.isInteger(min)||!Utilities.isInteger(max)||!Utilities.isInteger(howMany)||min>max||howMany-1>max-min)throw new Error("Utilities.getSeveralRandomInts() -> Invalid arguments.");for(var numbers=[];numbers.length<howMany;){var randomNumber=Utilities.getRandomInt(min,max);numbers.indexOf(randomNumber)<0&&numbers.push(randomNumber)}return numbers}function numberOfDigits(theNumber){if(!Utilities.isNumber(theNumber))throw new Error("Utilities.numberOfDigits() -> Invalid 'theNumber' argument. Not a number.");0>theNumber&&(theNumber*=-1);var numberString=theNumber.toString().replace(".","");return numberString.length}function round(num,dec){if(!Utilities.isNumber(num)||!Utilities.isInteger(dec)||0>dec)throw new Error("Utilities.round() -> Invalid arguments.");return Math.round(num*Math.pow(10,dec))/Math.pow(10,dec)}function deepClone(obj){return JSON.parse(JSON.stringify(obj))}function createEnum(values,start){if(!Utilities.isArray(values))throw new Error("Utilities.createEnum() -> Invalid 'values' argument. Needs to be an array of strings.");Utilities.isNumber(start)||(start=0);for(var name,obj={},length=values.length,a=0;length>a;a++)name=values[a],obj[start]=name,obj[name]=start,start++;return obj}function inheritPrototype(derivedClass,baseClass){var f=function(){};f.prototype=baseClass.prototype;var prototype=new f;prototype.constructor=derivedClass,derivedClass.prototype=prototype}function timeToString(dateMilliseconds,totalUnits){if(void 0===totalUnits&&(totalUnits=2),!Utilities.isNumber(dateMilliseconds))throw new Error("Utilities.timeToString() -> Invalid 'dateMilliseconds' argument. Not a number.");Utilities.isNumber(totalUnits)||(totalUnits=2);for(var second=1e3,minute=60*second,hour=60*minute,day=24*hour,minutesLeft=0,hoursLeft=0,daysLeft=0,secondsLeft=0;dateMilliseconds>=day;)daysLeft++,dateMilliseconds-=day;for(;dateMilliseconds>=hour;)hoursLeft++,dateMilliseconds-=hour;for(;dateMilliseconds>=minute;)minutesLeft++,dateMilliseconds-=minute;secondsLeft=Utilities.round(dateMilliseconds/second,2);var i,theDate=[["day",daysLeft],["hour",hoursLeft],["minute",minutesLeft],["second",secondsLeft]],constructDate=function(dateTmp,numberOf){return 1!==numberOf&&(dateTmp+="s"),numberOf+" "+dateTmp},date="";for(i=0;i<theDate.length&&0!==totalUnits;i++)0!==theDate[i][1]&&(""!==date&&(date+=" "),date+=constructDate(theDate[i][0],theDate[i][1]),totalUnits--);return""===date&&(date="0 seconds"),date}function calculateAngle(aX,aY,bX,bY){if(!(Utilities.isNumber(aX)&&Utilities.isNumber(aY)&&Utilities.isNumber(bX)&&Utilities.isNumber(bY)))throw new Error("Utilities.calculateAngle() -> Invalid arguments. Needs to be a number.");var triangleOppositeSide=aY-bY,triangleAdjacentSide=bX-aX;return Math.atan2(triangleOppositeSide,triangleAdjacentSide)}function calculateDistance(aX,aY,bX,bY){if(!(Utilities.isNumber(aX)&&Utilities.isNumber(aY)&&Utilities.isNumber(bX)&&Utilities.isNumber(bY)))throw new Error("Utilities.calculateDistance() -> Invalid arguments. Needs to be a number.");var opposite=bY-aY,adjacent=bX-aX;return Math.sqrt(Math.pow(opposite,2)+Math.pow(adjacent,2))}function toDegrees(radians){if(!Utilities.isNumber(radians))throw new Error("Utilities.toDegrees() -> Invalid 'radians' argument. Not a number.");return 180*radians/Math.PI}function toRadians(degrees){if(!Utilities.isNumber(degrees))throw new Error("Utilities.toRadians() -> Invalid 'degrees' argument. Not a number.");return degrees*Math.PI/180}Utilities.shuffle=shuffle,Utilities.boxBoxCollision=boxBoxCollision,Utilities.circleCircleCollision=circleCircleCollision,Utilities.circlePointCollision=circlePointCollision,Utilities.pointBoxCollision=pointBoxCollision,Utilities.KEY_CODE={backspace:8,tab:9,enter:13,esc:27,space:32,end:35,home:36,leftArrow:37,upArrow:38,rightArrow:39,downArrow:40,del:46,0:48,1:49,2:50,3:51,4:52,5:53,6:54,7:55,8:56,9:57,a:65,b:66,c:67,d:68,e:69,f:70,g:71,h:72,i:73,j:74,k:75,l:76,m:77,n:78,o:79,p:80,q:81,r:82,s:83,t:84,u:85,v:86,w:87,x:88,y:89,z:90,f1:112,f2:113,f3:114,f4:115,f5:116,f6:117,f7:118,f8:119,f9:120,f10:121,f11:122,f12:123},Utilities.MOUSE_CODE={left:0,middle:1,right:2},Utilities.getObject=getObject,Utilities.saveObject=saveObject,Utilities.isArray=isArray,Utilities.isBoolean=isBoolean,Utilities.isFunction=isFunction,Utilities.isInteger=isInteger,Utilities.isNumber=isNumber,Utilities.isString=isString,Utilities.getRandomFloat=getRandomFloat,Utilities.getRandomInt=getRandomInt,Utilities.getSeveralRandomInts=getSeveralRandomInts,Utilities.numberOfDigits=numberOfDigits,Utilities.round=round,Utilities.deepClone=deepClone,Utilities.createEnum=createEnum,Utilities.inheritPrototype=inheritPrototype,Utilities.timeToString=timeToString;var Timeout=function(){function Timeout(){this.is_active=!1,this.id=-1}return Timeout.prototype.start=function(functionToCall,interval){if(!Utilities.isFunction(functionToCall)||!Utilities.isNumber(interval))throw new Error("Utilities.Timeout.start() -> Invalid arguments.");var _this=this;this.is_active&&this.clear(),this.is_active=!0,this.id=window.setTimeout(function(){_this.is_active=!1,functionToCall()},interval)},Timeout.prototype.clear=function(){window.clearTimeout(this.id),this.is_active=!1},Timeout}();Utilities.Timeout=Timeout;var Timer=function(){function Timer(htmlElement){if(!(htmlElement instanceof HTMLElement))throw new Error("Utilities.Timer() -> Invalid 'htmlElement' argument. Not an HTML element.");this.is_active=!1,this.start_value=0,this.end_value=null,this.end_callback=null,this.tick_callback=null,this.count_down=!1,this.time_count=0,this.interval_f=null,this.html_element=htmlElement,this.html_element.innerHTML=this.getTimeString()}return Timer.prototype.start=function(args){"undefined"==typeof args&&(args={}),Utilities.isNumber(args.startValue)||(args.startValue=0),Utilities.isNumber(args.endValue)||(args.endValue=null),Utilities.isFunction(args.endCallback)||(args.endCallback=null),Utilities.isFunction(args.tickCallback)||(args.tickCallback=null),args.countDown!==!0&&(args.countDown=!1),this.is_active&&this.stop(),this.count_down=args.countDown,this.time_count=args.startValue,this.start_value=args.startValue,this.end_value=args.endValue,this.end_callback=args.endCallback,this.tick_callback=args.tickCallback,this.html_element.innerHTML=this.getTimeString(),this.resume()},Timer.prototype.resume=function(){if(!this.is_active){var _this=this,interval=1e3;this.is_active=!0,this.interval_f=window.setInterval(function(){if(_this.count_down?_this.time_count-=interval:_this.time_count+=interval,null!==_this.end_value){var ended=!1;_this.count_down?_this.time_count<=_this.end_value&&(ended=!0):_this.time_count>=_this.end_value&&(ended=!0),ended&&(_this.stop(),null!==_this.end_callback&&_this.end_callback())}null!==_this.tick_callback&&_this.tick_callback(),_this.html_element.innerHTML=_this.getTimeString()},interval)}},Timer.prototype.stop=function(){this.interval_f&&(window.clearInterval(this.interval_f),this.interval_f=null),this.is_active=!1},Timer.prototype.reset=function(){this.stop(),this.time_count=this.start_value,this.html_element.innerHTML=this.getTimeString()},Timer.prototype.restart=function(){this.reset(),this.start({startValue:this.start_value,endValue:this.end_value,endCallback:this.end_callback,tickCallback:this.tick_callback,countDown:this.count_down})},Timer.prototype.add=function(time){this.time_count+=time},Timer.prototype.getTimeString=function(){return Utilities.timeToString(this.time_count)},Timer.prototype.getTimeSeconds=function(){return this.time_count/1e3},Timer.prototype.getTimeMilliseconds=function(){return this.time_count},Timer}();Utilities.Timer=Timer,Utilities.calculateAngle=calculateAngle,Utilities.calculateDistance=calculateDistance,Utilities.toDegrees=toDegrees,Utilities.toRadians=toRadians}(Utilities||(Utilities={}));