var initialX=null;var initialY=null;var ball=document.getElementById("ball");var vertical_ball=document.getElementById("vertical_ball");var horizontal_ball=document.getElementById("horizontal_ball");var garden=document.getElementById("canvas");var maxX=(garden.clientWidth-ball.clientWidth)*1;var maxY=(garden.clientHeight-ball.clientHeight)*1;var top_middle=maxY/2;var left_middle=maxX/2;var difference_val_top=(maxY/2)*0.02;var difference_val_left=(maxX/2)*0.02;document.getElementById("vh").style.height=garden.clientHeight+"px";document.getElementById("hh").style.width=garden.clientWidth+"px";function handleOrientationEvent(a){var i=a.beta;var g=a.gamma;if(i>90){i=90}if(i<-90){i=-90}i+=90;g+=90;var h=(maxX*i/180);var b=(maxY*g/180);var c=1.2162*(78-b);var e=1.2*(77-h);var d=0.7086*(135-b);var f=0.7031*(133-h);if(screen.height==480){document.getElementById("horz").innerHTML="h : "+Number(c).toFixed(2)+"&deg;";document.getElementById("vert").innerHTML="v : "+Number(e).toFixed(2)+"&deg;"}else{document.getElementById("horz").innerHTML="h : "+Number(d).toFixed(2)+"&deg;";document.getElementById("vert").innerHTML="v : "+Number(f).toFixed(2)+"&deg;"}if(screen.height==480){if(areaCricle(h,b)<0.95){ball.style.top=h+"px";ball.style.left=b+"px";vertical_ball.style.top=h+"px"}}else{if(areaCricle(h,b)<0.854){ball.style.top=h+"px";ball.style.left=b+"px";vertical_ball.style.top=h+"px"}}horizontal_ball.style.left=b+"px";if(h>=(top_middle-difference_val_top)&&h<=(top_middle+difference_val_top)){document.getElementById("vertical_ball").getElementsByTagName("img")[0].src="images/water_bubble2.png"}else{document.getElementById("vertical_ball").getElementsByTagName("img")[0].src="images/water_bubble.png"}if(b>=(left_middle-difference_val_left)&&b<=(left_middle+difference_val_left)){document.getElementById("horizontal_ball").getElementsByTagName("img")[0].src="images/water_bubble2.png"}else{document.getElementById("horizontal_ball").getElementsByTagName("img")[0].src="images/water_bubble.png"}if((h>=(top_middle-difference_val_top)&&h<=(top_middle+difference_val_top))&&(b>=(left_middle-difference_val_left)&&b<=(left_middle+difference_val_left))){document.getElementById("ball").getElementsByTagName("img")[0].src="images/water_bubble2.png"}else{document.getElementById("ball").getElementsByTagName("img")[0].src="images/water_bubble.png"}}function isEventFired(){if(!initialX&&!initialY){var a=document.getElementById("warning");a.innerText="Warning: Cannot receive device orientation events, this browser is not supported.";a.style.display="inline-block"}}window.addEventListener("MozOrientation",handleOrientationEvent,true);window.addEventListener("deviceorientation",handleOrientationEvent,true);setTimeout(isEventFired,2000);function areaCricle(a,c){if(screen.height==480){var b=Math.pow((a-78),2)+Math.pow((c-77),2);return b/5625}else{var b=Math.pow((a-135),2)+Math.pow((c-133),2);return b/16129}};
