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()
{
  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 = "#00CCFF";
    }
    for(i = choices * categories + 4; i < choices * (categories + 1); i++) item_status[i] = 'closed';
    message.innerHTML = " Getting your results please stand by...";
    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";
  }
  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;
        document.all.item("item"+(keep)).style.backgroundColor = "#CC9966";
      }
      document.all.item("item"+(current)).style.backgroundColor = "#FFFFFF";
      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 <b>" + result[categories] + "</b>.<br><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> kids.<br><br>";
        mash = mash + "You will be a <b>" + result[5] + "</b> in <b>" + result[3] + "</b>.";
        message.innerHTML = mash;
      }
      else
        setTimeout("move_marker();", 1);
    }
    else
    {
      count++;
      document.all.item("item"+(current)).style.backgroundColor = "#336699";
      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);
  }
}
