u=0;	
l=0;	
p=0;	
t=0;	
b=0;	
c=0;	
q=0;	
f=0;	
a=0;	
function w(x){ 
	document.write(x);
}
function s(y,x){	
	return " style='position:absolute;top:"+y+"px;left:"+x+"px;text-align:center;vertical-align:middle;font-size:21px;";
}
function m(){ 
	
	w("<b id='l'"+s(9,9)+"width:96px'></b><b id='p'"+s(9,128)+"width:164px;border-top:1px solid white;border-bottom:1px solid white'></b><b id='s'"+s(9,280)+"width:128px'></b>");for(k=0,j=0;j<6;++j){
	w("<div"+s(42,j*64+9)+"'>");
	for(i=0;i<6;++i,++k){
		w("<div id='"+k+"' style='width:64px;height:64px;border: solid 1px #90f;'> </div>");
	}
	w("</div>");
	}

	for(i=0;i<3;++i){
	w("<img id='n"+(i+1)+"' src='n.gif' width='50' height='64'"+s(448,9+64*i)+"'>");
	}w("<img id='n' src='n.gif' width='50' height='64'"+s(448,9)+"'><img id='c' width='50' height='64' src=''"+s(0,0)+"'><h2 onclick='ng(0)'"+s(448,9+64*3)+"background-color:gray;border:outset 4px gray;width:128px'>New Game</h2>");
}


function g(x){	
	return document.getElementById(x);
}

function r(x){
	return Math.floor(Math.random()*x);
}

function d(x,y){	
	g(x).innerHTML=y;
}

function an(x,y,z){	
	g(x).src=y+".gif";
	setTimeout("g('"+x+"').src='"+x+".gif'",z);
}

function ch(){
	if(t==p){	
	clearInterval(b);	an('c','m',900);
	g("n"+l--).style.display="none";
	t=0;
	p=15;
	c-=100;
	u=0;
	setTimeout("v(0,0);v(0,1);++u;b=setInterval('o()',1500-q*50);",999);

	}
	if(!l){	
	clearInterval(b);	
	alert("U Dead!");
	}
	j=0;
	for(i=0;i<36;++i){	
	if(parseInt(g(i).a)==0)
		++j;
	}
	if(!j){
	ng(++q);
	}
}

function v(x,z){	i=t;	
	if(z){	
	i=p;
	}
	
if((x==1&&!((i+1)%6))||(x==-1&&!(i%6)))	
	return;

	if(i+x>-1&&i+x<36){	
	if(z){	
		p+=x;
	}else{
		t+=x;	
	}
	}
	i=t;	
	if(z){	
	i=p;
	}
	x=Math.floor(i/6)*64+18;
	y=i%6*64+42;if(z){
	z='n';
	}else{
	z='c';
	}g(z).style.left= x+"px";
	g(z).style.top= y+"px";
}


function o(){
	if(l){	if(Math.floor(t/6)!=Math.floor(p/6)){
		if(r(2)){
		x=t<p?6:6*-1;
		}else{
		x=t<p?-1:1;
		}
	}else{	
		x=t<p?1:-1;
	}
	if(x+t==a){
		x=0;
	}
	if(r(2)){
		np(t);
	}
	v(x,0);	
	++c;	
	ch();	}
}


function np(x){	
	g(x).a=0;	if(q%2){	
	if(!f){
		f=q<2?5:r(7)+2;	
	}d("p","Multiples of "+f);	
	z=r(9)*f;if(r(6)<2){	
		g(x).a=1;	
		z+=r(f-2)+1;
	}

}else{
	if(!f){
		f=(r(7)+2)*(r(5)+4);
		}
		d("p","Divisors of "+f);
		
		z=r(f)+1;
		
		if(f%z){	
		g(x).a=1;	
		}
	}
	d(x,"<br>"+z);	

}


function ng(x){
	++u;if(x==0){	
	c=0;
	l=3;
	q=1;
	for(i=1;i<=3;++i){g("n"+i).style.display="block";}
	}f=0;	
	for(i=0;i<36;++i){
	np(i);
	}
	d('l',"Level: "+q);
	d('s',"Score: "+c);
	p=15;
	t=0;
	v(0,1);
	v(0,0);
	g('c').src="c.gif";
	clearInterval(b);
	b=setInterval("o()",1500-q*50);
}



function h(x){if(document.all){	
	x=window.event.keyCode;
	}else{
	x=x.which;	
	}
	

if(l&&u){
	if(x==38||x==105){	
		v(-1,1);}
	if(x==40||x==107){	
		v(1,1);}
	if(x==37||x==106){	
		v(-1*6,1);}
	if(x==39||x==108){	
		v(6,1);}
	if(x==32){	
		
		d(p," ");
		if(g(p).a==0){
		an('n','e',99);
		c+=100;
		d('s',"Score: "+c);
		}else{
		if(g(p).a==1){
		an('n','d',900);
		g("n"+l--).style.display="none";
		u=0;
		setTimeout("++u",999);
		}
		}
		g(p).a=2;	
		
	}
	ch();	
	}	
}


function pt(){

	g(a).style.background="#007";
	a=r(35);
	g(a);
	g(a).style.background="#00F";
}


setInterval("pt()",9999);	