
var list1 = new Array("about","after","again","another","back","ball","because","bed","been","boy","brother","but","called","call","came","could","did","dig","door","down","first","from","girl","boy","good","got","had","half","has","have","help","her","here","him","his","home","house","how","jump","just","last","laugh","little","live","lived","love","made","make","man","many","may","more","much","must","name","new","next","night","not","now","off","old","once","one","our","out","over","people","push","pull","put","ran","saw","school","seen","should","sister","some","take","than","that","their","them","then","there","these","three","time","took","too","tree","two","very","want","water","way","were","what","when","where","who","will","with","would","your","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday","January","February","March","April","May","June","July","August","September","October","November","December","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen","twenty","red","orange","yellow","green","blue","violet","black","white","grey","silver","gold");

var list2 = new Array("asked","began","being","change","coming","does","found","goes","gone","heard","jumped","knew","know","leave","might","opened","show","started","stopped","think","thought","told","tries","turned","used","walked","walking","watch","write","woke","woken","almost","always","before","better","during","every","between","first","half","morning","much","never","number","often","only","second","sometimes","still","suddenly","today","until","while","year","young","above","across","along","around","below","both","different","following","high","inside","near","other","outside","place","right","round","such","through","together","under","where","without","baby","balloon","birthday","children","clothes","garden","great","happy","head","heard","something","sure","swimming","those","word","work","world","earth","eyes","father","friends","important","lady","light","money","mother","paper","sister","small","sound","white","whole","why","window");

var wordlist=new Array(list1,list2);

var hidden;
var wordseen, word;
var count, score;
var y, z;
score=0;

function setup(z,score)
	{
		y=z;
		var x,n;
		count=10;
		wordseen="";
		word="";
		x=Math.floor(Math.random()*wordlist[y].length);
		hidden=wordlist[y][x];
		n=hidden.length;

		for (var i=0;i<hidden.length;i++)
			{
				wordseen=wordseen+"_ ";
				word=word+"_";
			}

		document.getElementById("gameend").innerHTML="";
		document.getElementById("counter").innerHTML="10";
		document.getElementById("scorepad").innerHTML=score;
		document.getElementById("gameenter").innerHTML="";
		document.getElementById("hiddenword").innerHTML = wordseen;

		document.getElementById("guessbox").innerHTML="<table border=\"3\"><tr><td align=\"center\"><input type=\"text\" size=\"1\" maxlength=\"1\" id=\"letter\" style=\"font-size:30pt;text-align:center\" value=\"\"></td></tr><tr><td><input type=\"button\" id=\"guess\" value =\"guess\" onclick=\"guess(getElementById('letter').value.toString())\"></td></tr></table>";

		document.getElementById("letter").focus();

		document.getElementById("left").innerHTML="<p>Try to guess the hidden word letter by letter.<br><br> To make a guess enter a letter in the box and press the guess button.<br><br> If you guess a letter correctly, it will appear in place and you can guess again. If you make 10 wrong guesses then you lose.</p>";
	}

function guess(g)
	{
		var found=false;
		var message;
		for (var i=0;i<hidden.length;i++)
			{
				if (g == hidden.charAt(i))
					{
						wordseen=wordseen.substr(0,2*i)+g+wordseen.substr(2*i+1);
						word=word.substr(0,i)+g+word.substr(i+1);
						found=true;
					}
			}
		if (!found)
			{
				count--;

				document.getElementById("counter").innerHTML=count;
				if (count <= 0)
					{
						message="Bad luck! You ran out of guesses.<br><br><br><br><br><span style='color:#ff0000;z-index:5' onclick='setup(z,0)' onmouseover=\"style.color='#00a000';style.cursor='pointer'\" onmouseout=\"style.color='#ff0000'\"><u>Play again?</u></span>";
						showword(message);
					}
			}
		else
			{
				document.getElementById("hiddenword").innerHTML = wordseen;
				checkwon();
			}

				document.getElementById("letter").value="";
				document.getElementById("letter").focus();
			}

function checkwon()
	{
		if (word == hidden)
			{
				score++;
				document.getElementById("scorepad").innerHTML=score;
				message="Well done you won! <br><br><br><br><br><span style='color:#ff0000;z-index:5' onClick='setup(z,score)' onmouseover=\"style.color='#00a000';style.cursor='pointer'\" onmouseout=\"style.color='#ff0000'\"><u>Another word?</u></span>"
				showword(message);
			}
	}

function showword(message)
	{
		document.getElementById("gameend").innerHTML=message;
		document.getElementById("hiddenword").innerHTML = "\<span style=\"color:#ff00ff\"\>"+hidden+"\<\/span\>";
		document.getElementById("guess").disabled=true;
	}

