<!--
var dir = "";

var isMinNS4 = (document.layers) ? 1 : 0;
var isMinIE4 = (document.all)    ? 1 : 0;
var isMoz    = (isMinNS4+isMinIE4 == 0) ? 1 : 0

if(isMinNS4 && isMinIE4)
{
  isMinNS4=0
}

var mouseX = 0;
var mouseY = 0;

if ((isMinNS4)||(isMoz))
  document.captureEvents(Event.MOUSEMOVE);

document.onmousemove = getMousePosition;

var Balls=""

var speedX = 0;
var speedY = 0;

var speedMax = 25;
var speedMin = 1;
var acceleration = 3;

var minX, maxX, minY, maxY


function display_ball(ball_name,ball_gif)
{
   var cmd = "<div id=\""+ball_name+"\" class=\"ballt\"><img src=\""+ball_gif+"\" width=20 height=20></div>"
//   alert(cmd)
   document.writeln(cmd)
   balls_layer(ball_name)
}

function balls_layer(ball_name){
  if (isMinNS4)      Balls = document.layers[ball_name];
  if (isMinIE4)      Balls = eval('document.all.'+ball_name);
  if (isMoz)         Balls = document.getElementById(ball_name);
//  alert(Balls)
  return Balls
}


function init()
{
  get_page_size()

//  if (isMinNS4)      Balls = document.layers["divball"];
//  if (isMinIE4)      Balls = eval('document.all.divball');
//  if (isMoz)         Balls = document.getElementById("divball");

  initBall();
  showLayer(Balls);
  updateBall();
}

function get_page_size()
{
  minX = getPageScrollX();
  maxX = minX+getWindowWidth()-40;
  minY = getPageScrollY();
  maxY = minY+getWindowHeight()-30;
  
}


function moveLayerTo(layer, x, y) 
{

  if (isMinNS4)   
     layer.moveTo(x, y);
  if (isMinIE4) 
    {
      layer.style.left = x;
      layer.style.top  = y;
    }
  if (isMoz)
  {
    layer.style.left = x + "px";
    layer.style.top = y + "px";
  }
}

function getWindowWidth() 
{
  if (isMinNS4)      return(window.innerWidth);
  if (isMoz)         return(window.innerWidth);
  if (isMinIE4)      return(document.body.offsetWidth);
  return(-1);
}
function getWindowHeight()
{
  if (isMinNS4)      return(window.innerHeight);
  if (isMoz)         return(window.innerHeight);
  if (isMinIE4)      return(document.body.offsetHeight);
  return(-1);
}

function getPageScrollX() 
{
  if (isMinNS4)      return(window.pageXOffset);
  if (isMoz)         return(window.pageXOffset);
  if (isMinIE4)      return(document.body.scrollLeft);
  return(-1);
}

function getPageScrollY() 
{
  if (isMinNS4)      return(window.pageYOffset);
  if (isMoz)         return(window.pageYOffset);
  if (isMinIE4)      return(document.body.scrollTop);
  return(-1);
}

function getHeight(layer) 
{
  if (isMinNS4) 
    {
      if (layer.document.height)
        return(layer.document.height);
      else
        return(layer.clip.bottom - layer.clip.top);
    }
  if (isMinIE4) 
    {
      if (false && layer.style.pixelHeight)
        return(layer.style.pixelHeight);
      else
        return(layer.clientHeight);
    }
  if (isMoz)
  {
        return(layer.style.height);
  }
  return(-1);
}

function getWidth(layer) 
{
  if (isMinNS4) 
    {
      if (layer.document.width)
        return(layer.document.width);
      else
        return(layer.clip.right - layer.clip.left);
    }
  if (isMinIE4) 
    {
      if (layer.style.pixelWidth)
        return(layer.style.pixelWidth);
      else
        return(layer.clientWidth);
    }
  if (isMoz)
  {
        return(layer.style.width);
  }

  return(-1);
}

function getLeft(layer) 
{
   if (isMinNS4)       return(layer.left);
   if (isMinIE4)       return(layer.style.pixelLeft);
  if (isMoz)
  {
   return(parseInt(layer.style.left));
  }

   return(-1);
}

