var copyright_statement =
  'Copyright * 1997-2008 Butz Yung. All rights reserved. '
+ 'Do NOT copy or modify any part of the script without permission. '
+ 'Homepage: http://www.animetheme.com'

if (!self.default_msg)
  self.default_msg = "Click me once more and I'll bring you there~!"
if (!self.ok_msg)
  self.ok_msg = "Ok let's go~!"
if (!self.reiTable)
  self.reiTable = new Array("Welcome~!")
if (!self.msg_leave)
  self.msg_leave = "Ok...bye then. When you need me, press again~!"
if (!self.gtext_run)
  self.gtext_run = "I need you, Guide Lady!"
if (!self.gtext_stop)
  self.gtext_stop = "Can you leave, Guide Lady?"
if (!self.msg_coming)
  self.msg_coming = "A new guide is coming. Please wait for a while~!"
if (!self.msg_hello)
  self.msg_hello = "Hello~!"
if (!self.cloud_path)
  self.cloud_path = ""
var guide_script = 'efsatgiegieii st._ruud=_dtnl'
cloud_path += "guide_cloud.gif"

defaultStatus = "Anime Theme (animetheme.com)"

var use_AIL = !!ie6

var guide_resizable = (use_AIL || w3c_dom)

if (!dhtml)
  event = null

var Rei = new pilot("Rei", reiTable)
var reiPath = null
var loaded = false

var visible, hidden
if (ie4) {
  visible = "inherit"
  hidden = "hidden"
}
else {
  visible = "show"
  hidden = "hide"
}

var g_width, g_height, gw_offset, gh_offset, guide_count, nc4_seqTimerID

function calcDim() {
  var ws = Rei.width
  var hs = Rei.height
  for (var i = 0; i < 2; i++) {
    var w = parseInt(guides_img[guide_count][i].width)
    var h = parseInt(guides_img[guide_count][i].height)
    ws[i] = (w) ? w : 150
    hs[i] = (h) ? h : 300
  }
  g_width = (ws[0] > ws[1]) ? ws[0] : ws[1]
  g_height = (hs[0] > hs[1]) ? hs[0] : hs[1]
  gw_offset = g_width + 167
  gh_offset = g_height + 10
}

function nn_write(num) {
  var v = new Array("hide", "show")
  var l = document.rei.document.layers
  for (var i = 0; i < 2; i++) {
    var r = l[i]
    r.visibility = v[i]
    r = r.document
    r.open()
    r.write('<a href="#" onMouseDown="return clickGuide(event)" onClick="introduce(event); return false"><img border=0 src="' + guides[num] + '0' + i + '.gif"></a>')
    r.close()
  }
  document.rei.resizeTo(g_width, g_height)
}

function start() {
  nn_guides = 3

if (ie55) {
  for (var i = 0 ; i < 2; i++) {
    var g = guides_img[guide_count]
    if (!g[i].complete) {
      nn_guides--
      g[i].onload = nn_check_guides
    }
  }
  if (nn_guides < 3) {
    defaultStatus = "Loading Guides for IE"
    return
  }
}

  start2()
}

function start2() {
  defaultStatus = "Guides loaded!"

  document.all
  calcDim()
  if (ie4) {
    if (w3c_dom) {
      var nodes = Lsystem.childNodes
      for (var i = 0; i < nodes.length; i++) {
        var n = nodes[i]
        if (n.tagName)
          n.innerText = n.innerText
      }
    }

    var img1 = guides_img[guide_count][1]
    var img0 = guides_img[guide_count][0]

    if (use_AIL) {
      rei.innerHTML =
  '<div id=Irei1 style="position:absolute; width:' + (img1.width+0) + 'px; height:' + (img1.height+0) + 'px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + img1.src + '\', sizingMethod=\'scale\')"></div>\n'
+ '<div id=Irei0 style="position:absolute; width:' + (img0.width+0) + 'px; height:' + (img0.height+0) + 'px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + img0.src + '\', sizingMethod=\'scale\'); visibility:hidden"></div>'
    }
    else {
      rei.innerHTML =
  '<img id=Irei1 src="' + img1.src + '" style="position:absolute; width:' + (img1.width+0) + 'px; height:' + (img1.height+0) + 'px" GALLERYIMG="no">\n'
+ '<img id=Irei0 src="' + img0.src + '" style="position:absolute; width:' + (img0.width+0) + 'px; height:' + (img0.height+0) + 'px; visibility:hidden" GALLERYIMG="no">'
    }
  }
  else
    nn_write(guide_count)
  start_guide("guide"+"_data")
  setTimeout("initGuide()", 100)
}

