/*
 * konami_cmd.js
 * Copyright 2009-2010 ONGS Inc.
 * All rights reserved.
 */

function KONAMI_CMD(launch_func) {
  this.launch = launch_func;
  this._init();
}

KONAMI_CMD.prototype = {
keys: [],
konami: [38,38,40,40,37,39,37,39,66,65],
launch: undefined,
_init: function() {
  addEventListener(document, 'keydown', hitch(this, this.keydown));
},
keydown: function(e) {
  var key;
  if (e && e.which)
    key = e.which;
  else
    key = window.event.keyCode;
  this.keys.push(key);
  if (this.konami[this.keys.length -1] != key) {
    if (key == 38) {
      if (this.keys.length > 2 && this.konami[this.keys.length -2] == key)
        this.keys = [key, key];
      else
        this.keys = [key];
    } else
      this.keys = [];
  } else if (this.keys.length == this.konami.length) {
    if (this.launch)
      this.launch();
    this.keys = [];
  }
}
};