function getTop(layer) 
{
  if (isMinNS4)        return(layer.top);
  if (isMinIE4)        return(layer.style.pixelTop);
  if (isMoz)
  {
      return(parseInt(layer.style.top));
  }

  return(-1);
}

function getRight(layer) 
{
  if (isMinNS4)        return(layer.left + getWidth(layer));
  if (isMinIE4)        return(layer.style.pixelLeft + getWidth(layer));
  if (isMoz)
  {
      return(parseInt(layer.style.left) + getWidth(layer));
  }

  return(-1);
}

function getBottom(layer) 
{
  if (isMinNS4)        return(layer.top + getHeight(layer));
  if (isMinIE4)        return(layer.style.pixelTop + getHeight(layer));
  if (isMoz)
  {
   return(parseInt(layer.style.top) + getHeight(layer));
  }

  return(-1);
}

function showLayer(layer) {
  if (isMinNS4)        layer.visibility = "show";
  if (isMinIE4)        layer.style.visibility = "visible";
  if (isMoz)
  {
   layer.style.visibility = "visible";
  }

}

function getMousePosition(e) 
{
  if (isMinNS4) 
    {
       mouseX = e.pageX;
       mouseY = e.pageY;
    }
  if (isMinIE4) 
    {
       mouseX = event.clientX + document.body.scrollLeft;
       mouseY = event.clientY + document.body.scrollTop;
    }
  if (isMoz)
  {
       mouseX = e.pageX;
       mouseY = e.pageY;
  }

  return true;
}

function initBall()
{
  var s, x, y;
  x = Math.floor(Math.random() * getWindowWidth());
  y = Math.floor(Math.random() * getWindowHeight());
  s = Math.floor(Math.random() * 4);
  if (s == 0)
    x = -getWidth(Balls);
  if (s == 1)
    x = getWindowWidth();
  if (s == 2)
    y = -getHeight(Balls);
  if (s == 3)
    y = getWindowHeight();
  x += getPageScrollX();
  y += getPageScrollY();

  speedX = Math.floor(Math.random() * speedMax) - speedMax/2;
  speedY = Math.floor(Math.random() * speedMax) - speedMax/2;

  moveLayerTo(Balls, x, y);
}

function updateBall()
{
  var i, dx, dy, theta, d;

  var ballX = getLeft(Balls);
  var ballY = getTop(Balls);

  get_page_size()

//  alert("mouseX="+mouseX+", mouseY="+mouseY+", minX="+minX+", maxX="+maxX)

  if (mouseX < ballX)
    {
      speedX=speedX-acceleration
      if (speedX<(0-speedMax))
        speedX=(0-speedMax)
    }
  else
    {
      speedX=speedX+acceleration
      if (speedX>speedMax)
        speedX=speedMax
    }
  if (speedX==0)
    speedX=1
  ballX += speedX


  dx = ballX - minX                // Have we hit the left side?

//  alert("speedX="+speedX+", ballX="+ballX)


  if (dx<0)                        // Yes, so bounce
    {
       ballX=ballX-dx
       speedX=0-speedX
    }
  dx = ballX - maxX                // Have we hit the right side?
  if (dx>0)                        // Yes, so bounce
    {
       ballX=ballX-dx
       speedX=0-speedX
    }
  if (mouseY < ballY)
    {
      speedY=speedY-acceleration
      if (speedY<(0-speedMax))
        speedY=(0-speedMax)
    }
  else
    {
      speedY=speedY+acceleration
      if (speedY>speedMax)
        speedY=speedMax
    }
  if (speedY==0)       speedY=1
  ballY += speedY
  dy = ballY - minY                     // Have we hit the top side?
  if (dy<0)                             // Yes, so bounce
    {
       ballY=ballY-dy
       speedY=0-speedY
    }
  dy = ballY - maxY                     // Have we hit the bottom side?
  if (dy>0)                             // Yes, so bounce
    {
       ballY=ballY-dy
       speedY=0-speedY
    }

//  alert("ballX="+ballX+", ballY="+ballY)
  moveLayerTo(Balls,ballX,ballY)
  setTimeout(updateBall, 50);
  return;
}

//  End -->
