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()
{
	$("div#resultsMash").html();
  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.getElementById("item"+(i)).style.backgroundColor = "#FFFFFF";
    }
    for(i = choices * categories + 4; i < choices * (categories + 1); i++) item_status[i] = 'closed';
    
    $("div#reultsMash").html("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.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)] = $('[name=choice'+keep+']').val()
        document.getElementById("item"+(keep)).style.backgroundColor = "#FFFFCC";
      }
      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 <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> kids.<br>";
        mash = mash + "You will be a <b>" + result[5] + "</b> in <b>" + result[3] + "</b>.";
        
        $("div#resultsMash").html(mash);
      }
      else
        setTimeout("move_marker();", 1);
    }
    else
    {
      count++;
      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);
  }
}
