var dotposX=150;
var dotposY=100;
var eyeX=164;
var eyeY=121;
var mouthX=170;
var mouthY=144;
var active=0;
var active2=0;
var lastdir=1;
var lastf=2;
var a=2;
var dX;
var dY;
objmessage=new Array();
left=new Array();
right=new Array();
hleft=new Array();
hright=new Array();
dotpic=new Array();
eyes=new Image();
eyes.src=dotdir + "eyes.gif";
mouth=new Array();

for (i=1;i<5;i++){
mouth[i]=new Image();
mouth[i].src=dotdir + "m"+i+".gif";
}

for (i=1;i<7;i++){
dotpic[i]=new Image();
left[i]=new Image();
right[i]=new Image();
left[i].src=dotdir + "l"+i+".gif";
right[i].src=dotdir + "r"+i+".gif";
}

for (i=1;i<4;i++){
hleft[i]=new Image();
hright[i]=new Image();
hleft[i].src=dotdir + "hl"+i+".gif";
hright[i].src=dotdir + "hr"+i+".gif";
}

document.onmousemove=mousemove
ns=document.layers ? 1:0;
ie=document.all ? 1:0;

if (ns) document.captureEvents(Event.MOUSEMOVE)

function init(){
if (ns){
objeye=document.layers['eyes'];
objshadow=document.layers['shadow'];
objdot=document.layers['dotobj'];
imgdot=document.layers['dotobj'].document.dotimg;
objmouth=document.layers['mouthobj'];
imgmouth=document.layers['mouthobj'].document.mouthimg;
objhelmet=document.layers['helmetobj'];
imghelmet=document.layers['helmetobj'].document.helmetimg;
for (i=0;i<messages;i++)
objmessage[i]=document.layers['msg'+(i+1)];
}
if (ie){
objeye=document.all['eyes'].style;
objshadow=document.all['shadow'].style;
objdot=document.all['dotobj'].style;
imgdot=document.images['dotimg'];
objmouth=document.all['mouthobj'].style;
imgmouth=document.images['mouthimg'];
objhelmet=document.all['helmetobj'].style;
imghelmet=document.images['helmetimg'];
for (i=0;i<messages;i++)
objmessage[i]=document.all['msg'+(i+1)].style;
}
active=1;
active2=1;
setTimeout("blink()",5000)
}

function blink(){
t=4000+Math.round(Math.random()*4000)
setTimeout("blink()",t)
if (active!=1) return;
active=0;
t=2;
blinkOn();
}

function blinkOn(){
objeye.visibility=ns ? "hide":"hidden";
if (lastdir==1)
imgdot.src=left[lastf+3].src
else
imgdot.src=right[lastf+3].src;
setTimeout("blinkOff()",200);
}

function blinkOff(){
objeye.visibility=ns ? "show":"visible";
if (lastdir==1)
imgdot.src=left[lastf].src
else
imgdot.src=right[lastf].src;
t--;
if (t==1)
setTimeout("blinkOn()",200);
else{
active=1;
}
}

function changepic(dir,f){
if (dir==1){
imgdot.src=left[f].src
imghelmet.src=hleft[f].src
if (f==1){
eyeX=dotposX+19
eyeY=dotposY+10
mouthX=dotposX+20
mouthY=dotposY+30
}
else if (f==2){
eyeX=dotposX+14
eyeY=dotposY+21
mouthX=dotposX+20
mouthY=dotposY+44
}
else{
eyeX=dotposX+12
eyeY=dotposY+32
mouthX=dotposX+25
mouthY=dotposY+50
}
}
else{
imgdot.src=right[f].src
imghelmet.src=hright[f].src
if (f==1){
eyeX=dotposX+28
eyeY=dotposY+8
mouthX=dotposX+34
mouthY=dotposY+30
}
else if (f==2){
eyeX=dotposX+34
eyeY=dotposY+19
mouthX=dotposX+34
mouthY=dotposY+42
}
else{
eyeX=dotposX+35
eyeY=dotposY+31
mouthX=dotposX+27
mouthY=dotposY+50
}
}
objmouth.left=mouthX
objmouth.top=mouthY
lastf=f;
lastdir=dir;
}

function mousemove(e){
if (ns){
dX=e.pageX;
dY=e.pageY;
}
if (ie){
dX=event.x;
dY=event.y;
}
if (active!=1) return;
if (dX<dotposX+30)
direc=1
else
direc=2;
dX1=Math.abs(dX-dotposX-30)
dY1=dY-dotposY-30
if (dX1==0) dX1=0.1
d=dY1/dX1
if (d>1)
f=3
else if (d<-1)
f=1
else
f=2;
if (f!=lastf || direc!=lastdir)
changepic(direc,f)

dX1=dX-eyeX
dY1=dY-eyeY
i=Math.sqrt(dX1*dX1+dY1*dY1)
d1=4/i
objeye.top=eyeY+Math.round(dY1*d1)
objeye.left=eyeX+Math.round(dX1*d1)
}

function starttalking(msg){
if (!active2) return;
objmessage[msg].left=dotposX+62;
objmessage[msg].top=dotposY-10;
imgmouth.src=mouth[2].src
}

function stoptalking(msg){
if (!active2) return;
objmessage[msg].top=-1000
imgmouth.src=mouth[1].src
}

function goaway(){
if (active!=1) return;
active=0;
imgmouth.src=mouth[4].src;
X=-100;
x=1
if (dotposX<300){ X=100;x=2}
times=2;
changepic(x,2);
objeye.top=eyeY
objeye.left=eyeX
setTimeout("movedot()",200);
}

function movedot(){
dotposX=dotposX+X
objdot.left=dotposX
objhelmet.left=dotposX-4
objshadow.left=dotposX+30
eyeX=eyeX+X
objeye.left=eyeX
mouthX=mouthX+X
objmouth.left=mouthX
times--
if (times>0)
setTimeout("movedot()",100)
else{
active=1;
imgmouth.src=mouth[1].src;
}
}

function showPic(pic){
if (ns){
document.layers['pic'+pic].top=dY+20;
document.layers['pic'+pic].left=dX;
}
if (ie){
document.all['pic'+pic].style.top=dY+20 + document.body.scrollTop;
document.all['pic'+pic].style.left=dX;
}
imgmouth.src=mouth[3].src;
}

function hidePic(pic){
if (ns)
document.layers['pic'+pic].top=-1000;
if (ie)
document.all['pic'+pic].style.top=-1000;
imgmouth.src=mouth[1].src;
}