document.write("");
var checkerboardEccentricity=10;
var checkerboardScale=20;
var nDelayVariance=20;
var nFirstRealFrame=5;
var sNekoMessage="Click Neko and he'll chase your mouse! Double-click to visit Neko's home (http://webneko.net)";
var sNekoMessageCaught=sNekoMessage;
function byName(array,name){for(var i=0;i
";
this.layer=createLayer(strLayer,x,y,35,35,strContent);
this.layer.Neko=this;
this.homeX=this.layer.myx;
this.homeY=this.layer.myy;
this.doc=this.layer.document;
if(!this.doc)this.doc=document;
this.image=byName(this.doc.images,strImage);
this.image.Neko=this;
if(window.delay&&window.delay>0){this.delay=window.delay+Math.floor(nDelayVariance*Math.random()-5);
}else{this.delay=250+Math.floor(nDelayVariance*Math.random()-5);
}this.delayMultiplier=1;
if(window.stepsize&&window.stepsize>0){this.stepsize=window.stepsize;
}else{this.stepsize=16;
}if(!active)active=false;
this.active=active;
this.SetBehavior("resting");
this.frame=nFirstRealFrame;
this.direction="";
this.looseDirection="";
this.endx=0;
this.endy;
this.distx;
this.disty;
this.steps;
this.caught=true;
this.dx;
this.dy;
this.boardX=-1;
this.boardY=-1;
this.eccX=Math.floor(checkerboardEccentricity*Math.random()-checkerboardEccentricity/2);
this.eccY=Math.floor(checkerboardEccentricity*Math.random()-checkerboardEccentricity/2);
this.Think();
}function NekoMessage(){var sMsg=(this.caught)?sNekoMessageCaught:sNekoMessage;
window.status=sMsg;
}Neko.prototype.message=NekoMessage;
function NekoTargetMouse(){var endx=mouse.x+4;
var endy=mouse.y-20;
this.endx=endx;
this.endy=endy;
box.setBoard(this.whichNeko,this.endx,this.endy);
}Neko.prototype.TargetMouse=NekoTargetMouse;
function NekoShow(){sE(this.layer);
}Neko.prototype.Show=NekoShow;
function NekoHide(){hE(this.layer);
}Neko.prototype.Hide=NekoHide;
function NekoTargetHome(){this.endx=this.homeX;
this.endy=this.homeY;
}Neko.prototype.TargetHome=NekoTargetHome;
function NekoCalculateDistance(){this.distx=this.endx-this.layer.myx;
this.disty=this.endy-this.layer.myy;
this.steps=Math.sqrt(Math.pow(this.distx,2)+Math.pow(this.disty,2))/this.stepsize;
if(this.steps>=1){if(this.caught){eval(this.onUnCaught);
}this.caught=false;
}else{if(!this.caught){eval(this.onCaught);
}this.caught=true;
}this.dx=this.distx/this.steps;
this.dy=this.disty/this.steps;
}Neko.prototype.CalculateDistance=NekoCalculateDistance;
function NekoSetBehavior(strNewBehavior){this.behavior=strNewBehavior;
this.frame=nFirstRealFrame;
var paImages=eval("aNekos["+this.whichNeko+"].a_"+this.behavior);
this.onCaught=paImages[0];
this.onUnCaught=paImages[1];
this.onLoopEnd=paImages[2];
this.loopTimes=paImages[3];
this.delayMultiplier=paImages[4];
}Neko.prototype.SetBehavior=NekoSetBehavior;
function NekoUpdateImage(){var paImages=eval("aNekos["+this.whichNeko+"].a_"+this.behavior);
if(this.frame>=paImages.length){this.behaviorRepetition++;
if(this.loopTimes!=0&&this.behaviorRepetition>=this.loopTimes){this.behaviorRepetition=0;
eval(this.onLoopEnd);
var paImages=eval("aNekos["+this.whichNeko+"].a_"+this.behavior);
}else{this.frame=nFirstRealFrame;
}}if(this.aGifs[this.direction+paImages[this.frame]]){var strImage=this.aGifs[this.direction+paImages[this.frame]].src;
this.image.src=strImage;
}else if(this.aGifs[paImages[this.frame]]){var strImage=this.aGifs[paImages[this.frame]].src;
this.image.src=strImage;
}else if(this.looseDirection+this.aGifs[paImages[this.frame]]){var strImage=this.aGifs[this.looseDirection+paImages[this.frame]].src;
this.image.src=strImage;
}else{this.image.src=this.aGifs["alert"].src;
}this.frame++;
}Neko.prototype.UpdateImage=NekoUpdateImage;
function NekoMoveAStep(){if(this.steps>=1){this.layer.myx+=this.dx;
this.layer.myy+=this.dy;
}else{this.layer.myx=this.endx;
this.layer.myy=this.endy;
}if(box.checkBoard(this.whichNeko,this.layer.myx,this.layer.myy)){this.layer.myx+=this.eccX;
this.layer.myy+=this.eccY;
}sX(this.layer,this.layer.myx);
sY(this.layer,this.layer.myy);
box.setBoard(this.whichNeko,this.layer.myx,this.layer.myy);
}Neko.prototype.MoveAStep=NekoMoveAStep;
function NekoFindDirection(){if((dx==0)&&(dy==0)){this.direction="";
return;
}var dy=-1*this.dy;
var dx=this.dx;
var adx=Math.abs(dx);
var ady=Math.abs(dy);
var ns="";
var ew="";
var tan=ady/adx;
var bNSShallow=(tan<.41421);
var bEWShallow=(tan>2.4142);
if(dy>0){if(!bNSShallow)ns="n";
}else{if(!bNSShallow)ns="s";
}if(dx>0){if(!bEWShallow)ew="e";
}else{if(!bEWShallow)ew="w";
}if(ew!=""){this.looseDirection=ew;
}else{this.looseDirection=ns;
}this.direction=ns+ew;
}Neko.prototype.FindDirection=NekoFindDirection;
function NekoThink(){if(this.active){this.TargetMouse();
}else{this.TargetHome();
}this.CalculateDistance();
this.FindDirection();
this.UpdateImage();
if(this.behavior=="chasing"){this.MoveAStep();
}var delay=Math.floor(this.delay*this.delayMultiplier);
setTimeout("aNekos["+this.whichNeko+"].Think()",delay);
}Neko.prototype.Think=NekoThink;
function nekoChooseIdle(){var aChoice=new Array("resting","yawning","itching","scratching");
var nChoice=Math.floor(Math.random()*aChoice.length);
this.SetBehavior(aChoice[nChoice]);
}Neko.prototype.chooseIdle=nekoChooseIdle;
function startANeko(){var x=0;
var y=0;
if(window.startNekoX)x=window.startNekoX;
if(window.startNekoY)y=window.startNekoY;
if(parseInt(x)!=x){window.onresize=function(){for(var i=0;imaxx)x=maxx;
return x;
}box.prototype.boundWidth=boxBoundWidth;
function boxBoundHeight(y){if(y!=0&&!y)y=this.height();
var miny=20;
var maxy=this.height()-12;
if(ymaxy)y=maxy;
return y;
}box.prototype.boundHeight=boxBoundHeight;
function boxSetBoard(nNeko,x,y){var sx=Math.floor(x/this.width()*checkerboardScale);
var sy=Math.floor(y/this.height()*checkerboardScale);
if(sx<0)sx=0;
if(sx>=checkerboardScale)sx=checkerboardScale-1;
if(sy<0)sy=0;
if(sy>=checkerboardScale)sy=checkerboardScale-1;
var oN=aNekos[nNeko];
if(oN.boardX!=sx||oN.boardY!=sy){if(oN.boardX!=-1){checkerboard[oN.boardX][oN.boardY]--;
}checkerboard[sx][sy]++;
oN.boardX=sx;
oN.boardY=sy;
}if(checkerboard[sx][sy]==0)return 0;
return checkerboard[sx][sy]-1;
}box.prototype.setBoard=boxSetBoard;
function boxCheckBoard(nNeko,x,y){var sx=Math.floor(x/this.width()*checkerboardScale);
var sy=Math.floor(y/this.height()*checkerboardScale);
if(sx<0)sx=0;
if(sx>=checkerboardScale)sx=checkerboardScale-1;
if(sy<0)sy=0;
if(sy>=checkerboardScale)sy=checkerboardScale-1;
var oN=aNekos[nNeko];
var nDec=0;
if(oN.boardX==sx&&oN.boardY==sy){nDec=1;
}return checkerboard[sx][sy]-nDec;
}box.prototype.checkBoard=boxCheckBoard;
box=new box();
document.onmousemove=function(e){var x=e?e.pageX:event.x+document.body.scrollLeft;
var y=e?e.pageY:event.y+document.body.scrollTop;
mouse.x=box.boundWidth(x);
mouse.y=box.boundHeight(y);
};
if(document.captureEvents)document.captureEvents(Event.MOUSEMOVE);
var checkerboard=new Array(checkerboardScale);
for(var i=0;i