/*
** by Sitsanlis Ilias
*/

var wcInitial=720,hcInitial=9*wcInitial/16,iH=20,myMinLenField=180,sizeFixLen="151px",floatWidth=180,flagPos=window.innerWidth/window.innerHeight<1.8?"down":"right",dragFlag=!1;function fixDimCanvas(i,n){canvas.width=wcInitial*i*n,canvas.height=hcInitial*i*n,canvas.style.width=wcInitial*n+"px",canvas.style.height=hcInitial*n+"px",stage.scaleX=i*n,stage.scaleY=i*n,controlBoxContainer.scaleX=controlBoxContainer.scaleY=1/i,controlBoxContainer.x=2.5/i,controlBoxContainer.y=2.5/i,stage.update()}function resizeCanvas(){var i,n,t,e,a;$("#dialogVariables").dialog("isOpen")?"float"==flagPos?(i=window.innerWidth-4,n=window.innerHeight-7,t=window.devicePixelRatio||1,e=i/wcInitial,a=n/hcInitial,fixDimCanvas(t,Math.min(e,a)),dragFlag||$("#dialogVariables").dialog({position:{my:"right top",at:"right top",of:window}})):window.innerWidth/window.innerHeight<1.8?fixVariablesPosition(flagPos="down"):fixVariablesPosition(flagPos="right"):(i=window.innerWidth-4,n=window.innerHeight-7,t=window.devicePixelRatio||1,e=i/wcInitial,a=n/hcInitial,fixDimCanvas(t,Math.min(e,a)))}function fixVariablesPosition(i){var n,t;window.innerHeight;t="right"==i?(document.getElementById("left").classList.add("floatLeft"),$("#dialogVariables").prev(".ui-dialog-titlebar").hide(),n=window.innerWidth-myMinLenField-11,window.innerHeight-7):"down"==i?(document.getElementById("left").classList.remove("floatLeft"),$("#dialogVariables").prev(".ui-dialog-titlebar").hide(),n=window.innerWidth-4,$("#dialogVariables").dialog({width:n-5,height:"auto"}),o=$("#dialogVariables").height(),window.innerHeight-o-10.5):(document.getElementById("left").classList.remove("floatLeft"),$(".ui-dialog-titlebar").show(),n=window.innerWidth-4,window.innerHeight-7);var e=window.devicePixelRatio||1,a=n/wcInitial,o=t/hcInitial;fixDimCanvas(e,Math.min(a,o));var d,l,w,s,r,h,a=window.innerWidth-canvas.width/e,o=window.innerHeight-canvas.height/e;"right"==i?(d=a-11,l=canvas.height/e+4.8,w=window.innerHeight,r=s="right top",h=window,$(".widget fixLen").css("width",sizeFixLen)):"down"==i?(d=n-5,l="auto",w=200==t?o:"auto",s="center top-2px",r="center bottom",h=myCanvas,$(".widget fixLen").css("width","auto")):"float"==i&&(d=floatWidth,l="auto",w=window.innerHeight,r=s="right top",h=window,$(".widget fixLen").css("width","auto")),$("#dialogVariables").dialog({width:d,height:l,maxHeight:w,position:{my:s,at:r,of:h}})}function handleComplete(){window.addEventListener("resize",resizeCanvas),resizeCanvas()}screen.orientation.addEventListener("change",function(){resizeCanvas()});