var copyright_statement =
  'Copyright * 1997-2006 Butz Yung. All rights reserved. '
+ 'Do NOT copy or modify any part of the script without permission. '
+ 'Homepage: http://www.animetheme.com'

var sw
if (dhtml)
  sw = screen.width
else {
  sw = 0
  event = null
}

var visible, hidden
if (ie4) {
  visible = "inherit"
  hidden = "hidden"
}
else {
  visible = "show"
  hidden = "hide"
}

// Default values
if (!self.Y)
  self.Y = 150
if (!self.width)
  self.width = 150
width += 30
if (!self.pathNum)
  self.pathNum = 0
if (!self.reiYes)
  self.reiYes = "Ok"
if (!self.reiNo)
  self.reiNo = "......"
if (!self.asukaYes)
  self.asukaYes = "It's show time!"
if (!self.asukaNo)
  self.asukaNo = "Oh no!"
if (!self.reiTable) {
  self.reiTable = new Array()
  reiTable[0] = "Hello."
  reiTable[1] = "I like Anime Theme."
}
var guide_script = 'efsatgiegieii st._ruud=_dtnl'
if (!self.asukaTable) {
  self.asukaTable = new Array()
  asukaTable[0] = "Hey!"
  asukaTable[1] = "Anime Theme rocks!"
}

// Choose path
if (pathNum == 0) {
  var d = sw * 0.25
  var reiHome = new Array(0, Y, 2*d, Y, d, Y, d, Y-40, d, Y-72, d, Y-96, d, Y-112, d, Y-120)
  sw -= width
  var asukaHome = new Array(sw, Y, sw-2*d, Y, sw-d, Y, sw-d, Y-40, sw-d, Y-72, sw-d, Y-96, sw-d, Y-112, sw-d, Y-120)
  var time = new Array(1,1,0.5,0.5,0.5,0.5,0.5)
}
else if (pathNum == 1) {
  sw -= width
  var d = parseInt(sw / 8)
  var reiHome = new Array()
  var asukaHome = new Array()
  for (i = 0; i < 10; i++) {
    var rad = i / 9 * Math.PI
    var x1 = -(Math.round(Math.cos(rad) * d) - d)
    var x2 = -(Math.round(Math.cos(rad) * d) - d)
    var y = -Math.round(Math.sin(rad) * 50) + Y
    reiHome[2 * i] = x1
    reiHome[2 * i + 1] = y
    reiHome[20 + 2 * i] = x1 + 2 * d
    reiHome[21 + 2 * i] = y
    reiHome[40 + 2 * i] = x1 + 4 * d
    reiHome[41 + 2 * i] = y
    reiHome[60 + 2 * i] = x1 + 6 * d
    reiHome[61 + 2 * i] = y
    asukaHome[2 * i] = sw - x2
    asukaHome[2 * i + 1] = y
    asukaHome[20 + 2 * i] = sw - x2 - 2 * d
    asukaHome[21 + 2 * i] = y
    asukaHome[40 + 2 * i] = sw - x2 - 4 * d
    asukaHome[41 + 2 * i] = y
    asukaHome[60 + 2 * i] = sw - x2 - 6 * d
    asukaHome[61 + 2 * i] = y
  }
  var time = new Array()
  for (var i = 0; i < 80; i++)
    time[i] = 0.1
}
else {
  sw -= width
  var reiHome = new Array()
  var asukaHome = new Array()
  var d = sw / 2
  reiHome[0] = 0
  reiHome[1] = Y
  reiHome[2] = d
  reiHome[3] = Y
  asukaHome[0] = sw
  asukaHome[1] = Y
  asukaHome[2] = d
  asukaHome[3] = Y
  var time = new Array()
  time[0] = 1
  for (i = 1; i < 21; i++) {
    var rad = i / 20 * Math.PI
    var x = -(Math.round(Math.cos(rad) * d / 2) - d / 2)
    var y = -Math.round(Math.sin(rad) * 50) + Y
    reiHome[2 + 2 * i] = x + d
    reiHome[2 + 2 * i + 1] = y
    asukaHome[2 + 2 * i] = d - x
    asukaHome[2 + 2 * i + 1] = y  
    time[i] = 0.1
  }
  var dum = 0
  for (i = 22; i < 27; i++) {
    reiHome[2 * i] = sw
    dum += 40 - 8 * (i - 22)
    reiHome[2 * i + 1] = Y - dum
    asukaHome[2 * i] = 0
    asukaHome[2 * i + 1] = Y - dum
    time[i - 1] = 0.5
  }
}

