/*
** by Sitsanlis Ilias
*/

helpText.text = "Εφαρμογή με την οποία μπορούμε να μελετήσουμε το Νόμο της θερμιδομετρίας. Μπορείς να επιλέξεις για κάθε δοχείο το υλικό και την ποσότητα του περιέχει και να διαβάσεις την θερμοκρασία που αποκτά το κάθε υλικό μετά την απορρόφηση ενός ποσού θερμότητας.";
var canvas,stage,self,controlBoxContainer,PI=Math.PI,toDeg=180/PI,toRad=PI/180,X0=wcInitial/2,Y0=(hcInitial-iH)/2,t=0,dt=1/60,dtInitial=dt,dtSlow=dt,factor=.5,playMovie=!1,framePlay=!1,xScale=50,yScale=-xScale,FScale=2,vScale=2,vectorScale=1,valuesText=new createjs.Text("","12px Trebuchet MS");valuesText.set({x:wcInitial/2,y:hcInitial-iH-25,textAlign:"center"});var text1=new createjs.Text("","12px Trebuchet MS");text1.set({textAlign:"center"});var text2=new createjs.Text("","12px Trebuchet MS");text2.set({textAlign:"center"});for(var liquid=[{name:"Νερό",c:4186,color:"#80c5de"},{name:"Λάδι",c:1970,color:"#FFCC00"},{name:"Οινόπνευμα",c:2400,color:"#6a9dfb"},{name:"Πετρέλαιο",c:2132,color:"#3a3a3a"},{name:"Υδράργυρος",c:140,color:"#9b9b9b"},{name:"Άμμος",c:840,color:"#FF9900"}],m1=1,m2=1,θ1i=20,θ1=θ1i,θ2i=20,θ2=θ2i,λ=5e3,c1=4186,c2=1970,name1="Νερό",name2="Λάδι",box1=addBox(color1),box2=addBox(color2),thermometer1=box1.getChildAt(3),thermometer2=box2.getChildAt(3),lab1=new createjs.Container,lab2=new createjs.Container,array=[],i=0;i<=13;i++)array.push([40.9*i,0,40.93,125]);var data={images:["calorimetryLab/images/fire2.png"],frames:array,animations:{run:[0,13],speed:.05}},spriteSheet=new createjs.SpriteSheet(data),animation1=new createjs.Sprite(spriteSheet);animation1.set({x:X0-12-150,y:Y0+90,visible:!1,scaleX:.6,scaleY:.5});var animation2=new createjs.Sprite(spriteSheet);animation2.set({x:X0-12+150,y:Y0+90,visible:!1,scaleX:.6,scaleY:.5});var emergencyFlag,animationPlay=!1,stopFlag=!1,hours=1,baseFront1=baseFrontShape(),baseFront2=baseFrontShape(),mvalue=1;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 e=new createjs.DOMElement("mainButtons");controlBoxContainer.addChild(e),controlBoxContainer.x=2.5,controlBoxContainer.y=2.5,lab1.addChild(box1),lab2.addChild(box2),stage.addChild(lab1),stage.addChild(lab2),lab1.addChild(animation1),lab2.addChild(animation2),lab1.addChild(baseFront1),lab2.addChild(baseFront2),baseFront1.set({x:X0-150,y:Y0+80,scaleY:-1,scaleX:.9}),baseFront2.set({x:X0+150,y:Y0+80,scaleY:-1,scaleX:.9}),stage.addChild(valuesText),createRegister("Ο Νόμος της Θερμιδομετρίας"),$("#dialogVariables").dialog("open"),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(){animation1.gotoAndPlay(),animation2.gotoAndPlay(),box1.set({x:X0-150,y:Y0,scale:1}),box2.set({x:X0+150,y:Y0,scale:1}),restart()}function restart(){$("#play").button("enable"),animation1.visible=playMovie,animation2.visible=playMovie,t=0,hours=1,θ1=θ1i,θ2=θ2i,setMass(box1,m1,color1,name1),setMass(box2,m2,color2,name2),positions()}function tick(e){playMovie&&(framePlay=framePlay&&(playMovie=!1),calculations(),positions())}function calculations(){t+=dt,round(t,2)==hours&&(hours++,stopFlag&&$("#play").trigger("click")),dθ1=λ*dt/(m1*c1),θ1+=dθ1,dθ2=λ*dt/(m2*c2),θ2+=dθ2,(emergencyFlag=2==mvalue?90<θ1||90<θ2:90<θ1)&&($("#play").trigger("click"),$("#play").button("disable"))}function positions(){setTemperature(thermometer1,θ1),setTemperature(thermometer2,θ2),valuesText.text="t = "+t.toFixed(1)+" min, Q = "+(λ*t).toFixed(1)+" kJ",stage.update()}