﻿
document.onmousemove=moveHandler;function moveHandler(evt){if(!evt){evt=window.event;}
animateEyes(evt.clientX,evt.clientY);}
function animateEyes(xPos,yPos){var leftEye=document.getElementById("left");leftEye.style.left=(document.body.clientWidth-960)/2+"px";leftEye.style.top=31+"px";var rightEyeball=document.getElementById("reb").style;var leftEyeball=document.getElementById("leb").style;var circle1x=leftEye.offsetLeft+29;var circle1y=leftEye.offsetTop+41;var circle2x=leftEye.offsetLeft+69;var circle2y=leftEye.offsetTop+41;var radius=12;var r1=calculateDistance(circle1x,circle1y,xPos,yPos);var r2=calculateDistance(circle2x,circle2y,xPos,yPos);if(r1>radius&&r2>radius&&yPos<=circle1y){leftEyeball.left=radius/r1*(xPos-circle1x)+circle1x+"px";leftEyeball.top=circle1y-radius/r1*(circle1y-yPos)+"px";rightEyeball.left=radius/r2*(xPos-circle2x)+circle2x+"px";rightEyeball.top=circle2y-radius/r2*(circle1y-yPos)+"px";}
else if(r1>radius&&r2>radius&&yPos>circle1y){leftEyeball.left=radius/r1*(xPos-circle1x)+circle1x+"px";leftEyeball.top=circle1y+radius/r1*(yPos-circle1y)+"px";rightEyeball.left=radius/r2*(xPos-circle2x)+circle2x+"px";rightEyeball.top=circle2y+radius/r2*(yPos-circle1y)+"px";}
else if(r1<=radius&&r2>radius&&yPos<=circle1y){rightEyeball.left=radius/r2*(xPos-circle2x)+circle2x+"px";rightEyeball.top=circle2y+radius/r2*(yPos-circle1y)+"px";leftEyeball.left=xPos-7.5+"px";leftEyeball.top=yPos-7.5+"px";}
else if(r1<=radius&&r2>radius&&yPos>circle1y){rightEyeball.left=radius/r2*(xPos-circle2x)+circle2x+"px";rightEyeball.top=circle2y+radius/r2*(yPos-circle1y)+"px";leftEyeball.left=xPos-7.5+"px";leftEyeball.top=yPos-7.5+"px";}
else if(r1>radius&&r2<=radius&&yPos<=circle1y){leftEyeball.left=radius/r1*(xPos-circle1x)+circle1x+"px";leftEyeball.top=circle1y-radius/r1*(circle1y-yPos)+"px";rightEyeball.left=xPos-7.5+"px";rightEyeball.top=yPos-7.5+"px";}
else if(r1>radius&&r2<=radius&&yPos>circle1y){leftEyeball.left=radius/r1*(xPos-circle1x)+circle1x+"px";leftEyeball.top=circle1y+radius/r1*(yPos-circle1y)+"px";rightEyeball.left=xPos-7.5+"px";rightEyeball.top=yPos-7.5+"px";}}
function calculateDistance(x1,y1,x2,y2){return(Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)));}
