V=0;
P=Array(13,2,1,9,5,4,13,4,10,14,5,9,13,2,14,0);
O=Array();
BR=ce('br');
Y="You start with this item. If you uncheck it, you can't get it from the game.";

function t2(){if(V&2){V+=10;}else{V+=2;}}
function t3(){if(V&2&&V&1){V+=9;}else{V+=1;}}

function y(X,Y){gtni('input',X).style.backgroundColor=(Y)?'':'Yellow';}

function cls()
	{
	for(i=0;i<16;i++){O[i]=P[i];}
	V=0;
	}

function b1(X,Y,Z)
	{
	if(c(X)&&!c(Y))
		{
		y(Y);
		x=confirm('You can\'t have this item without '+Z+' Do you want that item checked?');
		if(x){C(Y,1);}
		else{C(X);}
		y(Y,1);
		}
	}

function b2(X,Y,Z)
	{
	if(c(X)&&!c(Y))
		{
		y(X);
		x=confirm('You can\'t uncheck this unless '+Z+' is unchecked.\nWould you like to uncheck '+Z+'?');
		if(x)
			{
			C(X,0);
			C(Y);
			}
		else{C(Y);}
		y(X,1);
		}
	}

function b3(X,Y,Z)
	{
	if(c(X)&&!c(Y))
		{
		y(Y);
		x=confirm('If you don\'t have the '+Z+', this item will be lost.\n\nWould you like to select the '+Z+'?');
		C(Y,(x)?1:0);
		y(Y,1);
		}
	}

function mod(X,Y)
	{
	O[X]+=Y;
	if(O[X]>=16){O[X]-=16;}
	}

function check()
	{
	if(c(4))
		{
		mod(0,12);
		V+=12;
		}
	if(c(8))
		{
		mod(0,2);
		mod(9,14);
		V+=12;
		}
	if(c(12))
		{
		mod(0,15);
		V+=1;
		}
	if(c(16))
		{
		mod(2,8);
		mod(9,8);
		}
	if(c(20))
		{
		mod(2,4);
		V+=12;
		}
	if(c(24))
		{
		mod(2,2);
		V+=2;
		}
	if(c(28))
		{
		mod(2,15);
		t3();
		}
	if(c(1))
		{
		mod(4,8);
		V+=8;
		}
	if(c(5))
		{
		mod(4,12);
		mod(9,12);
		V+=8;
		}
	if(c(9))
		{
		mod(4,2);
		t2();
		}
	if(c(13))
		{
		mod(4,15);
		t3();
		}
	if(c(17))
		{
		mod(6,8);
		V+=8;
		}
	if(c(21))
		{
		mod(6,12);
		V+=12;
		}
	if(c(25))
		{
		mod(6,2);
		t2();
		}
	if(c(29))
		{
		mod(6,15);
		mod(9,1);
		t2();
		}
	if(c(2))
		{
		mod(8,8);
		mod(13,8);
		}
	if(c(6))
		{
		mod(8,4);
		V+=12;
		}
	if(c(10))
		{
		mod(8,14);
		t2();
		}
	if(c(14))
		{
		mod(8,1);
		t3();
		}
	if(c(18))
		{
		mod(10,8);
		V+=8;
		}
	if(c(22))
		{
		mod(10,12);
		mod(13,4);
		V+=8;
		}
	if(c(26))
		{
		mod(10,2);
		t2();
		}
	if(c(30))
		{
		mod(10,15);
		t3();
		}
	if(c(3))
		{
		mod(12,8);
		V+=8;
		}
	if(!c(7))
		{
		mod(12,12);
		V+=4;
		}
	if(c(11))
		{
		mod(12,2);
		mod(13,14);
		V+=12;
		}
	if(c(15))
		{
		mod(12,15);
		t3();
		}
	if(c(19))
		{
		mod(14,8);
		V+=8;
		}
	if(c(23))
		{
		mod(14,12);
		V+=12;
		}
	if(c(27))
		{
		mod(14,14);
		t2();
		}
	if(c(31))
		{
		mod(14,1);
		mod(13,1);
		t2();
		}
	if(c(32))
		{
		mod(3,8);
		mod(11,8);
		}
	if(c(33))
		{
		mod(1,8);
		V+=8;
		}
	if(c(34))
		{
		mod(5,8);
		V+=8;
		}
	if(c(35))
		{
		mod(5,2);
		t2();
		}
	if(c(36))
		{
		mod(1,4);
		V+=12;
		}
	if(c(37))
		{
		mod(7,12);
		V+=12;
		}
	if(c(38))
		{
		mod(5,12);
		mod(11,4);
		V+=8;
		}
	if(c(39))
		{
		mod(3,4);
		V+=12;
		}
	if(c(40))
		{
		mod(7,2);
		mod(11,2);
		V+=12;
		}
	if(c(41))
		{
		mod(1,14);
		t2();
		}
	if(c(42))
		{
		mod(1,1);
		mod(11,15);
		t2();
		}
	if(c(43))
		{
		mod(7,8);
		V+=8;
		}
	if(c(44))
		{
		mod(1,2);
		mod(3,2);
		}
	if(c(45))
		{
		mod(1,14);
		t2();
		}
	if(c(46))
		{
		mod(3,15);
		t3();
		}
	while(V>15){V-=16;}
	O[15]=V;
	gen();
	}

function coutp()
	{
	X=gid('outp');
	if(X.firstChild)
		{
		X.removeChild(X.firstChild);
		}
	}

function gen()
	{
	coutp();
	OP=ce('div');
	for(i=0;i<16;i++)
		{
		if(!(i&3)){OP.appendChild(BR.cloneNode(0));}
		OP.appendChild(ctn(eval(O[i]).toString(16)))
		}
		OP.style.textAlign='left';
		OP.style.marginLeft='2em';
		document.getElementById('outp').appendChild(OP);
		cls();
	}
cls();