// These variables will hold the current mouse pointer position.
var mouseX = 0;
var mouseY = 0;
// Set up event capturing.
if (isMinNS4)  document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMousePosition;
function getMousePosition(e) 
{ 
 // Save cursor position using browser-specific code.
  if (isMinNS4) 
{    mouseX = e.pageX;    mouseY = e.pageY;  }
  if (isMinIE4) 
{    mouseX = event.clientX + document.body.scrollLeft;    
mouseY = event.clientY + document.body.scrollTop;  }  
return true;}
var diskuss = new Array();
function initdiskuss() 
{  
var i, layer;  
// Get handles to all the diskus layers.
  i = 0;  while ((layer = getLayer("diskus" + (i + 1))) != null)
 {    diskuss[i] = layer;    
if (isMinNS4)
      diskuss[i].image = diskuss[i].document.images["diskusImg" + (i + 1)];
if (isMinIE4)
      diskuss[i].image = document.images["diskusImg" + (i + 1)];
    setdiskus(i);
    showLayer(diskuss[i]);
    i++;
  }
  updatediskuss();
}
function setdiskus(n)
 {
  var s, x, y;
  // Randomly place an diskus on the window.
  x = Math.floor(Math.random() * getWindowWidth() );
  y = Math.floor(Math.random() * getWindowHeight() );
  s = Math.floor(Math.random() * 4);
  if (s == 0)
    x = -getWidth(diskuss[n]);
  if (s == 1)
    x = getWindowWidth();
  if (s == 2)
    y = -getHeight(diskuss[n]);
  if (s == 3)
    y = getWindowHeight();
  x += getPageScrollX();
  y += getPageScrollY();
  moveLayerTo(diskuss[n], x - 70 , y - 70);
}
function updatediskuss()
 {
  var i, dx, dy, theta, d;
  // Move each diskus toward the mouse pointer, if she hits it, drop her back onto
  // the page randomly.
  d = 3;
  for (i = 0; i < diskuss.length; i++)
 {
    // Find the angle between the diskus and the pointer.
//  dx = Math.floor(Math.random() * getWindowWidth())- getLeft(diskuss[i]);
//  dy = Math.floor(Math.random() * getWindowHeight())- getTop(diskuss[i]);
    dx = mouseX - getLeft(diskuss[i]) - 25;
    dy = mouseY - getTop(diskuss[i]) - 25;
    theta = Math.round(Math.atan2(-dy, dx) * 180 / Math.PI);
    if (theta < 0)
      theta += 360;
    // Hit the pointer?
    if (Math.abs(dx) < d && Math.abs(dy) < d)
      setdiskus(i);
    // If not, move the diskus and set the image based on angle.
    else if (theta > 23 && theta <= 68)
 {        moveLayerBy(diskuss[i], d, -d);
        diskuss[i].image.src = "images/diskus_kl_no.gif";
    }    else if (theta > 68 && theta <= 113)
 {        moveLayerBy(diskuss[i], 0, -d);
        diskuss[i].image.src = "images/diskus_kl_n.gif";
    }    
else if (theta > 113 && theta <= 158)
 {        moveLayerBy(diskuss[i], -d, -d);
        diskuss[i].image.src = "images/diskus_kl_nw.gif";
    }    
else if (theta > 158 && theta <= 203)
 {        moveLayerBy(diskuss[i], -d, 0);
        diskuss[i].image.src = "images/diskus_kl_w.gif";
    }
    else if (theta > 203 && theta <= 248)
 {        moveLayerBy(diskuss[i], -d, d);
        diskuss[i].image.src = "images/diskus_kl_sw.gif";
    }
    else if (theta > 248 && theta <= 293)
 {        moveLayerBy(diskuss[i], 0, d);
        diskuss[i].image.src = "images/diskus_kl_s.gif";
    }
    else if (theta > 293 && theta <= 338)
 {
        moveLayerBy(diskuss[i], d, d);
        diskuss[i].image.src = "images/diskus_kl_so.gif";
    }
    else 
{        moveLayerBy(diskuss[i], d, 0);
        diskuss[i].image.src = "images/diskus_kl_o.gif";
    }
  }
  // Set up next call.
  setTimeout('updatediskuss()', 50);
  return;
}

