// based on original code by ueli weiss (webmaster@kasag.com)(www.kasag.com/uw)
// new code, including streamlining of original and added functionality,
// by kevin kendel (hahciman@rbnet.com)(listen.to/kendel)

  IEtrue = ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4));
  NNtrue = ((navigator.appName == "Netscape") && (parseInt(navigator.appVersion) >= 3));

  OFF = 0;
  ON  = 1;
  sZ  = 40;                        // size of the lights
  whichLevel = 1;                // play level to begin

//  if (document.images)
//    {
//    lights = new Array(2);
//    for (m=0; m<2; m++)
//      lights[m] = new Image();
//    lights[OFF].src = "cynoff.gif";
//    lights[ON].src = "cynon.gif";
//    }

  level = new Array();
  level[1] = [0];
  level[2] = [13];
  level[3] = [7,9,17,19];
  level[4] = [1,9,13,22];

  lightBulb = new Array();

  function initialize(picpath)
    {

    if (document.images)
      {
      lights = new Array(2);
      for (m=0; m<2; m++)
        lights[m] = new Image();
      lights[OFF].src = picpath+"cynoff.gif";
      lights[ON].src = picpath+"cynon.gif";
      }

    for (x=1;x<=25;x++)
      {
      lightBulb[x] = ON;
      document.getElementById("lights_"+x).src = lights[ON].src;
      }
    for(i=0;i<(level[whichLevel].length);i++)
      {
      bulbNum = level[whichLevel][i];
      if (document.images)
        {
        lightBulb[bulbNum] = OFF;
        document.getElementById("lights_"+bulbNum).src = lights[OFF].src;
        }
      }
    calcCounts();
    updateCounts(a,b);
    }

  function flipSwitch(which)
    {
    posArray =  which.split(',');
    i = eval(posArray[0]);
    j = eval(posArray[1]);
    if ((5*(i-1)+j)>0) toggle(5*(i-1)+j);
    if ((5*i+j-1)%5!=0) toggle(5*i+j-1);
    if (5*i+j>0) toggle(5*i+j);
    if ((5*i+j)%5>0) toggle(5*i+j+1);
    if (5*(i+1)+j<26) toggle(5*(i+1)+j);
    checkWin();
    }

  function toggle(bulbNum)
    {
    if (document.images)
      {
      if (lightBulb[bulbNum])
        lightBulb[bulbNum] = OFF;
      else
        lightBulb[bulbNum] = ON;
      document.getElementById("lights_"+bulbNum).src = lights[lightBulb[bulbNum]].src;

      }
    }

  function calcCounts()
    {
    a = 0;
    for (x=1;x<=25;x++)
      a += lightBulb[x];
    b=25-a;
    return(a,b)
    }

  function checkWin()
    {
    calcCounts();
    if (a==0)
      with (window.document.lightGrid)
        onon.value = offoff.value = "Gratuluji!!!!!! :-)))";
    else
      updateCounts(a,b);
    }

  function updateCounts(x,y)
    {
    document.getElementById("lights_t1").value=x;
    document.getElementById("lights_t2").value=y;
    }

