
// ------------- EYES ---------------------------


//------------------------------------------------------
//         Watching Eyes Script (Second edition)
//              script by Virtual_Max 
// Please, check my site for latest edition of this script
//      http://www.geocities.com/siliconvalley/lakes/8620    
// This script can be used/modified free without special permission 
// until this notice presents unchanged in all copies and derivatives.             
// MIE5, NN4, NN6 compatible
//------------------------------------------------------

var mx=200;  
var my=200;
var moving=true;


var imw=80    // eyes bg image width
var imh=40    // eyes bg image height
var imey=20   // y coordinate of eyes center
var imex1=20  // x coordinate of left eye
var imex2=60  // x coordinate of right eye


var rx;
var ry;
var eyetimer=null;

var eyeballs,lefteye,righteye;

function getById(id,o){
    if(document.getElementById) return document.getElementById(id);
    if(document.all)            return document.all[id]
    if(o==null) o=window.document;

    if(o.layers[id]){
      return o.layers[id]
    }

    if(o.images[id]){
      return o.images[id]
    }

    for(var i=0; i<o.layers.length; i++){
       var oo=getById(id,o.layers[i].document); 
       if(oo!=null) return oo;
    }
    return null;
}


function moveObject(x,y,o){
  if( o==null ) return;
  if(document.layers){
     o.moveTo(x,y);     
  }
  else {
    o=o.style;
    if(document.all) {
       o.pixelLeft=x;
       o.pixelTop=y;
    }
    else {
       o.left=x;
       o.top=y;     
    }
  }
}

function mymousemoved(ex,ey){
    mx=ex; my=ey;
}

function movestart()
{if(moving){
   rx+=(mx-rx-imw/2)*0.1;
   ry+=(my-ry-imh-20)*0.1; 
 }
 dy=my-ry-imey;
 dx1=mx-rx-imex1;
 dx2=mx-rx-imex2;
 r=Math.sqrt(dx1*dx1+dy*dy);
 if(r<20) r=20
 dx1=dx1*10/r+rx+10;
 dy1=dy*10/r+ry+10;
 r=Math.sqrt(dx2*dx2+dy*dy);
 if(r<20) r=20
 dx2=dx2*10/r+rx+50;

 if(eyeballs == null) eyeballs = getById("eyeballs");
 if(lefteye  == null) lefteye  = getById("lefteye");
 if(righteye == null) righteye = getById("righteye");

 moveObject(Math.floor(rx),Math.floor(ry),eyeballs);
 moveObject(Math.floor(dx1),Math.floor(dy1),lefteye);
 moveObject(Math.floor(dx2),Math.floor(dy1),righteye);
 eyetimer=setTimeout("movestart()",100);

}

function myhandler(e){
 if(e)
  {   ex=e.pageX; 
      ey=e.pageY;
      mymousemoved(ex,ey);
      return routeEvent(e);
  }
 if(event)
  {ex=event.clientX+window.document.body.scrollLeft;
   ey=event.clientY+window.document.body.scrollTop;
   mymousemoved(ex,ey);
  }
 return null;  
}

function clearmytimer()
 {if(eyetimer!=null) clearTimeout(eyetimer);
 }

function setupeyes(eyeballs,eye,xx,yy,follow)
{
if(xx!=null) mx=xx;
if(yy!=null) my=yy;
if(follow!=null)  moving=follow;
rx=mx-40;
ry=my-60;

 window.onunload = clearmytimer;

 if(document.layers)
   {window.captureEvents(Event.MOUSEMOVE);
    window.onMouseMove=myhandler;
    window.onresize=new Function('history.go(0)');
   }
 else
   {document.onmousemove=myhandler;}

 movestart();
}
// ------------- End EYES ---------------------------