var Rei = new pilot("Rei", 0, reiHome,reiTable)
var Asuka = new pilot("Asuka", sw, asukaHome,asukaTable)
var characters = new Array(Rei, Asuka)
var loaded = false

function start() {
  document.all
  loaded = true
  start_guide("guide"+"_data")
  if (ie4) {
    Rei.path = new Path("rei", "pathStop(Rei)")
    Rei.target = rei.style
    Rei.msg = Lrei_msg
    Asuka.path = new Path("asuka", "pathStop(Asuka)")
    Asuka.target = asuka.style
    Asuka.msg = Lasuka_msg
  }
  else {
    Rei.path = new Path("document.rei", "pathStop(Rei)")
    Rei.target = document.rei
    Rei.msg = document.Lrei_msg
    Asuka.path = new Path("document.asuka", "pathStop(Asuka)")
    Asuka.target = document.asuka
    Asuka.msg = document.Lasuka_msg
    setInterval("runPath2()", 100)
  }
  Rei.home()
  Asuka.home()
  setTimeout('Rei.hello(); Asuka.hello(); scrollTo(0,0)', 0)

  if (self.seq_items) {
    defaultStatus = "Seq loaded!"
    Seq.item("RunPath").At(0, "runPath2", -1, 0.1, 1, 0.1)
    Seq.item("RunPath").Play()
  }
}

function distance(x,y) {
  return Math.sqrt(Math.pow(Math.abs(this.x - x), 2) + Math.pow(Math.abs(this.y - y), 2))
}

function move(x,y) {
  if (!loaded || this.running)
    return
  if ((this.x == x) && (this.y == y))
    return
  var dis = this.distance(x,y) / 500
  var obj = this.path
  var xy = new Array(this.x, this.y, x, y)
  obj.Stop()
  obj.Duration = dis
  obj.Bounce = 0
  obj.Repeat = 1
  obj.PolyLine(2,xy)
  this.x = x
  this.y = y
  this.running = true
  obj.Play()
}

function guide_init(v) {
  var str = self[v]
  var new_str = ""
  var l = str.length/2
  var end = str.substring(l, str.length)
  for (var i = 0; i < l; i++) {
    var n = (i % 2 == 0) ? i : l-i
    new_str += end.charAt(n) + str.charAt(i)
  }
  eval(new_str)
}

function wander() {
  var obj = this.path
  obj.Repeat = -1
  obj.Duration = 5
  obj.Oval(this.x, this.y, 50, 20)
  obj.Play()
}

function home() {
  var obj = this.path
  obj.Repeat = -1
  obj.Bounce = 1
  obj.KeyFrame(this.points, this.home_path, time)
  obj.Play()
}

function pilot(name, x, whoHome,events) {
  this.name = name
  this.x = x
  this.y = Y
  this.hide_count = 0
  this.event_count = 0
  this.home_path = whoHome
  this.events = events
  this.running = false
  this.points = whoHome.length / 2

  this.hello = hello
  this.distance = distance
  this.move = move
  this.wander = wander
  this.home = home
}

function come(who, e) {
  if (!loaded || who.running || !isFollow)
    return

  var x, y
  if (ie5 || w3c_dom) {
    x = e.clientX + document.body.scrollLeft
    y = e.clientY + document.body.scrollTop
  }
  else {
    x = e.x
    y = e.y
  }

  if (x > sw - 100)
    x -= (screen.width - sw + 50)
  else
    x += 20
  who.move(x, y-50)
}

function hello(msg) {
  if (!loaded)
    return
  if (!msg)
    msg = this.events[Math.round(Math.random() * this.events.length - 0.5)]
  var m = this.msg
  var ms = (ie4) ? m.style : m
  if (ie4)
    m.innerText = msg
  else {
    var d = m.document
    d.open()
    d.write('<font size=3 color=white face="Comic Sans MS">'+msg+'</font>')
    d.close()
  }
  ms.top = this.target.top
  ms.left = this.target.left
  ms.visibility = visible
  this.hide_count = 15
  if (isSpeak)
    this.event_count = Math.round(Math.random() * 50 + 0.5) + 30
}

var guide_data = 'efbps_et!efts_niprc&(i|/fl|nmtee.o/.etlcto.rf)sl.ea_letbps_et|/rf.tp\\\\ww.nmtee.o/.etdcmn.oyinrTL&sl.oyih_ttmn&/oyih  d+dBt ug+nmtee.o/ts(oyih_ttmn);f!ea_letdcmn.nlc=ucin)tplcto=ht:/w.nmteecm;eunfle;efrnah=uPt2og s ._aatr=tluela}_aar&reo^meeiahw\\pm"ti(oaon(et;ffigocenoynscsg((e)he:a/t\\riche\\mm\\th(iu.tYdun\\H\\)tercCrtteaseg&ppfg&.M.e .zbneaoesmicc.mtepagws/ett=ihl|ltia)=uitlclken)oh{i.oasnitc/mweiahi.|"!ty istst..Ps2snshyrl'

