(function() {
  var Car = Class.create();
  Car.prototype = {
    initialize: function() {
      this.elm = document.createElement('img');
      this.size = 50;
      this.top = 100;
      this.left = -this.size;
      this.xSpeed = 10;
      this.ySpeed = 11;
      this.elm.src = '/images/car.png';
      this.elm.style.position = 'absolute';
    },
    show: function() {
      if (this.elm) {
        this.elm.width = this.size;
        this.elm.style.top = Math.floor(this.top) + 'px';
        this.elm.style.left = Math.floor(this.left) + 'px';
      }
    },
    step: function() {
      setTimeout(function(){this.move(); this.show();}.bind(this), 100);
    },
    move: function() {
      this.size *= 1.2;
      this.top += this.xSpeed;
      this.left += this.ySpeed;
      this.xSpeed *= 1.05;
      this.ySpeed *= 1.05;
      if (this.left < 1000) {
        this.step();
      }
      else {
        this.reset();
      }
    },
    reset: function() {
      if (this.elm) {
        this.elm.parentNode.removeChild(this.elm);
        this.elm = null;
      }
    }
  };

  var k = ProtoCommand.keys;
  var konami = new ProtoCommand();
  konami.setCommand([k.up, k.up, k.down, k.down, k.left, k.right, k.left, k.right, k.b, k.a]);
  konami.action = function() {
    if (this.car) {
      this.car.reset();
    }
    this.car = new Car;
    this.car.show();
    document.body.appendChild(this.car.elm);
    this.car.step();
  }.bind(konami);
  konami.reset = function() {
    if (!this.car) return;
    this.car.reset();
    this.car = null;
  }.bind(konami);

  var help = new ProtoCommand();
  help.setCommand([k.h, k.e, k.l, k.p, k.up]);
  help.link('http://mondju-help.seesaa.net/');

  var search = new ProtoCommand();
  search.setCommand([k.s, k.e, k.a, k.r, k.c, k.h]);
  search.link('http://mondju.com/blog_networks/search');

  ProtoCommand.observeAll();
})();
