/*
 * Run a parade of cells, swapping colors. And other stupid tricks with a timer...
 *
 * tested and working under:
 * Windows: IE4 + IE5, Mozilla 0.91, Opera 6
 * (not working under Opera 5 and Netscape 4.7)
 *
 * Mac: IE5
 *
 * Script copyright 2000/2001 jalal @ gnomedia.
 *
 * $Id: parader.js,v 1.2 2001/12/26 09:48:36 jalal Exp $
 *
 */
var allIDs = document.all;

function init() {
  var i;
  var j;
  for( j = 0; j < numGroups; j++ ) {
    for( i = 0; i < numCells; i++ ) {
      if( document.getElementById ) {
        eval( "document.getElementById('cell_" + j + i + "').style.backgroundColor = colors[" + i + "];" );
      }
      else if( document.all ) {
        eval( "allIDs['cell_" + j + i + "'].style.backgroundColor = colors[" + i + "];" );
      }
    }
  }
  loopTimer();
}

function loopTimer() {
  if( loopTime <= 0 ) return;
  var j;
  for( j = 0; j < numGroups; j++ ) {
    swapCells( j, randomInt( 0, numCells-1 ));
  }
  setTimeout( "loopTimer()", loopTime );
}

function swapCells( group, cell ){
  var next = (cell + 1) % numCells;
  var c1;  var c2;
  if( document.getElementById ) {
    c1 = eval( "document.getElementById('cell_" + group + cell + "').style.backgroundColor");
    c2 = eval( "document.getElementById('cell_" + group + next + "').style.backgroundColor");
    //alert("c1=" + document.getElementById('cell_01').style.backgroundColor + " c2=" + c2);
    eval( "document.getElementById('cell_" + group + cell + "').style.backgroundColor = '" + c2 + "'" );
    eval( "document.getElementById('cell_" + group + next + "').style.backgroundColor = '" + c1 + "'");
  }
  else if( document.all ){
    c1 = eval( "allIDs['cell_" + group + cell + "'].style.backgroundColor");
    c2 = eval( "allIDs['cell_" + group + next + "'].style.backgroundColor");
    eval( "allIDs['cell_" + group + cell + "'].style.backgroundColor = '" + c2 + "'" );
    eval( "allIDs['cell_" + group + next + "'].style.backgroundColor = '" + c1 + "'");
  }
}

// return an integer between (including)
// min and max.
function randomInt( min, max ) {
  return Math.round( Math.random() * (max - min) + min );
}

function shuffleColors() {
  var x = colors.shift();
  colors.push(x);
}