function clickGuide(e) {
  if (ie5 || w3c_dom)
    return true

  var b = (ie4) ? e.button : e.which
  if (b < 2)
    return true
  alert("Why do you want to click on me? ^_^;")
  return false
}

function initGuide() {
  loaded = true

  if (use_AIL) {
    Irei0.src = Irei0.filters(0).src
    Irei1.src = Irei1.filters(0).src
  }

  if (ie4) {
    reiPath = new Path("rei", "pathStop")
    Rei.target = rei.style
    Rei.msg = Lrei.style
    Rei.img = document.all.Irei1

    rei.style.cursor = (w3c_dom) ? "pointer" : "hand"
    rei.onmousedown = new Function("e", "if (!e) {e = event}; return clickGuide(e)")
    rei.oncontextmenu = new Function("e", "introduce(e); return false")
    rei.onclick = introduce
  }
  else {
    reiPath = new Path("document.rei", "pathStop")
    Rei.target = document.rei
    Rei.msg = document.Lrei
    Rei.img = new Object()
    Rei.img.src = guides_img[guide_count][1].src
    Rei.img.watch("src", nn_assignImage)
    nc4_seqTimerID = setInterval('runPath2()', 100)
  }

  calcBodyDim()
  if (Rei.x > body_w)
    Rei.x = body_w
  Rei.y += body_sh
  if (Rei.y > body_h)
    Rei.y = body_h

  Rei.target.visibility = visible
  wander()
  hello(Rei.events[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 nn_assignImage(id, old_v, new_v) {
  var l = document.rei.document.layers
  var active_img = (new_v.indexOf("00.gif") != -1) ? 0 : 1
  l[active_img].visibility = "show"
  l[Math.abs(active_img-1)].visibility = "hide"
  return new_v
}

function distance(x, y) {
  return Math.sqrt(Math.pow(Math.abs(Rei.x - x), 2) + Math.pow(Math.abs(Rei.y - y), 2))
}

function move(x, y) {
  var xy = new Array(Rei.x, Rei.y, x, y)
  reiPath.Stop()
  reiPath.Duration = distance(x, y) / 500
  reiPath.Bounce = 0
  reiPath.Repeat = 1
  reiPath.PolyLine(2,xy)
  Rei.x = x
  Rei.y = y
  Rei.moving = true
  reiPath.Play()
}

function wander() {
  reiPath.Repeat = -1
  reiPath.Duration = 5
  reiPath.Oval(Rei.x, Rei.y, 50, 20)
  reiPath.Play()
}

function pilot(name, events) {
  this.name = name
  this.x = 50
  this.y = 50
  this.width = new Array()
  this.height = new Array()
  this.event_count = 0
  this.hide_count = 0
  this.guide_count = 0
  this.events = events
  this.intros = new Array(events[0])
  this.moving = false
}

function returnXY(e) {
  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
  }

  return new Array(x, y)
}

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 come(intros, e, link) {
  if (!loaded || Rei.running || (Rei.intros[0] == intros[0]))
    return

  if (Rei.moving) {
    Rei.moving = false

    Rei.x = Rei.target.posLeft
    Rei.y = Rei.target.posTop
  }

  hideMenu()

  Rei.intros = intros
  Rei.link = (link) ? link : null
  Rei.clicked = false

  var x, y
  var xy = returnXY(e)
  x = xy[0]
  y = xy[1]

  calcBodyDim()
  if (x < gw_offset) {
    x += 50
    if (x > body_w)
      x = body_w
    y += 100
  }
  else
    x -= gw_offset

  y -= 50
  if (y < body_sh + 10)
    y = body_sh + 10

  if (y > body_h)
    y = body_h

  Rei.guide_count = 0

if (ie4) {
  Rei.img = document.all.Irei0
  Rei.img.style.visibility = visible
  document.all.Irei1.style.visibility = hidden
}
else
  Rei.img.src = guides_img[guide_count][0].src

  move(x, y)
}

var body_w, body_h, body_sw, body_sh

function calcBodyDim() {
  if (ie) {
    body_w = document.body.clientWidth
    body_sw = document.body.scrollLeft
    body_h = document.body.clientHeight
    body_sh = document.body.scrollTop
  }
  else {
    body_w = window.innerWidth
    body_sw = window.pageXOffset
    body_h = window.innerHeight
    body_sh = window.pageYOffset
  }
  body_w += body_sw - gw_offset
  body_h += body_sh - gh_offset
}

var msg_full

function hello_org(msg) {
  if (!msg) {
    var target = (Math.random() > 0.5) ? Rei.events : Rei.intros
    msg = target[random(target)]
  }

  var p = msg.indexOf("||")
  if (p != -1) {
    msg_full = msg
    if (msg.indexOf("//") != -1) {
      var exp_end = msg.lastIndexOf("//")
      var exp = eval(msg.substring(1, exp_end+1))
      msg = (exp.test(Rei.img.src)) ? msg.substring(exp_end+2, p) : msg.substring(p+2, msg.length)
    }
    else
      msg = (Rei.img.src.indexOf("00.") != -1) ? msg.substring(0, p) : msg.substring(p+2, msg.length)
  }
  else
    msg_full = ""

  if (ie4)
    Lrei_msg.innerText = msg
  else {
    var d = document.Lrei.document.Lrei_msg.document
    d.open()
    d.write('<LAYER style="font-family:Comic Sans MS;font-size:14px;color:black">' + msg + '</LAYER>')
    d.close()
  }
  Rei.msg.top = parseInt(Rei.target.top) + (g_height - 103) / 2
  Rei.msg.left = parseInt(Rei.target.left) + g_width - 50
  Rei.msg.visibility = visible
  Rei.hide_count = 20
  Rei.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;efhlohloogsr.la=te=ll}eaar_rao&mee^aewiph"\\imoto((atnfei;ofegocnncygs(s)(eeaht:r/c\\eimh\\\\hmit.(Yuut\\d\\ntHr)Cetcerstgapef&&pMge...b ezonsaiecmmce.atwp/gts=eht|itlal=ii)lultec)khnioo{s.iacnmte/awii|h!.y"itt ts.ss.slsey_l'

var custom_e = new CustomEvent()
function CustomEvent() {
  this.tagName = "A"
  this.button = 1
  this.which = 1
}

function introduce(e) {
  if (!loaded || Rei.moving)
    return

  hideMenu()

if (Rei.link && Rei.clicked) {
  Rei.clicked = false

  var l = Rei.link
  custom_e.href = l.href
  custom_e.target = l.target

  var func = (ie4) ? document.onmousedown : window.onmousedown
  if (func) {
    if (func(custom_e, true) == false)
      return

    l.href = custom_e.href
    l.target = custom_e.target
  }

  func = l.onclick
  if (w3c_dom && !func) {
    func = l.getAttribute("onclick")
    if (func)
      func = new Function(func)
  }

  if (func) {
    if (!confirmAction(l, true))
      return
    if (func() == false)
      return
  }
  else if (!confirmAction(l))
    return

  var t
  if ((!l.target) || (l.target.indexOf("self") != -1))
    t = self
  else if (l.target.indexOf("top") != -1)
    t = top
  else if (l.target.indexOf("parent") != -1)
    t = parent
  else {
    window.open(l.href)
    return
  }

  hello(ok_msg)
  t.location = l.href
  return
}

  if (ie4 && (Rei.link || !Rei.clicked)) {
    if (!e)
      e = event

    Saction.style.display = (Rei.link) ? "block" : "none"

    var ls = Lsystem.style
    var xy = returnXY(e)
    ls.posLeft = xy[0]
    ls.posTop = xy[1]
    ls.visibility = "inherit"
  }
  else if (Rei.link) {
    Rei.clicked = true
    hello(default_msg)
  }
  else {
    Rei.clicked = false
    hello(Rei.intros[random(Rei.intros)])
  }
}

function confirmAction(l, isAction) {
  if (!ie4)
    return true

  var txt = l.innerText
  var link_msg
  if (txt) {
    txt = "<" + txt + ">"
    link_msg = "following link.\n\n"
  }
  else {
    link_msg = "image link that the guide is currently on."
    if (!isAction)
      link_msg += "\n"
  }

  var msg
  msg = (isAction) ? "This will perform the action of the " + link_msg + txt : "This will bring you to the destination of the " + link_msg + txt + "\nURL: " + l.href
  msg += "\n\nAre you sure?"

  var answer = confirm(msg)
  if (!answer)
    hello("......")
  return answer
}

function random(target) {
  return Math.round(Math.random() * target.length - 0.5)
}

function checkGuide() {
  if (--Rei.hide_count == 0)
    Rei.msg.visibility = hidden
  if (--Rei.event_count == 0)
    hello()
  if (--Rei.guide_count == 0) {
if (ie4) {
  Rei.img = document.all.Irei1
  Rei.img.style.visibility = visible
  document.all.Irei0.style.visibility = hidden
}
else
  Rei.img.src = guides_img[guide_count][1].src

    if (msg_full)
      hello(msg_full)
  }

  if (!resizeGuide_count)
    return

  for (var i = 0; i < 2; i++) {
    var rs = document.getElementById("Irei" + i).style
    var img = guides_img[guide_count][i]
    var w = img.width
    var h = img.height

    var cc = (resizeGuide_mod == 1) ? resizeGuide_count : (10 - resizeGuide_count)
    rs.pixelWidth = Math.round(w*2/3 + (w/30 * cc))
    rs.pixelHeight = Math.round(h*2/3 + (h/30 * cc))
  }

  resizeGuide_count++
  if (resizeGuide_count > 10)
    resizeGuide_count = 0
}

function runPath2() {
  runPath()
  checkGuide()
}

function pathStop() {
  if (!Rei.moving)
    return

  Rei.moving = false
  Rei.guide_count = 50
  hello(Rei.intros[0])
  wander()
}

function menuIn(menu) {
  menu.style.backgroundColor = "HIGHLIGHT"
  menu.style.color = "HIGHLIGHTTEXT"
}

function menuOut(menu) {
  menu.style.backgroundColor = "MENU"
  menu.style.color = "MENUTEXT"
}

function hideMenu() {
  if (ie4)
    Lsystem.style.visibility = "hidden"
}

var resizeGuide_count = 0
var resizeGuide_mod = 1

function resizeGuide() {
  hideMenu()

  if (resizeGuide_count)
    return

  resizeGuide_mod *= -1
  resizeGuide_count = 1

  Ssize.innerText = (resizeGuide_mod == -1) ? "Normal" : "Shrink"
}

var temp_count, guides, img_loaded, guides_img, guides_length, load_count

function initLoading(target, random_length) {
  if (!dhtml)
    return

  var HTML
  if (nc4) {
    HTML =
      '<LAYER id=rei visibility=hide>\n'
    + '<LAYER></LAYER><LAYER></LAYER>\n'
    + '</LAYER>\n'
    + '<LAYER id=Lrei height=103 width=167 visibility=hide>\n'
    + '<LAYER top=0 left=0><img onLoad="nn_check_guides()" src="'+cloud_path+'"></LAYER>\n'
    + '<LAYER name=Lrei_msg top=20 left=20 width=127></LAYER>\n'
    + '</LAYER>\n'
  }
  else {
    HTML =
  '<DIV id=rei style="position:absolute;height:1;width:1;visibility:hidden;z-index:100"></DIV>\n'
+ '<DIV id=Lrei style="position:absolute;height:103;width:167;visibility:hidden;z-index:100">\n'
+ '<img style="position:absolute;top:0;left:0" src="'+cloud_path+'">\n'
+ '<DIV id=Lrei_msg style="position:absolute;top:20;left:20;width:127;font-size:14px;font-family:Comic Sans MS;color:black;text-align:left"></DIV>\n'
+ '</DIV>\n'

    if (ie4) {
      HTML +=
  '<STYLE>\n'
+ '.Smenu { padding-top:3; height:25; width:96; text-align:left; background-color:MENU; color:MENUTEXT; padding-left:5 }\n'
+ '</STYLE>\n'
+ '<DIV id=Lsystem style="position:absolute; width:100; font-family:Comic Sans MS; font-size:12px; font-weight:bold; cursor:default; z-index:100; background-color:MENU; border-width:2; border-style:outset; border-color:BUTTONHIGHLIGHT BUTTONSHADOW BUTTONSHADOW BUTTONHIGHLIGHT; visibility:hidden">\n'
+ '<DIV id=Saction class=Smenu onMouseOver="menuIn(this)" onMouseOut="menuOut(this)" onClick="Rei.clicked=true; introduce(event)">ACTION!</DIV>\n'
+ '<DIV id=Schange_guide class=Smenu onMouseOver="menuIn(this)" onMouseOut="menuOut(this)" onClick="nextGuide()">Change Guide</DIV>\n'
+ ((guide_resizable) ? '<DIV id=Ssize class=Smenu onMouseOver="menuIn(this)" onMouseOut="menuOut(this)" onClick="resizeGuide()">Shrink</DIV>\n' : '')
+ '<DIV id=Shide_guide class=Smenu onMouseOver="menuIn(this)" onMouseOut="menuOut(this)" onClick="toggleGuide()">Hide</DIV>\n'
+ ((self.G_custom_menu) ? G_custom_menu + '\n' : '')
+ '<DIV id=Scancel class=Smenu onMouseOver="menuIn(this)" onMouseOut="menuOut(this)" onClick="hideMenu()">Cancel</DIV>\n'
+ '</DIV>\n'
    }
  }

  HTML += '<script language="JavaScript" src="/seq.js"></sc'+'ript>\n'
  document.write(HTML)

  guide_init("guide"+"_script")

  if (!random_length)
    guides_length = target.length
  else if (random_length < 0)
    guides_length = target.length + random_length
  else
    guides_length = random_length
  guide_count = Math.round(Math.random() * guides_length - 0.5)

  guides = target
  guides_img = new Array()
  for (var i = 0; i < guides.length; i++)
    guides_img[i] = new Array()
  var gg = guides_img[guide_count]
  for (var i = 0; i < 2; i++) {
    gg[i] = new Image()
    if (nc4)
      gg[i].onload = nn_check_guides
  }
  for (var i = 0; i < 2; i++)
    gg[i].src = guides[guide_count] + "0" + i + ".gif"
  img_loaded = new Array()
  img_loaded[guide_count] = true
}

function nextGuide(cc) {
  if (!dhtml) {
    defaultStatus = "This requires MSIE or Mozilla."
    return
  }
  if (!loaded) {
    defaultStatus = "Please wait until the page is completely loaded."
    return
  }
  if (guide_state || load_count)
    return

  hideMenu()

  var c
  if ((cc == -1) || (cc == true)) {
    if (confirm("Press OK for random, or CANCEL for direct selection."))
      c = Math.round(Math.random() * guides_length - 0.5)
    else {
      var txt = (guides_length == guides.length) ? guides_length-1 : (guides_length-1) + " (" + guides_length + " - " + (guides.length-1) + " ^_^;)"
      c = parseInt(prompt("0 - " + txt + "?", guide_count))
      if ((isNaN(c)) || (c < 0) || (c >= guides.length) || ((c >= guides_length) && (self.hidden_guides_msg) && (!confirm(hidden_guides_msg)))) {
        hello("......")
        return
      }
    }
  }
  else {
    c = (cc == null) ? guide_count + 1 : cc
    if (c >= guides_length)
      c = 0
  }

  temp_count = c
  load_count = 2
  hello(msg_coming)
  if (img_loaded[temp_count]) {
    setTimeout("prepareGuide()", 500)
    return
  }

  for (var i = 0; i < 2; i++) {
    var img = guides_img[temp_count]
    img[i] = new Image()
    img[i].onload = loadingGuide
    img[i].src = guides[temp_count] + "0" + i + ".gif"
  }
}

function loadingGuide() {
  if (--load_count)
    return
  img_loaded[temp_count] = true
  load_count = 2
  setTimeout("prepareGuide()", 500)
}

function prepareGuide() {
  load_count = 0
  guide_count = temp_count
  calcDim()
  if (nc4)
    nn_write(guide_count)
  setTimeout("showGuide()", 100)
}

function showGuide() {
  if (guide_resizable) {
    resizeGuide_count = 0
    resizeGuide_mod = 1
    Ssize.innerText = "Shrink"
  }

if (ie4) {
  for (var i = 0; i < 2; i++) {
    var r = document.all["Irei" + i]
    var rs = r.style
    var img = guides_img[guide_count][i]

    rs.pixelWidth = img.width+0
    rs.pixelHeight = img.height+0
    r.src = img.src

    if (use_AIL)
      r.filters(0).src = img.src
  }

  Rei.img = document.all.Irei1
  Rei.img.style.visibility = visible
  document.all.Irei0.style.visibility = hidden
}
else
  Rei.img.src = guides_img[guide_count][1].src

  hello(msg_hello)
}

var guide_state = 0

function toggleGuide() {
  if (!dhtml) {
    defaultStatus = "This requires MSIE or Mozilla."
    return
  }
  if (!loaded) {
    defaultStatus = "Please wait until the page is completely loaded."
    return
  }

  hideMenu()

// 0=visible, 1=hiding, 2=hidden

  if (guide_state == 0) {
    hello(msg_leave)
    guide_state = 1
    setTimeout("stopGuide()", 1500)
  }
  else if (guide_state == 2) {
    if (ie4) {
      Lguide_control.innerText = gtext_stop
      Seq.item("RunPath").Play()
    }
    else {
      nc4_seqTimerID = setInterval('runPath2()', 100)
      document.rei.resizeTo(g_width, g_height)
    }
    Rei.target.visibility = visible
    hello(msg_hello)
    guide_state = 0
  }
}

function stopGuide() {
  hideMenu()

  if (ie4) {
    Lguide_control.innerText = gtext_run
    Seq.item("RunPath").Stop()
  }
  else {
    clearInterval(nc4_seqTimerID)
    document.rei.resizeTo(0,0)
  }
  Rei.target.visibility = hidden
  Rei.msg.visibility = hidden
  guide_state = 2
}

if (ie4)
  window.onload = start

var nn_guides = 0
var sp_func = start2

function nn_check_guides() {
  if (++nn_guides == 3)
    setTimeout('sp_func()', 100)
}

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

