var deltaX, deltaY, windowWidth, windowHeight, imgWidth, imgHeight; function move(objName, dx, dy, speed){ obj = document.getElementById(objName); obj_img = document.getElementById(objName+"_img"); deltaX = dx; deltaY = dy; imgWidth = obj_img.width; imgHeight = obj_img.height; newSize(); // fly(obj); setInterval('fly(obj)', speed); } function newSize(){ if(window.innerWidth){ windowWidth = window.innerWidth - imgWidth - 1; windowHeight = window.innerHeight - imgHeight - 1; } else{ windowWidth = document.body.offsetWidth - imgWidth - 1; windowHeight = document.body.offsetHeight - imgHeight - 1; } } function fly(obj){ xPos = eval(obj.style.left.replace(/p./, "")); yPos = eval(obj.style.top.replace(/p./, "")); xPos = xPos + deltaX; yPos = yPos + deltaY; if(xPos < 0){ deltaX = Math.abs(deltaX); } if(xPos > windowWidth){ deltaX = -Math.abs(deltaX); } if(yPos < 0){ deltaY = Math.abs(deltaY); } if(yPos > windowHeight){ deltaY = -Math.abs(deltaY); } xPos = xPos + "px"; yPos = yPos + "px"; obj.style.left = xPos; obj.style.top = yPos; } function show(sObjName){ sobj = document.getElementById(sObjName); sobj.style.visibility = "visible"; }