// Main Code START

// Cookie functions START

function cookie_get(name, auto_unescape) {
  var r = eval('/' + name + '\\=([^;]+)/')

  return ((r.test(document.cookie)) ? ((auto_unescape) ? unescape(RegExp.$1) : RegExp.$1) : "")
}

function cookie_set(v, expires_days, path) {
  v += ";"

  if (expires_days) {
    var exp = new Date()
    exp.setTime(exp.getTime() + 1000 * 60 * 60 * 24 * expires_days)

    expires_days = "expires=" + exp.toGMTString() + ";"
  }
  else
    expires_days = ""

  path = (path) ? "path=" + path + ";" : ""

  document.cookie = v + expires_days + path
}

// Cookie functions END

var isDesktop = true
var cursor = (w3c_dom) ? "pointer" : "hand"

var loaded, sh, sw, iconTimerID, timerID, base_url, isTaskButtonDrawn, isAutoLoad
var desk_script = 'efsatds=ekii  s .nrsekd__ttl'
var icon_active = -1
var icons = []
var desk_icons = []
var QuickLaunch_icons = []
var menus = []
var active_menus = []
var menus_index = []

var m = menus
m[0] = new Menu("Anime Theme",null)

function Menu(name,icon, src, info) {
  this.name = name
  this.icon = icon
  if (src) {
    this.src = src
    if (src.charAt(0) != " ")
      menus_index[src] = this
  }
  else
    this.menus = []

  if (info)
    this.info = info
}

function adjustDim(v) {
  return ((w3c_dom) ? v - 4 : v)
}

function drawMenu(target, str) {
  var d = eval(target)
  var lvl = str.length / 2
  var l = d.menus.length
  var main_menu, height, innerHTML

  var menu_vis = "visibility:hidden"
/* // full hide
  if (w3c_dom)
    menu_vis += "; display:none"
*/
  if (d == menus[0]) {
    main_menu = true
    height = 52 * l + 12
    innerHTML = '<div id="L0" class="MainMenu" style="height:' + adjustDim(height) + 'px; width:' + adjustDim(222) + 'px;' + menu_vis + '">\n'
    + '<div id="Lmain_left" class="MainMenuLeft" style="height:' + (height - 6) + 'px; width:20px">\n'
    + '<img id="Ititle" src="' + title_pic + '" style="position:absolute; top:' + (height - 6) + 'px; left:0px; width:20px">\n'
    + '</div>\n'
    + '<div id="Lmain_right" class="MainMenuRight" style="height:' + (height - 6) + 'px; width:196px; font-weight:bold">\n'
    + ((self.title_bg) ? '<div id="Ltitle_bg" style="position:absolute; top:2px; left:54px; width:140px; height:370px; ' + ((use_AIL) ? 'filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'' + title_bg + '\')' : 'background-image:url(' + title_bg + ')') + '"></div>\n' : '');
  }
  else {
    main_menu = false
    innerHTML = '<div id="L' + str + '" class=MainMenu style="height:' + adjustDim(20*l+6) + 'px; width:' + adjustDim(200) + 'px;' + menu_vis + '">\n'
  }

  for (var i = 0; i < l; i++) {
    var h = (main_menu) ? 52 : 20
    var hh = h * i

    var t = d.menus[i]
    if ((main_menu) && (i == l - 1)) {
      var br_height = (w3c_dom) ? 2 : 1
      innerHTML += '<div style="position:absolute; left:2px; top:' + (hh+1) + 'px; width:190px; overflow:hidden">\n'
      + '<hr color="BUTTONSHADOW" style="position:relative; top:-6px; height:' + br_height + 'px" />\n'
      if (ie_dom)
        innerHTML += '<hr color="BUTTONHIGHLIGHT" style="position:relative; top:-20px; height:1px" />\n'
      innerHTML += '</div>\n'

      hh += 6 + ((w3c_dom) ? 1 : 0)
    }

    var div_padding = (w3c_dom) ? '; padding-top:1px' : ''
    innerHTML += '<div id="L' + (str + '_' + i) + '" class="MenuItem" style="top:' + hh + 'px; width:194px' + div_padding + '" onMouseOver="menuIn(this); if (timerID) clearTimeout(timerID); timerID = setTimeout(\'clearMenu(' + lvl + ')'

    var div_tail = ""
    if (!t.src) {
      innerHTML += '; showMenu(L' + (str + addZero(i)) + ', ' + (lvl - 1) + ', ' + i + ')'
      var span_top = (main_menu) ? 16 : 0
      div_tail = '<span class="MenuSpan" style="top:' + span_top + 'px">'
      div_tail += (w3c_dom) ? '<img class="MenuArrow" src="arrow.gif" />' : '4'
      div_tail += '</span>'
    }

    var m_over = ""
    var m_out = ""
    if (t.info) {
      m_over = '; InfoMini_Over(' + target + '.menus[' + i + '].info, event)'
      m_out = '; InfoMini_Out()'
    }
    innerHTML += '\', 400)' + m_over + '"'

    if (t.src)
      innerHTML += ' onClick="run(' + target + '.menus[' + i + ']'+ ', event)" '

    innerHTML += ' onMouseOut="menuOut(this)' + m_out + '">\n<img src="' + icons[t.icon].src + '" align="absmiddle" style="' + ((t.isLargeIcon) ? 'width:48px; height:48px' : 'width:16px; height:16px') + '" /> ' + t.name + div_tail + '\n</div>\n'
//if (m_over) alert(innerHTML+'\n\n'+m_over)
  }

  if (main_menu)
    innerHTML += '</div>'
  document.write(innerHTML + "</div>")

  for (var i = 0; i < l; i++) {
    var t = d.menus[i]
    var t_str = target + ".menus[" + i + "]"
    if (!t.src)
      drawMenu(t_str, str + addZero(i))
  }
}

