antPic=new Array(3);
for (i=0;i<=2;i++) {antPic[i]=new Image(); antPic[i].src="../Obrazky/Ant/ant"+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 maxX() {return 150;}
function maxY() {return (document.all)?(document.body.clientHeight+document.body.scrollTop):(window.innerHeight+pageYOffset)}

function antStart() {
antDir=1; antShow(); antLeg=Math.floor(Math.random()*100)+5;
if (document.layers) 
 {document.ant.top=Math.floor(Math.random()*window.innerHeight)+pageYOffset; document.ant.left=-23;}
else
 {document.all.ant.style.posTop=Math.floor(Math.random()*document.body.clientHeight)+document.body.scrollTop;
 document.all.ant.style.posLeft=-23;}
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--;
antCheck();
}

function antCheck() {
if (antX() > maxX() || antY() < -23 || 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)+10;
antID=setTimeout("antStep()",30);
}

if (document.all || document.layers) {window.onload=antStart;}
