(function($, window){
  "use strict";

  var Application = function() {
    var app = this;

    var $pages = $('.page');

    var log = function() {
      if (app.debug && window.console) {
        Function.prototype.apply.call(window.console.log, window.console,
                                        Array.prototype.slice.call(arguments));
      }
    };

    app.debug = false;

    app.Connection = {
      socket: null,
      active: false,

      start: function(host) {
        log("[Connection] Starting connection to", host);
        this.socket = new window.WebSocket("ws://" + host);
        this.socket.onopen = this.opened;
        this.socket.onclose = this.closed;
      },

      stop: function() {
        this.active = false;
        $(this).trigger("closed");
      },

      opened: function() {
        this.active = true;
        $(this).trigger("connected");
      },

      closed: function() {
        this.stop();
      }
    },

    app.Controllers = {
      _app: app,

      _showOnly: function(id) {
        $pages.not(id).hide();
        return $pages.filter(id).show();
      },

      _getParam: function(key) {
        var query = window.location.search.substring(1),
            vars = query.split('&');
        for (var i = 0; i < vars.length; i++) {
          var pair = vars[i].split('=');
          if (decodeURIComponent(pair[0]) == key) {
            return decodeURIComponent(pair[1]);
          }
        }
      },

      _controllers: {
        index: function($page) {
          var serverHost = this._getParam('server');
          if (!serverHost) {
            log("[Controller] No server address provided");
            $('h2', $page).text('Please supply a server address.');
          } else {
            this._app.Connection.start(serverHost);
            $(this._app.Connection).on('connected', function() {
              app.Controllers.go('build');
            });
          }
        },

        build: function($page) {
        },

        shoot: function($page) {
        }
      },

      go: function(page) {
        log("[Controller] viewing page", page);

        var $page = this._showOnly('#' + page);
        if (page in this._controllers) {
          this._controllers[page].call(this, $page);
        }
      }
    };

    app.start = function(){
      app.debug = !!(app.Controllers._getParam('debug'));
      app.Controllers.go('index');
    };

  };

  window.App = new Application();
  window.App.start();

})(jQuery, window);

@@ -407,22 +407,26 @@
 %7B%0A      
-socket
+connection
 : null,%0A
@@ -552,202 +552,25 @@
 his.
-socket = new window.WebSocket(%22ws://%22 + host);%0A        this.socket.onopen = this.opened;%0A        this.socket.onclose = this.closed;%0A      %7D,%0A%0A      stop: function() %7B%0A        this.active = false
+connection = host
 ;%0A  
@@ -592,20 +592,20 @@
 rigger(%22
-clos
+open
 ed%22);%0A  
@@ -618,22 +618,20 @@
 %0A%0A      
+st
 op
-ened
 : functi
@@ -663,11 +663,12 @@
 e = 
-tru
+fals
 e;%0A 
@@ -696,75 +696,14 @@
 r(%22c
-onnected%22);%0A      %7D,%0A%0A      closed: function() %7B%0A        this.stop(
+losed%22
 );%0A 
@@ -1322,16 +1322,16 @@
 ram(
-'
+%22
 server
-'
+%22
 );%0A 
@@ -1436,12 +1436,12 @@
   $(
-'h2'
+%22h2%22
 , $p
@@ -1450,17 +1450,17 @@
 e).text(
-'
+%22
 Please s
@@ -1482,17 +1482,17 @@
 address.
-'
+%22
 );%0A     
@@ -1509,60 +1509,8 @@
 e %7B%0A
-            this._app.Connection.start(serverHost);%0A
     
@@ -1548,19 +1548,16 @@
 .on(
-'connected'
+%22opened%22
 , fu
@@ -1604,15 +1604,15 @@
 .go(
-'
+%22
 build
-'
+%22
 );%0A 
@@ -1626,16 +1626,68 @@
     %7D);%0A
+            this._app.Connection.start(serverHost);%0A
         

Replace Websocket wtuff with general implementation