var n4=(document.layers);
var n6=(document.getElementById&&!document.all);
var ie=(document.all);
var O=(navigator.appName.indexOf("Opera") != -1)?true:false;
var mozillaBrowser=(navigator.appName.indexOf("Mozilla") != -1)?true:false;
var netscapeBrowser=(navigator.appName.indexOf("Netscape") != -1)?true:false;

if (n4||n6||mozillaBrowser||netscapeBrowser)
{
  pic0=new Image();
  pic0.src="http://mislab.cbi.msstate.edu/~rpearson/eye.gif";
  pic1=new Image();
  pic1.src="http://mislab.cbi.msstate.edu/~rpearson/pupils.gif";

  document.write('<img src="http://mislab.cbi.msstate.edu/~rpearson/eye.gif"    name=eyeball style="position:absolute;top:0px;left:0px;width:69px;height:34px">');
  document.write('<img src="http://mislab.cbi.msstate.edu/~rpearson/pupils.gif" name=pupil1  style="position:absolute;top:0px;left:0px;width:12px;height:13px">');
  document.write('<img src="http://mislab.cbi.msstate.edu/~rpearson/pupils.gif" name=pupil2  style="position:absolute;top:0px;left:0px;width:12px;height:13px">');

  var ym=0;
  var xm=0;

  window.captureEvents(Event.MOUSEMOVE);
  function mouseNS(e)
  {
    ym = e.pageY-window.pageYOffset;
    xm = e.pageX;
  }
  if (n4)window.onMouseMove=mouseNS;
  if (n6)document.onmousemove=mouseNS;

  dy=0;
  dx=0;
  fy=0;
  fx=0;
  angle1=0;
  angle2=0;
  d1=0;
  d2=0;

  window.onload=move;
}

function makefollow()
{
  sy=(!ie)?window.pageYOffset:0;
  wy=(ie)?document.body.clientHeight:window.innerHeight;
  wx=(ie)?document.body.clientWidth:window.innerWidth;
  //Keep eyes on screen. Netscape 6 plays up otherwise!
  var chy=Math.floor(fy-34);
  if (chy <= 0) chy = 0;
  if (chy >= wy-34) chy = wy-34;
  var chx=Math.floor(fx-34);
  if (chx <= 0) chx = 0;
  if (chx >= wx-69) chx = wx-69;
  document.eyeball.style.top=(chy+sy)+'px';
  document.eyeball.style.left=chx+'px';
  
  //eyeball1 centre.
  c1y=parseInt(document.eyeball.style.top)+17;
  c1x=parseInt(document.eyeball.style.left)+17;

  //eyeball2 centre.
  c2y=parseInt(document.eyeball.style.top)+17;
  c2x=parseInt(document.eyeball.style.left)+52;

  dy1 = ym+sy - c1y;
  dx1 = xm - c1x;
  d1 = Math.sqrt(dy1*dy1 + dx1*dx1);
  dy2 = ym+sy - c2y;
  dx2 = xm - c2x;
  d2 = Math.sqrt(dy2*dy2 + dx2*dx2);
  ay1 = ym+sy - c1y;
  ax1 = xm - c1x;
  angle1 = Math.atan2(ay1,ax1)*180/Math.PI;
  ay2 = ym+sy - c2y;
  ax2 = xm - c2x;
  angle2 = Math.atan2(ay2,ax2)*180/Math.PI;
  dv=1.7;
  document.pupil1.style.top=((d1 < 17)?(c1y-6+d1/dv*Math.sin(angle1*Math.PI/180)):(c1y-6+10*Math.sin(angle1*Math.PI/180)))+'px';
  document.pupil1.style.left=((d1 < 17)?(c1x-6+d1/dv*Math.cos(angle1*Math.PI/180)):(c1x-6+10*Math.cos(angle1*Math.PI/180)))+'px';
  document.pupil2.style.top=((d2 < 17)?(c2y-6+d2/dv*Math.sin(angle2*Math.PI/180)):(c2y-6+10*Math.sin(angle2*Math.PI/180)))+'px';
  document.pupil2.style.left=((d2 < 17)?(c2x-6+d2/dv*Math.cos(angle2*Math.PI/180)):(c2x-6+10*Math.cos(angle2*Math.PI/180)))+'px';
}

function move()
{
  dy=fy+=(ym-fy)*0.12;
  dx=fx+=(xm-fx)*0.12;
  makefollow();
  setTimeout('move()',10);
}

