var choices = 5;
var categories = 6;
var itemStatus = new Array();
var current = 0;
var count = 1;
var max;
var result = new Array();

function go()
{
  max = parseInt(document.choices.number.value);
  if (!(max > 0))  {
		alert("You must enter your favorite positive number!");
	}
  else if (max > 10) {
		alert("You must enter a number between 1 and 10.");
	}
  else {
    current = 0;
    count = 1;
    for (i = 0; i < choices * categories + 4; i++)
    {
      itemStatus[i] = "open";
      document.all.item("item" + (i)).style.backgroundColor = "#FFFFFF";
    }
    for (i = choices * categories + 4; i < choices * (categories + 1); i++) 
		{
			itemStatus[i] = "closed";
		}
    message.innerHTML = "WORKING...";
    setTimeout("moveMarker();", 1);
  }
}

function moveMarker()
{
  if (current === 0) prev = choices * categories + 3;
  else prev = current - 1;
  if (itemStatus[prev] === "open")
  {
    document.all.item("item"+(prev)).style.backgroundColor = "#FFFFFF";
  }
  if (itemStatus[current] === "open")
  {
    if (count === max)
    {
      itemStatus[current] = "closed";
			document.all.item("item"+(current)).style.backgroundColor = "#716092";
      start = Math.floor( current / choices ) * choices;
      c = 0;
      for(i = start; i < start + choices; i++)
        if(itemStatus[i] === "open")
        {
          c++;
          keep = i;
        }	
      if (c === 1)
      {	
				itemStatus[keep] = "keep";
    		result[Math.floor( keep / choices )] = document.all.item("choice"+keep).value;
        document.all.item("item"+keep).style.backgroundColor = "#ffffff";
      }	
      count = 1;
      keep = 0;
      for (i = 0; i < choices * categories + choices; i++) 
				if (itemStatus[i] === "keep") keep++;
      if (keep === categories + 1)
      {
        mash = "<font face=\"Verdana, Arial, Helvetica, sans-serif\">You will go to <b>" + result[2] + "</b> and be a(n) <b>" + result[0] + "</b>.<br>";
        mash = mash + "You will live in a(n) <b>" + result[categories] + "</b> in <b>" + result[4] + "</b>.<br>";
        mash = mash + "You will marry <b>" + result[1] + "</b> and have <b>" + result[3] + "</b> kids.<br>";
        mash = mash + "You will get around by <b>" + result[5] + "</b>.</font>";
        message.innerHTML = mash;
      }
      else
        setTimeout("moveMarker();", 1);
    }
    else
    {
      count++;
      document.all.item("item"+(current)).style.backgroundColor = "#FF69B4";
      if (current === choices * categories + 4) current = 0;
      else current++;
      setTimeout("moveMarker()", 60);
    }
  }
  else
  {
    if (current === 34) current = 0;
    else current++;
    setTimeout("moveMarker();", 1);
  }
}
