/*!
* © by Sitsanlis Ilias
* This notice shall be included in all copies or substantial portions of the Software.
* Creative Commons 4.0/CC BY - NC - SA 4.0. 
*/

helpText.text = "Εφαρμογή με την οποία μπορούμε να μελετήσουμε τις μεταβολές φάσεων μιας ποσότητας 1kg νερού που αρχικά βρισκόταν σε μορφή πάγου θερμοκρασίας -30°C."
var canvas,stage,self,controlBoxContainer,PI=Math.PI,toDeg=180/PI,toRad=PI/180,X0=360,Y0=215,t=0,dt=1/160,dtInitial=dt,dtSlow=dt,factor=.5,playMovie=!1,framePlay=!1,xScale=50,yScale=-xScale,FScale=2,vScale=2,vectorScale=1,m=0,lMax=200,θCi=-30.0001,θCf=120,θ=-30,m0=1,c0=2100,m1=1,c1=4200,λ=5e3,LT=334e3,LB=2256e3,valuesText=new createjs.Text("","12px Trebuchet MS");valuesText.set({x:wcInitial/2,y:hcInitial-iH-25,textAlign:"center"});for(var box=addBox(!0),baseFront=baseFrontShape(),thermometer=box.getChildAt(3),array=[],i=0;i<=13;i++)array.push([40.9*i,0,40.93,125]);var data={images:["waterPhases/images/fire.png"],frames:array,animations:{run:[0,13],speed:.05}},scales=[],spriteSheet=new createjs.SpriteSheet(data),animation=new createjs.Sprite(spriteSheet);animation.set({x:X0-9,y:Y0+90,visible:!1,scaleX:.6,scaleY:.5});var animationPlay=!1,animationsContainer=new createjs.Container;animationsContainer.visible=!1;for(var animationScale=.2,solidArray=[],i=0;i<=6;i++)solidArray.push([352*i+1,0,349,348]);var solidData={images:["waterPhases/images/solid.png"],frames:solidArray,animations:{run:[0,6]},framerate:30},solidSheet=new createjs.SpriteSheet(solidData),solidAnimation=new createjs.Sprite(solidSheet);solidAnimation.set({x:X0+70,y:Y0+20,visible:!1,scaleX:animationScale,scaleY:animationScale});for(var solidAnimationPlay=!1,liquidArray=[],i=0;i<=13;i++)liquidArray.push([340*i,0,340,341]);var liquidData={images:["waterPhases/images/liquid.png"],frames:liquidArray,animations:{run:[0,13]},framerate:10},liquidSheet=new createjs.SpriteSheet(liquidData),liquidAnimation=new createjs.Sprite(liquidSheet);liquidAnimation.set({x:X0-138,y:Y0+20,visible:!1,scaleX:animationScale,scaleY:animationScale});for(var liquidAnimationPlay=!1,gasArray=[],i=0;i<=8;i++)gasArray.push([346*i,0,346,345]);var gasData={images:["waterPhases/images/gas.png"],frames:gasArray,animations:{run:[0,8]},framerate:30},gasSheet=new createjs.SpriteSheet(gasData),gasAnimation=new createjs.Sprite(gasSheet);gasAnimation.set({x:X0+70,y:Y0-100,visible:!1,scaleX:animationScale,scaleY:animationScale});var gasAnimationPlay=!1,stopFlag=!1,sec=1,bubbles=new createjs.Container,dQ=160*dt,Q=0,expContainer=new createjs.Container;function init(){stage=new createjs.Stage(document.getElementById("myCanvas")),createjs.Touch.isSupported()&&createjs.Touch.enable(stage),stage.enableMouseOver(),stage.enableDOMEvents(!0),canvas=document.getElementById("myCanvas"),self=stage,controlBoxContainer=new createjs.Container,self.addChild(controlBoxContainer);var a=new createjs.DOMElement("mainButtons");controlBoxContainer.addChild(a),controlBoxContainer.x=2.5,controlBoxContainer.y=2.5,stage.addChild(valuesText),expContainer.addChild(box),expContainer.addChild(baseFront),baseFront.set({x:X0,y:Y0+80,scaleY:-1,scaleX:.9}),expContainer.addChild(animation),expContainer.addChild(bubbles),bubbles.set({x:X0,y:Y0}),animationsContainer.addChild(solidAnimation),animationsContainer.addChild(liquidAnimation),animationsContainer.addChild(gasAnimation),expContainer.addChild(animationsContainer),stage.addChild(expContainer),graphContainer.addChild(xAxis),graphContainer.addChild(xAxisLabel),graphContainer.addChild(yAxis),graphContainer.addChild(yAxisLabel),graphContainer.addChild(graph),graphContainer.addChild(point),stage.addChild(graphContainer),createRegister("Φάσεις του Νερού"),handleComplete(),initialize(),createjs.Ticker.timingMode=createjs.Ticker.RAF,createjs.Ticker.addEventListener("tick",tick),canvas.style.visibility="visible",document.getElementById("dialogVariables").style.visibility="visible"}function initialize(){box.set({x:X0,y:Y0,scale:1}),animation.gotoAndPlay(),solidAnimation.gotoAndPlay(),liquidAnimation.gotoAndPlay(),gasAnimation.gotoAndPlay(),drawAllAxis(),restart()}function restart(){sec=1,Q0=m0*c0*((m=Q=t=0)-(θ=θCi))/1e3,QT=LT*m0/1e3,Q0T=Q0+QT,Q1=m1*c1*100/1e3,Q0T1=Q0+QT+Q1,QB=LB*m0/1e3,Q0T1B=Q0+QT+Q1+QB,setMass(box,0);for(var a=box.getChildByName("iceContainer"),e=a.numChildren,i=0;i<=e-1;i++)a.getChildAt(i).scale=iceScales[i];$("#play").button("enable"),animation.visible=playMovie,positions()}function tick(a){playMovie&&(framePlay=framePlay&&(playMovie=!1),0<=t+dt&&t<=100&&(t+=dt,calculations(),positions(a)))}function calculations(){Q=160*t,119.4<(θ=findθ(Q))&&($("#play").trigger("click"),$("#play").button("disable"),bubbles.removeAllChildren())}function positions(a){setTemperature(thermometer,θ,θCi,θCf,lMax),valuesText.text+="\nt = "+(5*t).toFixed(1)+" min",100<=θ&&θ<119&&addBubble(),solidAnimation.visible=θ<=0,liquidAnimation.visible=0<=θ&&θ<=100,gasAnimation.visible=100<=θ&&θ<119,flagGraph&&drawGraph(t),stage.update(a)}flagGraph&&expContainer.set({x:-200,y:15,scale:.95});