movingRight = true
movingDown = true
picWidth = 180
picHeight = 180
xMargin = 21
yMargin = 4

minVelocity = 2
maxVelocity = 5

velocityX = 1
velocityY = 1


xpos = 0
ypos = 0

function moveObj(obj)
{	if ((velocityX - 0.01) >= minVelocity)
		velocityX -= 0.01
	if ((velocityY - 0.01) >= minVelocity)
		velocityY -= 0.01
	
	// Get the random replacement
	movX = Math.random() * 0.5 * velocityX
	movY = Math.random() * 0.5 * velocityY
	
	// Determine if direction changed
	// X-coor.
	if (xpos>=document.body.offsetWidth -picWidth - xMargin){
		movingRight = false
		velocityX = maxVelocity
	}
	else
		if (xpos<=0){
			movingRight = true
			velocityX = maxVelocity
		}
	// Y-coor.
	if (ypos>=document.body.offsetHeight - picHeight - yMargin){
		movingDown = false
		velocityY = maxVelocity
	}
	else
		if (ypos <= 0){
			movingDown = true
			velocityY = maxVelocity
		}
		
	// Move the object
	// X-coor.
	if (movingRight==true)
		xpos += movX
	else
		xpos -= movX
	
	// Y-coor.
	if (movingDown==true)
		ypos += movY
	else
		ypos -= movY
	
	obj.style.left = xpos
	obj.style.top = ypos
	
	window.setTimeout ("moveObj("+obj.id+");",0);
}