
var line1 = null, line2 = null, line3 = null, lines = null;
var decorationImage = null, decorationBox = null;
var bodyBrightness = null, boxBrightness = null;
var step = 0;

function intro (delay)
{
  ++step;
  if (step <= 50) {
    var t = step / 50;
    var tc = 1 - t;
    line1.style.left = (1000 * tc) + "px";
    line1.style.letterSpacing = (1000 * tc) + "px";
    if (line1.style.visibility != "visible") {
      line1.style.visibility = "visible";
    }
  } else if (step == 51) {
    line1.style.fontStyle = "normal";
  } else if (step <= 60) {
    ;
  } else if (step <= 110) {
    var t = (step - 60) / 50;
    var tc = 1 - t;
    line2.style.left = (1000 * tc) + "px";
    line2.style.letterSpacing = (1000 * tc) + "px";
    var p1 = t*0.4;
    var p2 = (1 - 2*t*t*t*0.3);
    var p3 = (1 - (Math.pow(2, t)-1)*0.3);
    line2.style.color = "rgb(" + (p1*100) + "%," + (p2*100) + "%," + (p3*100) + "%)";
    if (line2.style.visibility != "visible") {
      line2.style.visibility = "visible";
    }
  } else if (step == 111) {
    line2.style.fontStyle = "normal";
  } else if (step <= 120) {
    ;
  } else if (step <= 170) {
    var t = (step - 120) / 50;
    var tc = 1 - t;
    line3.style.left = (1000 * tc) + "px";
    line3.style.letterSpacing = (1000 * tc) + "px";
    var p1 = (1 - t*t*t*0.3);
    var p2 = (1 - (Math.pow(3, t)-1)/3);
    var p3 = (1 - (t+1)/3);
    line3.style.color = "rgb(" + (p1*100) + "%," + (p2*100) + "%," + (p3*100) + "%)";
    if (line3.style.visibility != "visible") {
      line3.style.visibility = "visible";
    }
  } else if (step == 171) {
    line3.style.fontStyle = "normal";
  } else if (step <= 180) {
  } else if (step <= 230) {
    if (step % 1 == 0) {
      var t = (step - 180) / 50;
      t = t*t*t;
      var ct = 1 - t;
      decorationImage.style.left = (20 * ct) + "%";
      decorationImage.style.top = (-10 * ct) + "%";
      decorationImage.style.width = (100 * t) + "%";
      decorationImage.style.height = (200 * t) + "px";
      if (decorationImage.style.visibility != "visible") {
        decorationImage.style.visibility = "visible";
      }
    }
  } else if (step <= 240) {
    ;
  } else if (step <= 250) {
    if (step % 2 == 0) {
      var t = (step - 240) / 10;
      var ct = 1 - t;
      for (var i = 0; i < 3; ++i) {
        var p = ((bodyBrightness * ct + boxBrightness[i] * t) * 100) + "%";
        decorationBox[i].style.backgroundColor = "rgb(" + p + "," + p + "," + p + ")";
        if (decorationBox[i].style.visibility != "visible") {
          decorationBox[i].style.visibility = "visible";
        }
      }
    }
  } else if (step <= 259) {
    ;
  } else if (step == 260) {
      lines.style.marginLeft = "0px";
      lines.style.borderWidth = "1px";
  } else {
    document.location = "start";
    return;
  }
  setTimeout("intro(" + delay + ");", delay);
}

function initIntro () {
  line1 = getAndHide("line1");
  line2 = getAndHide("line2");
  line3 = getAndHide("line3");
  decorationImage = getAndHide("decorationImage");
  decorationBox = [
    getAndHide("decorationBox1"),
    getAndHide("decorationBox2"),
    getAndHide("decorationBox3")
  ];
  lines = line1.parentNode;
  lines.style.borderWidth = "0px";
  lines.style.marginLeft = "1px";
  lines.style.fontStyle = "italic";
  bodyBrightness = 5*16 / 255;
  boxBrightness = [ (5*16 + 8) / 255, (7*16 + 2) / 255, (6*16 + 2) / 255 ];
  intro(20);
}

function getAndHide (id) {
  var element = document.getElementById(id);
  element.style.visibility = "hidden";
  return element;
}
