//This preloads the images
phase = 1
if(document.images) {
	scriptyes = 1
	var Ims0 = new Array(26)
	var Ims1 = new Array(26)
	lett = new 	Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z")
	for(j=0; j<26; j++){
		Ims0[j]=new Image(20,20)
		Ims0[j].src = lett[j] + "0.gif"
		Ims1[j]=new Image(20,20)
		Ims1[j].src = lett[j] + "1.gif"
		}
	j = 52
	Ims1[j]=new Image(20,20)
	Ims1[j].src = "blank.gif"
	j = 53
	Ims1[j]=new Image(20,20)
	Ims1[j].src = "smiley1.gif"
	j = 54
	Ims1[j]=new Image(20,20)
	Ims1[j].src = "smiley2.gif"
	j = 55
	Ims1[j]=new Image(20,20)
	Ims1[j].src = "smiley3.gif"
	var rowsav
	var colsav
	}

//This is the core function
function cxn(num) { 
	row = Math.floor(num / puzdim) 
	col = num % puzdim 
	drows = Math.abs(row - rowsav)
	dcols = Math.abs(col - colsav)
	if( drows == 0 || dcols == 0 || drows == dcols ) { 
		dr = 0 
		if( row > rowsav) { dr = 1}
		if( row < rowsav) { dr = -1}
		dc = 0 
		if( col > colsav) { dc = 1}
		if( col < colsav) { dc = -1}
		puzword = ""
		xrow = rowsav
		xcol = colsav
		for(j=0; j<=Math.max(drows, dcols); j++){ 
			ndx = xcol + puzdim*xrow 
			puzword = puzword + puz.charAt(ndx)
			xrow = xrow + dr
			xcol = xcol + dc
			}
		match = -1
		for(j=0; j<lwl; j++){ 
			if( wordlist[j].toLowerCase() == puzword ) { match = j } 
			}
		if( match != -1 ) { 
			xrow = rowsav
			xcol = colsav
			for(j=0; j<=Math.max(drows, dcols); j++){ 
				ndx = xcol + puzdim*xrow
				lettnum = puz.charCodeAt(ndx) - 97  
				imgName = "cc" + ndx
				document[imgName].src = Ims0[lettnum].src
				xrow = xrow + dr
				xcol = xcol + dc
				}
			puzword = wordlist[match]
			for(j=match; j<=lwlt; j++) { 
				wordlist[j] = wordlist[j+1]
				}
			lwl = lwl - 1 
			document.wform.wleft.value=lwl;

			wordlist[lwlt] = puzword
			showwords()	 
			if( lwl == 0 ){ 
				alert('Well done! You have managed to find all the words.');
				showsmiley() 
				}
			} 
		} 
	rowsav = row
	colsav = col
	}
 
function showwords() { 
	parent.clues.document.ans[puzword].value=puzword;
	}

function showsmiley() { 
	if( phase == 1) {
		ndx = Math.floor(Math.random()*(puzdim*puzdim - .001)) 
		imgName = "cc" + ndx
		fname = document[imgName].src
		jsm = Math.floor(Math.random()*2.999) + 53 
		document[imgName].src = Ims1[jsm].src
		tw = 600 
		phase = 0
		} else {
		document[imgName].src = fname 
		tw = 300 
		phase = 1
		}
	setTimeout("showsmiley()", tw) 
	}

