var Cell = function (x, y)
{
  this.x        = x;
  this.y        = y;
  this.life     = [];
  this.neighbor = [];

  for (var i = 0; i < Cell.INT_AGE_LENGTH; ++i)
  {
    this.life[i] = false;
  }
}

// STATICs
// ________________________________________________________________________

Cell.INT_AGE_LENGTH = 2;

// SCRATCH PADS
// _______________________________________________________________________





























// VIEW METHODS
// _______________________________________________________________________

Cell.prototype.turn = function ()
{
  //console.log('cell:', this.x, this.y);
  var c = 0;
  for (var i = 0, len = this.neighbor.length; i < len; ++i)
  {
    if (this.neighbor[i].getLife(1))
    {
      ++c;
    }
  }
  //console.log(temp);
  //console.log('cell:', this.x, this.y, ' => ', c);
  switch (true)
  {
    case (c === 3):
      this.life[0] = true;
    break;
    case (c === 2):
      this.life[0] = this.life[1];
    break;
    default:
      this.life[0] = false;
    break;
  }
  return this.life[0];
}


// UTILITY METHODS
// _______________________________________________________________________


Cell.prototype.getLife = function (age)
{
  age = age || 0;
  return this.life[age];
}


Cell.prototype.on = function ()
{
  this.life[0] = true;
}


Cell.prototype.off = function ()
{
  this.life[0] = false;
}


Cell.prototype.setNeighbor = function (cell)
{
//  if (this.neighbor.length >= 9)
//  {
//    throw new Error('to many neighbors');
//  }
  this.neighbor[this.neighbor.length] = cell;
}


Cell.prototype.shiftAge = function ()
{
  this.life.pop();
  this.life.unshift(false);
}


Cell.prototype.toggle = function ()
{
  this.life[0] = !this.life[0];
  //console.log('toggling: ', this.x, this.y, (this.life[0]?'true':'false'));
}



