$(document).ready(function(){
  var socket = io();
  var attachFastClick = Origami.fastclick;
  attachFastClick(document.body);

  var DEAD_COLOR = '#eeeeee';
  var TEST_DEAD_COLOR = 'rgb(238, 238, 238)';
  var USER_COLOR = "#000000".replace(/0/g,function(){return (~~(Math.random()*16)).toString(16);});

  window.songjack = window.songjack || {};

  var isMousedown = false;   // Tracks status of mouse button
  $(document).mousedown(function() {
    isMousedown = true;      // When mouse goes down, set isDown to true
  })
  .mouseup(function() {
    isMousedown = false;    // When mouse goes up, set isDown to false
  });

  var colorCell = function(cellData) {
    var jcell = $('#' + cellData.x + '-' + cellData.y);

    jcell.css('background-color', cellData.alive ? cellData.css : DEAD_COLOR);
  }

  //assumes 'this' is the DOM element
  var requestCell = function() {
    //only proceed if cell is dead
    //jquery only returns a stupid rgb string
    if($(this).css("background-color") == TEST_DEAD_COLOR) {
      var coords = $(this).attr('id').split('-');

      socket.emit('requestCell', {
          x: coords[0],
          y: coords[1],
          alive: true,
          css: USER_COLOR
        }
      );
    }
  }

  var setCells = function (cells) {
    cells.forEach(function (cell) {
      window.songjack.game.addCell(cell);
      colorCell(cell);
    });
  }

  var setCursor = function (allowed) {
    document.getElementsByTagName('table')[0].style.cursor = allowed ? 'cell' : 'not-allowed';
  }

  //set up DOM listeners
  $('td').click(requestCell).mousedown(requestCell).mouseover(function () {
    if(isMousedown) {
      requestCell.call(this);
    }
  });

  socket.on('init', function(bundle) {
    window.songjack.game = new window.songjack.GameOfLife(bundle.map.cols, bundle.map.rows);

    setCells(bundle.cells);

    if(bundle.running) {
      window.songjack.gameIntervalID = setInterval(iterateGame, bundle.running);
    }

    setCursor(!bundle.running);
  });

  //set up socket listeners
  socket.on('newCell', function(cellData){
    window.songjack.game.addCell(cellData);
    colorCell(cellData);
  });

  socket.on('setup', function(){

    // clear the current game running id
    if(window.songjack.gameIntervalID) {
        clearInterval(window.songjack.gameIntervalID);
        window.songjack.gameIntervalID = null;
    }

    window.songjack.game.clear();
    $('td').css('background-color', DEAD_COLOR);
    setCursor(true);
  });

  socket.on('simulate', function(bundle){
    window.songjack.game.clear();
    setCells(bundle.cells);
    window.songjack.gameIntervalID = setInterval(iterateGame, bundle.interval);
    setCursor(false);
  });

  socket.on('countdown', function(data){
    var message = data.running ? 'Simulating! Next round in: ' : 'Place your cells! Round starts in: ';
    $('#alert').text(message + data.time);
  });

  var iterateGame = function() {
    var changedCells = window.songjack.game.iterate();

    changedCells.forEach(function(cell) {
      colorCell(cell);
    })
  }
});
@@ -618,24 +618,49 @@
 alse%0A  %7D);%0A%0A
+  //vanilla JS for speed%0A
   var colorC
@@ -698,24 +698,39 @@
 var 
-j
 cell = 
-$('#' + 
+document.getElementById(
 cell
@@ -766,19 +766,19 @@
     
-j
 cell.
-css('
+style.
 back
@@ -783,24 +783,23 @@
 ckground
--c
+C
 olor
-',
+ =
  cellDat
@@ -829,25 +829,24 @@
 : DEAD_COLOR
-)
 ;%0A  %7D%0A%0A  //a
@@ -878,16 +878,43 @@
 element%0A
+  //vanilla JS for speeeed%0A
   var re
@@ -1030,21 +1030,50 @@
  if(
-$(
+!
 this
-).css(%22
+.style.backgroundColor %7C%7C this.style.
 back
@@ -1082,16 +1082,13 @@
 ound
--c
+C
 olor
-%22)
  == 
@@ -1129,26 +1129,15 @@
 s = 
-$(
 this
-).attr('id')
+.id
 .spl

optimize client side code