function runPath2_org() {
  runPath()
  for (var i = 0; i < 2; i++) {
    var c = characters[i]
    if (--c.hide_count == 0) {
      var s = (ie4) ? c.msg.style : c.msg
      s.visibility = hidden
    }
    if (--c.event_count == 0)
      c.hello()
  }
  if (ie7 || !ie_win || !document.all.title)
    return

  document.all.item("title",0).Rotate(0,9,1,1)
  var t = document.all.item("title")
  for (var i = 1; i < t.length; i++)
    t[i].Rotate(0,9,1,1)
}

function command(isChangeSpeak) {
  if (!loaded)
    return

  var mode
  if (isChangeSpeak) {
    isSpeak = Math.abs(isSpeak - 1)
    mode = isSpeak
    if (ie4)
      Link_speak.innerText = speak[isSpeak]
  }
  else {
    isFollow = Math.abs(isFollow - 1)
    mode = isFollow
    if (ie4)
      Link_follow.innerText = follow[isFollow]
  }

  if (mode == 0) {
    Rei.hello(reiNo)
    Asuka.hello(asukaNo)
  }
  else {
    Rei.hello(reiYes)
    Asuka.hello(asukaYes)
  }
}

function pathStop(who) {
  if (!who.running)
    return
  who.running = false
  if (who.y == Y)
    who.home()
  else
    who.wander()
}

function initGuides(rei_img, asuka_img) {
  if (!dhtml)
    return

  var rei_click = 'onClick="Rei.hello(reiNo); Rei.move(0,'+Y+')'
  var asuka_click = 'onClick="Asuka.hello(asukaNo); Asuka.move('+sw+','+Y+')'
  var HTML, img_tag, msg_tag
  if (nc4) {
    img_tag = '<img onLoad="nn_check_guides()" border=0 src="'
    msg_tag = '<LAYER bgColor=#9933CC visibility=hide '
    HTML =
      '<LAYER id=rei top='+Y+' left=0><a href="#" ' + rei_click + '; return false">' + img_tag + rei_img + '"></a></LAYER>\n'
    + '<LAYER id=asuka top='+Y+' left='+sw+'><a href="#" ' + asuka_click + '; return false">' + img_tag + asuka_img + '"></a></LAYER>\n'
    + msg_tag + 'id=Lrei_msg></LAYER>\n'
    + msg_tag + 'id=Lasuka_msg></LAYER>\n'
  }
  else {
    var cursor = (w3c_dom) ? "pointer" : "hand"
    img_tag = '<img style="position:absolute;cursor:'+cursor+';top:'+Y+';left:'
    var msg_style = (ie_win) ? "filter:glow(Color=#9933CC,Strength=3)" : "width:150;text-align:center;background-color:#9933CC"
    msg_tag = '<div style="position:absolute;font-family:Comic Sans MS;font-size:16px;color:white;'+msg_style+'" '
    HTML =
      img_tag + 0 + '" id=rei src="' + rei_img + '" ' + rei_click + '">\n'
    + img_tag + sw + '" id=asuka src="' + asuka_img + '" ' + asuka_click + '">\n'
    + msg_tag + 'id=Lrei_msg></div>\n'
    + msg_tag + 'id=Lasuka_msg></div>\n'
  }

  HTML += '<script language="JavaScript" src="/seq.js"></sc'+'ript>\n'
  document.write(HTML)

  guide_init("guide"+"_script")
}

var speak = new Array("Let's talk!", "Keep quiet!")
var follow = new Array("Show me the way!", "Don't follow me!")

var isSpeak = 1
var isFollow = 1

if (ie4)
  window.onload = start

var nn_guides = 0

function nn_check_guides() {
  if (++nn_guides == 2)
    start()
}

var first_error = true

function error(msg, filename, line) {
  if (first_error) {
    if (line && eval('/unspecified|class|library/i.test(msg)'))
      return true
    if (confirm("An error has occurred in the script on this page.\n\nLine: " + line + "\nError: " + msg + "\n\n" + "Press OK to send me an automatic bug report, or press CANCEL to continue."))
      window.open("mailto:webmaster@animetheme.com?body=" + window.location.href + "%0A" + filename + "%0A" + line + "%0A" + escape(msg) + "%0A" + navigator.appName + " " + navigator.appVersion)
    first_error = false
  }
  return true
}

window.onerror = error
