var choices = 5;
var categories = 6;
var item_status = new Array();
var current = 0;
var count = 1;
var max;
var result = new Array();

function go() {
	//alert("let's do this");
	max = parseInt(document.choices.number.value);
	
	if(!(max > 0)) {
	  	alert("You must enter your favorite number!");
	} else {
		current = 0;
		count = 1;
		for(i = 0; i < choices * categories + 4; i++) {
	  		item_status[i] = 'open';
	  		//document.all.item("item"+(i)).style.backgroundColor = "#FFFFFF";
			document.getElementById("item"+(i)).style.backgroundColor = "#FFFFFF";
		}
		for(i = choices * categories + 4; i < choices * (categories + 1); i++) {
			item_status[i] = 'closed';
		}
		//message.innerHTML = "WORKING...";
		document.getElementById("message").innerHTML = "WORKING...";
		setTimeout("move_marker();", 1);
	}
}

function move_marker() {
	if(current == 0) { 
  		prev = choices * categories + 3;
	} else { 
		prev = current - 1;
	}
	
	if(item_status[prev] == 'open') {
		//document.all.item("item"+(prev)).style.backgroundColor = "#FFFFFF";
		document.getElementById("item"+(prev)).style.backgroundColor = "#FFFFFF";
	}
  
  
	if(item_status[current] == 'open') {
    	if(count == max) {
			item_status[current] = 'closed';
			start = Math.floor(current / choices) * choices;
			c = 0;
	  
			for(i = start; i < start + choices; i++) {
				if(item_status[i] == 'open') {
					c++;
					keep = i;
				}
			}
	  
			if(c == 1) {
				item_status[keep] = 'keep';
				//result[Math.floor(keep / choices)] = document.choices.item('choice'+keep).value;
				//result[Math.floor(keep / choices)] = document.getElementsByName('choice'+keep).value;
				result[Math.floor(keep / choices)] = document.getElementById('item'+keep).value;
				
				//document.all.item("item"+(keep)).style.backgroundColor = "#FFFFCC";
				document.getElementById("item"+(keep)).style.backgroundColor = "#FFFFCC";
			}
	  
			//document.all.item("item"+(current)).style.backgroundColor = "#666666";
			document.getElementById("item"+(current)).style.backgroundColor = "#666666";
			count = 1;
			keep = 0;
	  
			for(i = 0; i < choices * categories + 4; i++) {
				if(item_status[i] == 'keep') {
					keep++;
				}
			}
      
	  
			if(keep == categories + 1) {
				mash = "You will live in a <b>" + result[categories] + "</b>.<br>";
				mash = mash + "You will drive a <b>" + result[4] + "</b> <b>" + result[2] + "</b>.<br>";
				mash = mash + "You will marry <b>" + result[0] + "</b> and have <b>" + result[1] + "</b> kid(s).<br>";
				mash = mash + "You will be a <b>" + result[5] + "</b> in <b>" + result[3] + "</b>.";
				//message.innerHTML = mash;
				document.getElementById("message").innerHTML = mash;
			} else {
        		setTimeout("move_marker();", 1);
			}
		} else {
      		count++;
      		//document.all.item("item"+(current)).style.backgroundColor = "#FF3333";
			document.getElementById("item"+(current)).style.backgroundColor = "#FF3333";
      		if(current == choices * categories + 3) { 
				current = 0;
			} else { 
				current++;
			}
      		setTimeout("move_marker()", 60);
    	}
	} else {
		if(current == 34) { 
			current = 1;
		} else { 
			current++;
		}
		setTimeout("move_marker();", 1);
	}
}