antScore=0;
antPic=new Array(3);
for (i=0;i<=2;i++) {
 antPic[i]=new Image();
 antPic[i].src="images/g-"+i+".gif";
 }

function antShow() {
 if (document.layers) {
  document.ant.document.images["imgAnt"].src=antPic[antDir].src;
  } else {
  document.images["imgAnt"].src=antPic[antDir].src;
  }
 } 

function antX() {return (document.all)?document.all.ant.style.posLeft:document.ant.left;}
function antY() {return (document.all)?document.all.ant.style.posTop:document.ant.top;}
function maxX() {return (document.all)?document.body.clientWidth:window.innerWidth;}
function maxY() {return (document.all)?(document.body.clientHeight+document.body.scrollTop):(window.innerHeight+pageYOffset)}

function antStart() {
 antDir=1;
 antShow();
 antLeg=Math.floor(Math.random()*250)+50;
 if (document.layers) {
  document.ant.top=Math.floor(Math.random()*window.innerHeight)+pageYOffset;
  document.ant.left=-70;
  } else {
  document.all.ant.style.posTop=Math.floor(Math.random()*document.body.clientHeight)+document.body.scrollTop;
  document.all.ant.style.posLeft=-60;
  }
 antStep();
 }

function antStep() {
 if (antDir==1) {
  if (document.layers) {
   document.ant.left++;
   } else {
   document.all.ant.style.posLeft++;
   }
  } else {
  if (document.layers) {
   document.ant.top+=(antDir-1);
   } else {
   document.all.ant.style.posTop+=(antDir-1);
   }
  }
 antLeg--;
 antScore++;
 antCheck();
 }

function antCheck() {
 if (antX() > maxX() || antY() < -22 || antY() > maxY()) {
  antID=setTimeout("antStart()",Math.floor(Math.random()*400)+300);
  } else if (!antLeg) {
  antTurn();
  } else {
  antID=setTimeout("antStep()",30);
  }
 }

function antTurn() {
 if (antDir==1) {
  antDir=Math.floor(Math.random()*2)*2;
  } else {
  antDir=1;
  }
 antShow();
 antLeg=Math.floor(Math.random()*200)+20;
 if ((Math.random()*4500)+3000 < antScore) {
  antScore=-999999;
  //alert("Welcome to kids.yam.com !");
  }
 antID=setTimeout("antStep()",10);
 }
 
if (document.all || document.layers) {
 window.onload=antStart;
 }