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

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

    app.debug = false;
    app.WEAPON_APPEARING_INTERVAL = 100;
    app.WEAPON_COMBINATION_SIZE = 3;
    app.SHOOTING_TIME = 1000;

    app.$templates = $('.template').hide();
    app.$content   = $('#content');

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

    app.$ = function(selector) {
      return $(selector, app.$content);
    };

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

      start: function(host) {
        log("[Connection] Starting connection to", host);
        this.connection = host;
        $(this).trigger("opened");
      },

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

    app.Controllers = {
      _app: app,

      _render: function(id) {
        var $template = app.$templates.filter(id);
        app.$content.html($template.html());
      },

      _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() {
          var app = this._app;

          var serverHost = this._getParam("server");
          if (!serverHost) {
            log("[Controller] [index] No server address provided");
            app.$("h2").text("Please supply a server address.");

          } else {
            $(app.Connection).on("opened", function() {
              app.Controllers.go("build");
            });
            app.Connection.start(serverHost);
          }
        },

        build: function() {
          // show weapons one-by-one
          var app = this._app;
          var $weapons = app.$("#weapons button");
          var addWeapon = function() {
            var $hidden = $weapons.filter(".hidden");
            var random = Math.round(Math.random() * $hidden.length-1);
            $hidden.eq(random).removeClass("hidden");
          };
          $weapons.addClass("hidden");
          window.setInterval(addWeapon, this._app.WEAPON_APPEARING_INTERVAL);

          // weapon construction
          var selectedWeapons = [];
          $weapons.on('click', function() {
            var weapon = $(this).text();
            selectedWeapons.push(weapon);
            log("[Controller] [build] weapons selected:", selectedWeapons);

            $(this).attr('disabled', true);

            if (selectedWeapons.length >= 3) { // time to shoot
              app.Controllers.go('shoot', { weapons: selectedWeapons });
            }
          });
        },

        shoot: function(params) {
          var app = this._app;

          log("[Controller] [Shoot] Shooting with weapons", params.weapons);
        }
      },

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

        this._render('#' + page);
        if (page in this._controllers) {
          this._controllers[page].call(this, params);
        }
      }
    };

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

  };

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

})(jQuery, window);

@@ -800,16 +800,28 @@
 ection =
+ %22http://%22 +
  host;%0A 
@@ -949,24 +949,184 @@
 (%22closed%22);%0A
+      %7D,%0A%0A      send: function(data) %7B%0A        log(%22%5BConnection%5D Sending to server%22, data);%0A        $.ajax(this.connection, %7B dataType: %22jsonp%22, data: data %7D);%0A
       %7D%0A    
@@ -3290,16 +3290,320 @@
 eapons);
+%0A%0A          // send fire%0A          app.Connection.send(%7B%0A            w: params.weapons.join(',')%0A          %7D);%0A%0A          // go back after shooting time ended%0A          var goBack = function() %7B%0A            app.Controllers.go('build');%0A          %7D;%0A          window.setTimeout(goBack, app.SHOOTING_TIME);
 %0A       

Fix sending fire action