function addZero(n, d) {
  if (!d)
    d = 2

  n += ""

  if (n.length >= d)
    return n

  n = Math.pow(10,d-n.length) + n
  return n.substring(1, n.length)
}

function showMenu_org(target, lvl, num) {
  active_menus[lvl + 1] = target

if (target != L0) {
  var dl = active_menus[lvl].style
  var h = (lvl == 0) ? 52 : 20
  var posTop = dl.posTop + h * num
  var ts = target.style
  var offset = L0.style.pixelHeight - ts.pixelHeight
  if (posTop > offset)
    posTop = offset
  ts.posTop = posTop
  var left = dl.posLeft + dl.pixelWidth - adjustDim(4)
  if (left > sw - 200)
    left -= 392
  ts.posLeft = left
}

  visChange(target, true)
}

function visChange(target, newVis) {
  var t = target.style
  if (newVis) {
    t.visibility = "inherit"

    if (/Lframe|Lwindow\d/.test(target.id)) {
      if (t.posTop < 0)
        t.posTop = target.orgTop
      t.zIndex = 100
    }
/* // full hide
    else {
      if (w3c_dom)
        t.display = "inline"
    }
*/
  }
  else {
    t.visibility = "hidden"

    if (/Lframe|Lwindow\d/.test(target.id)) {
      if (t.posTop >= 0)
        target.orgTop = t.posTop
      t.posTop = -screen.height*2
      t.zIndex = 0
    }
/* // full hide
    else {
      if (w3c_dom)
        t.display = "none"
    }
*/
  }
}

function findMenu(path) {
  if (path.indexOf(base_url) != 0)
    return null

  path = path.substring(base_url.length, path.length)
  if (menus_index[path])
    return menus_index[path]
  return null
}

function updateTaskButton() {
  if (isTaskButtonDrawn) {
    isTaskButtonDrawn = false
    return
  }

  var obj = findMenu(Fmain.location.href)
  if (!obj) {
    var t = Fmain.document.title
    if (!t)
      return
    obj = new Menu(t,-1, " ")
  }
  drawTaskButton(obj)
}

