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

function KONAMI_LAUNCH() {
  this._init();
}

KONAMI_LAUNCH.prototype = {
msg: ["Powered by ONGS Inc.", "Powered by FreeBSD", "How about to consider getting our book?", "Nice Beer", "See you again :)"],
mousepos: undefined,
mode: 0,
curcolor: undefined,
colorinc: undefined,
text: undefined,
timerid: undefined,
_mousemove_event_cb: undefined,
_scroll_event_cb: undefined,
_init: function() {
  this._mousemove_event_cb = hitch(this, this.img_move);
  this._scroll_event_cb = hitch(this, this.img_move);
  this.mousepos = new MousePosition();
},
launch: function() {
  this.mode = (this.mode + 1) % (this.msg.length + 1);
  if (this.mode == 0) {
    this.remove_event();
    this.remove_text();
  } else if (this.mode == 1) {
    this.add_text();
    this.add_event();
    this.img_move();
  } else {
    clearInterval(this.timerid);
    this.text.innerHTML = this.msg[this.mode -1];
    this.timerid = setInterval(hitch(this, this.chg_color), 500);
  }
},
add_text: function() {
  this.curcolor = 0x000000;
  this.colorinc = 0x111111;
  this.text = document.createElement('div');
  this.text.id = 'hoge';
  this.text.style.position = 'absolute';
  this.text.style.color = toColor(this.curcolor);
  this.text.style.margin = '0';
  this.text.style.left = '0';
  this.text.style.right = '0';
  this.text.style.visiblity = 'visible';
  this.text.style.fontSize = '0.8em';
  this.text.innerHTML = this.msg[0];
  document.body.appendChild(this.text);
  this.timerid = setInterval(hitch(this, this.chg_color), 500);
},
remove_text: function() {
  document.body.removeChild(this.text);
  this.text = undefined;
  clearInterval(this.timerid);
  this.timerid = undefined;
},
add_event: function() {
  addEventListener(document, 'mousemove', this._mousemove_event_cb);
  addEventForObjectEvent(window, 'onscroll', this._scroll_event_cb);
},
remove_event: function() {
  removeEventListener(document, 'mousemove', this._mousemove_event_cb);
  removeEventForObjectEvent(window, 'onscroll', this._scroll_event_cb);
},
img_move: function() {
  if (this.text) {
    this.text.style.left = this.mousepos.getX() + 20 + 'px';
    this.text.style.top = this.mousepos.getY() + 5 + 'px';
  }
},
chg_color: function() {
  if (this.text) {
    this.curcolor += this.colorinc;
    if (this.curcolor > 0xffffff) {
      this.curcolor = 0xffffff;
      this.colorinc = -0x111111;
    } else if (this.curcolor < 0) {
      this.curcolor = 0x000000;
      this.colorinc = 0x111111;
    }
    this.text.style.color = toColor(this.curcolor);
  }
}
};