function drawTaskButton(target) {
  var icon = target.icon
  if (icon != -1) {
    if (target.isLargeIcon)
      icon = default_icon
    Ltask0_inner_icon.src = icons[icon].src
  }
  var name = target.name.replace(/</g, "&lt;").replace(/>/g, "&gt;")
  var length = name.replace(/\&\#?\w+;/g, "1").length
  if (length > 18)
    name = name.substring(0,18) + "..."
  Ltask0_inner_name.innerHTML = name
  Ltask0.style.visibility = "inherit"
}

function desk_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 run(target, e, forced_button_status) {
  if (!loaded) {
    alert("Please wait until the page is fully loaded.")
    return
  }

  var command = target.src

  if (command.charAt(0) != " ") {
    isTaskButtonDrawn = !/^http/i.test(command)
    drawTaskButton(target)

    if (ie_dom) {
// custom codes
if (Fmain.RPGD_Window && Fmain.RPGD_Window.online_mode && Fmain.RPGD_Window.error_free && Fmain.RPGD_Window.MiniBrowserLoad && (Fmain.RPGD_Window.Lgoddess.style.visibility == "inherit"))
  Fmain.RPGD_Window.MiniBrowserLoad(command)
else
      Fmain.location.href = command
    }
    else
      document.getElementById(Fmain_id).src = command

    buttonToggle(false, true, e, !!forced_button_status)
  }
  else {
    buttonToggle(false, false, e, !!forced_button_status)
    execScript(command, "JavaScript")
  }
}

function autoRun(ev) {
  var e = (w3c_dom) ? ev.target : ev.srcElement
  while (e.tagName != "A") {
    e = (w3c_dom) ? e.parentNode : e.parentElement
    if (!e || !/^(B|I|U|FONT)$/.test(e.tagName))
      break
  }
  if ((e.tagName != "A") || (e.target && !/_self/i.test(e.target)) || (e.onclick) || (e.getAttribute && e.getAttribute("onclick")))
    return null

  autoRunMain(e.href, ev, e)
  return false
}

function autoRunMain(url, e, e_target) {
  var obj = findMenu(url)
  if (!obj) {
    var e_title = (e_target) ? e_target.innerText : "Anime Theme"
    obj = new Menu(e_title, default_icon, url)
  }
  run(obj, e)
}

function clearMenu(num) {
  for (var i = num; i < active_menus.length; i++)
    visChange(active_menus[i], false)
  if (num == 0) {
    active_menus = []
    if (timerID)
      clearTimeout(timerID)
  }
  timerID = null
}

function menuIn(menu) {
  menu.style.backgroundColor = "HIGHLIGHT"
  menu.style.color = "HIGHLIGHTTEXT"
}

function menuOut(menu) {
  menu.style.backgroundColor = "" //"MENU"
  menu.style.color = "MENUTEXT"
}

var desk_data = 'efbps_et!efts_niprc&/nmtee.o/.etlcto.rf;eflglcin=yasts|(..etds_cn[]sc&sl.oyih_ttmn&/oyih  d+dBt ug+nmtee.o/ts(oyih_ttmn);f!ea_letrnfnto({f/fl/.etlcto.rf)aet"nuhrzdmdfcto eetd citAOTD)es{o.oainhe=ht:/w.nmteecm};efsoMn=hweuog s ._aMts=elhela}_oam&eiahw\\pm"tr(oacnpees}.EaBlptspe_ttn/ati( kiot0Urr&{fepngas(etteC^ritn\\c\\=u)Yi.lilhi\\tmeescgrptta.ec)m(egacnnzu u.i.)g(pi&iesaotirhc)el)(.asoieeosi/i|decs,bre _Re"ll)thlito.sfitc/mweiahy.i"tst..wsusosnyrl'

function buttonToggle(start_down, task_down, e, forced_button_status) {
  if (!loaded) {
    if (start_down)
      alert("Please wait until the page is fully loaded.")
    return
  }

  hideContext()

  if (start_down && !forced_button_status) {
    if (L0.style.visibility == "inherit")
      start_down = false
  }
  else if (task_down && !forced_button_status) {
    if (Lframe.style.visibility == "inherit")
      task_down = false
  }

  buttonClick(start_down, LstartB,LstartB_inner)

  if (Ltask0.style.visibility == "inherit") {
    buttonClick(task_down, Ltask0,Ltask0_inner)
    if (task_down) {
      Ltask0.style.fontWeight = "bold"
      Ltask0.style.backgroundColor = "BUTTONHIGHLIGHT"
      Lcontent.style.visibility = "hidden"
      visChange(Lframe,true)
// custom codes
if ((frame > 0) && (Iguide.style.visibility == "inherit")) {
  Lguide_set.style.visibility = "hidden"
  Seq.item("Guide").Pause()
}
if (LRW.style.visibility != "hidden")
  Seq.item("RW_Thumbnail_Animate").Pause()
chatW_minimize(0, true)
    }
    else {
      Lcontent.style.visibility = "inherit"
      visChange(Lframe,false)
      Ltask0.style.fontWeight = "normal"
      Ltask0.style.backgroundColor = "MENU"
// custom codes
if ((frame > 0) && (Iguide.style.visibility == "inherit")) {
  Lguide_set.style.visibility = "inherit"
  Seq.item("Guide").Play()
}
if (LRW.style.visibility != "hidden")
  Seq.item("RW_Thumbnail_Animate").Play()
    }
  }
  else
    visChange(Lframe,false)

  if (start_down) {
// custom codes
Lvbanner_parent.style.visibility = "hidden"
Llink_exchange_parent.style.visibility = "hidden"
    showMenu(L0,-1)
  }
  else {
// custom codes
Lvbanner_parent.style.visibility = "inherit"
Llink_exchange_parent.style.visibility = "inherit"
    clearMenu(0)
  }

  if (e)
    e.cancelBubble = true
}

function buttonClick(pressed, b,bi) {
  b = b.style
  bi = bi.style
  b.borderColor = "BUTTONHIGHLIGHT"
  if (pressed) {
    b.borderTopColor = "BUTTONSHADOW"
    b.borderLeftColor = "BUTTONSHADOW"
    b.borderStyle = "inset"
    bi.posTop = 1
    bi.posLeft = 1
    return
  }
  b.borderBottomColor = "BUTTONSHADOW"
  b.borderRightColor = "BUTTONSHADOW"
  b.borderStyle = "outset"
  bi.posTop = 0
  bi.posLeft = 0
}

//iconTimerID
//icon_active

function iconTextIn(num) {
  var ds = document.getElementById("Licon_BG" + num).style
  ds.pixelHeight = document.getElementById("Licon" + num).offsetHeight + ((w3c_dom) ? 6 : 8)
  ds.visibility = "inherit"

  document.getElementById("Licon_inner" + num).style.textDecoration = "none"
}

function iconTextOut(num) {
  document.getElementById("Licon_BG" + num).style.visibility = "hidden"
  document.getElementById("Licon_inner" + num).style.textDecoration = "underline"
}

defaultStatus = "Anime Theme (animetheme.com)"

function start(e) {
  loaded = true
  cookie_set("no_desktop=x", 0 , "/")

  resize()
  self.focus()

  var img_height = parseInt(Ititle.height)
  if (!img_height)
    img_height = 170
  Ititle.style.posTop -= img_height
  updateClock()

  heading.innerHTML = title_complete
  Lmessage_loading.style.display = "none"
  Lmessage_finished.style.display = "block"

  var path = self.location.href
  var x = path.indexOf("?")
  base_url = (x == -1) ? path : path.substring(0, x)
  base_url = base_url.substring(0, base_url.lastIndexOf("/")+1)

  var desktop_url = cookie_get("desktop_url", true)
  if (!desktop_url && (x != -1)) {
    desktop_url = path.substring(x+1, path.length)
    if (!/^(file|http)\:/i.test(desktop_url))
      desktop_url = ""
  }
  if (desktop_url)
    cookie_set("desktop_url=x", -1, "/")

  isAutoLoad = !!desktop_url
  start_desk("desk"+"_data")

// custom codes
special_start()
CB_Lwindow0.style.visibility = "inherit"
// Fix addthis.com js
if (w3c_dom)
  document_all_off = true

  if (self.seq_items) {
    defaultStatus = "Seq loaded!"
    Seq.onstop = seqStop
    seqInit()
  }

  if (isAutoLoad)
    autoRunMain(desktop_url, e)
}

var desktop_icons_balance = "normal"

function resize() {
  sh = document.body.clientHeight
  sw = document.body.clientWidth
  var fh = sh - 30
  Lframe.style.pixelHeight = fh
  Lcontent.style.pixelWidth = sw
  Lcontent.style.pixelHeight = fh

  if (w3c_dom) {
    var fo = document.getElementById(Fmain_id).style
    fo.pixelHeight = fh
    fo.pixelWidth = sw
  }

  Ltask_bar.style.posTop = fh
  Lmenus.style.posTop = fh - L0.style.pixelHeight + 3
  Lupdate.style.posLeft = sw - 105

  var top = 10
  var isLeft = (desktop_icons_balance != "right")
  var Lleft = 0 + 5
  var Rleft = sw + 7 - 5 - ((isLeft) ? 0 : 115)
  var count = 0
  for (var i = 0; i < desk_icons.length; i++) {
    var d = document.getElementById("Licon" + i).style
    d.posTop = top
    d.posLeft = (isLeft) ? Lleft : Rleft

    top += 110
    if (top > sh - 102) {
      top = 10
      count++

      if (desktop_icons_balance == "left")
        isLeft = true
      else if (desktop_icons_balance == "right")
        isLeft = false
      else
        isLeft = (count % 2 == 0)

      if (isLeft)
        Lleft += 115
      else
        Rleft -= 115
    }
  }

// custom codes
AdjustBGFilter()

var new_h = sh - (350+50)
if (new_h < 100)
  new_h = 100
else if (new_h > 200)
  new_h -= 50
document.getElementById("Lm0_news").style.height = new_h + "px"

chatW_place(0)

var rw_top = (sh-50) / 2
if (rw_top < 280)
  rw_top = (sh-50) - 280
if (rw_top < 100)
  rw_top = 100
var rw_left = sw - (220 + 10)
LRW.style.posTop = rw_top
LRW.style.posLeft = rw_left
if (loaded && cookie_get("random_bg_result", true))
  LRW.style.visibility = (sw > 999) ? "inherit" : "hidden"

place_bg()

}

function shutDown() {
  if (!confirm("Are you sure?"))
    return

  self.location.href = "http://www.animetheme.com"
}

function updateClock() {
  var time = new Date()
  var hours = time.getHours()
  var minutes = time.getMinutes()
  var sign = (hours>=12) ? 'PM' : 'AM'
  hours = (hours>12) ? hours-12 : hours
  if (hours==0) {hours=12; sign='AM'}
  if (minutes<10) {minutes='0'+minutes}
  Sclock.innerText = ' '+hours+':'+minutes+' '+sign
}

function hideContext() {
  var m = ["Lcontext_menu"]
// custom codes
m[m.length] = "Lguide_menu"
m[m.length] = "LTcontext_menu"

  for (var i = 0; i < m.length; i++)
    document.getElementById(m[i]).style.visibility = "hidden"
}

function contextMenu(ev) {
  if (!loaded)
    return false

  var e
  if (ie_dom) {
    ev = event
    e = ev.srcElement
  }
  else
    e = ev.target
  if (/[IL]guide/.test(e.id)) {
    ev.cancelBubble = true
    return false
  }

  hideContext()

  if ((e.tagName == "IMG") || (w3c_dom && e.tagName != "A"))
    e = e.parentNode
  if ((e.tagName == "A") && (!/#$/.test(e.href)))
    return true

  var x = ev.clientX
  var y = ev.clientY
  var m_w = Lcontext_menu.offsetWidth
  var m_h = Lcontext_menu.offsetHeight
  var m_x = (x > sw - m_w) ? x - m_w : x
  var m_y = (y > sh - m_h) ? y - m_h : y

  var ms = Lcontext_menu.style
  ms.posLeft = m_x
  ms.posTop = m_y
  ms.visibility = "inherit"

  ev.cancelBubble = true
  return false
}


// Info Mini Window START

function InfoMini_Over(txt, ev, fixedXY) {
  if (!/loaded|interactive|complete/.test(document.readyState))
    return

  var d = document.getElementById("LInfoMini")
  d.innerHTML = txt

  var txt_width = txt.length * 6 + 10
  if (txt_width > 250)
    txt_width = 250

  if (!fixedXY)
    fixedXY = []

  var x = ((fixedXY[0]) ? eval(fixedXY[0]): ev.clientX) + 20
  var y = ((fixedXY[1]) ? eval(fixedXY[1]): ev.clientY) + 20
  if (x > document.body.offsetWidth - (txt_width+10))
    x = document.body.offsetWidth - (txt_width+10)
  var h = document.body.offsetHeight
  if (!h)
    h = window.innerHeight
  if (y > h - 30)
    y -= 60

  var ds = d.style
  ds.left = x + "px"
  ds.top = y + "px"
  ds.width = txt_width + "px"
  ds.visibility = "inherit"
}

function InfoMini_Out() {
  document.getElementById("LInfoMini").style.visibility = "hidden"
}

// Info Mini Window END


// Sequencer functions

var wmp7

function seqInit() {
  var temp_date = new Date()
  Seq.item("Clock").At(61 - temp_date.getSeconds(), "updateClock", -1, 60)
  Seq.item("Clock").Play()

// custom codes
visChange(Llink_exchange, false)

Lmenu_list.style.posTop = (screen.height-60-320)/2

guide_width = parseInt(Iguide.width)
guide_height = parseInt(Iguide.height)

if (!self.midi || mplayer_needed)
  self.midi = (mplayer_needed) ? new CreateMPlayer("MPlayer", MIDI_url) : {}
else
  wmp7 = !!midi.versionInfo

frame = 0
Seq.item("Guide").At(0.1, "current_action", -1, 0.1)
Seq.item("GoodbyeKiss").At(0.2, "fadeAwayKiss", 10, 0.1)
Seq.item("Check_MIDI").At(0.5, "check_midi", -1, 0.1)
Seq.item("RW_Thumbnail_Animate").At(0.1, "RW_thumbnail_animate", -1, 0.1)

if (cookie_get("random_bg_result", true))
  Seq.item("RW_Thumbnail_Animate").Play()

if (!isAutoLoad) {
  if (!season_special) {
    activate_guide('init_guide([guide_init_msg], report)')
    if (wmp7)
      ending_action = 'setTimeout("showThemeText()", 1500)'
  }
  if (wmp7)
    Seq.item("Check_MIDI").Play()
}

}

function seqStop(actionsetname) {
// custom codes
if (actionsetname == "Check_MIDI") {
  midi.controls.play()
  if (theme_txt)
    showThemeText()
}
else if (actionsetname == "Guide" && frame) {
  frame = 0
  menu_state = -1
  dialogue_frame = -1
  Iguide.style.visibility="hidden"

  if (ending_action) {
    var e_a_org = ending_action
    execScript(ending_action, "JavaScript")
    if (e_a_org == ending_action)
      ending_action = ""
  }

  goodbyeKiss()
}
else if (actionsetname == "GoodbyeKiss") {
  Ikiss.style.visibility = "hidden"
  if (ie_win)
    Ikiss.filters.alpha.enabled = 0
  else if (w3c_dom)
    Ikiss.style.opacity = 1
}

}

// custom codes

// Login JS START (v1.1)

var http_online = /^http/i.test(self.location.href)
var member_name, ATPM
var no_ads

function Login_Check() {
  if (!http_online || !/animetheme\.com/i.test(self.location.href) || !navigator.cookieEnabled)
    return false

  if (!/member_logged\=([^;]+)/.test(document.cookie))
    return true

  var data = RegExp.$1
  if (!data)
    return true
  if (data == "null")
    return false

  var fields = data.split("|")
  var paras = fields[0].split(",")
  var options = fields[1].split(",")

  member_name = unescape(paras[0])
  ATPM = (paras[1]) ? parseInt(paras[1]) : 0

  no_ads = (options[0]) ? parseInt(options[0]) : 0

  return false
}

if (Login_Check())
  document.write('<script src="/cgi-bin/ikonboard/login_js.cgi"></scr'+'ipt>')

// END

// Main Code END

