/* Algohol */

// CLASS#1: navbar()
function navbar(pos) {
  this.navnum = navi.length
  if (pos == undefined || pos == -1) var pos = [[0, ''], -1, -1, [0, '']]
  this.pos = pos
  this.height = 25
  this.border = [0, 0, 2, 0]
  
  this.menu = document.createElement('div')
  this.menu.className = 'navbar navi' + this.navnum
  
  this.update()
  
  wrapper.appendChild(this.menu)
}

navbar.prototype.update = function() {
  for (var i = 0; i < global_directions_length; i++) {
    if (this.pos[i] != -1)
      this.menu.style[global_directions[i]] = this.pos[i][0] + this.pos[i][1]
  }
}

navbar.prototype.support = function(name) {
  posis[name] = this.navnum
  
  if (name == 'dropdowns')
    this.drops = []
}

navbar.prototype.unsupport = function(name) {
  if (posis[name] == undefined) return
  delete posis[name]
  
  if (name == 'dropdowns')
    delete this.dropdowns
  else if (name == 'appboxes')
    delete this.appboxes
}

// DROPDOWN
navbar.prototype.drop = function(name, list) {
  var listlen = list.length
  var wrap = this.append_level(list, name)
  this.dropdowns.appendChild(wrap)
  this.drops[this.drops.length] = [wrap, name, list]
}

navbar.prototype.append_level = function(list, first) {
  var listlen = list.length
  var i, wrap, dtop, type, elem, elema, elemb, spl, title
  
  wrap = document.createElement('div')
  if (first) {
    wrap.className = 'dropdown'
    dtop = document.createElement('div')
    dtop.className = 'top drop' + navi[posis['dropdowns']].drops.length
    dtop.innerHTML = first
    wrap.appendChild(dtop)
  }
  else {
    wrap.className = 'entries'
    elem = document.createElement('div')
    elem.className = 'side'
    wrap.appendChild(elem)
  }
  
  for (i = 0; i < listlen; i++) {
    type = typeof(list[i])
    if (type == 'string') {
      spl = [list[i], 'true']
      if (list[i].indexOf('#') != -1)
        spl = list[i].split('#')
      elem = document.createElement('div')
      elem.className = 'entry'
      elem.rel = spl[1]
      elem.onmouseup = function() {
        navi[posis['dropdowns']].hide_drops()
      }
      elem.innerHTML = spl[0]
      elem.onclick = function() {
        eval('scr.setwindow(\'' + this.innerHTML + '\',' +  this.rel + ')')
      }
      wrap.appendChild(elem)
    }
    else if (type == 'object') {
      elem = document.createElement('div')
      elem.className = 'group'
      elema = document.createElement('div')
      elema.className = 'header'
      elema.innerHTML = list[i][0]
      elem.appendChild(elema)
      elema = this.append_level(list[i][1])
      elem.appendChild(elema)
      wrap.appendChild(elem)
    }
  }
  return wrap
}

navbar.prototype.hide_drops = function() {
  if (!hiding_drops) {
    hiding_drops = true
    var l = this.drops.length
    for (i = 0; i < l; i++) {
      this.drops[i][0].className = 'dropdownh dropdown'
    }
    setTimeout('navi[posis[\'dropdowns\']].hide_drops()', 100)
  }
  else {
    hiding_drops = false
    var l = this.drops.length
    for (i = 0; i < l; i++) {
      this.drops[i][0].className = 'dropdown'
    }
  }
}

navbar.prototype.box = function(name, pos) {
  if (pos == undefined) pos = 'none'
  this[name] = document.createElement('div')
  this[name].className = name
  this[name].style.cssFloat = pos
  this.menu.appendChild(this[name])
  
  if (name == 'clock') {
    this.setclock()
    this.clockinterval = setInterval('navi[posis[\'clock\']].setclock()', 30000)
  }
  if (name == 'abs_scroller') {
    this.abs_scroller.className = 'abs'
    var elem
    elem = document.createElement('div')
    elem.className = 'scrollup'
    elem.onclick = function() {
      navi[posis['appboxes']].abs_scroll(1)
    }
    this.abs_scroller.appendChild(elem)
    elem = document.createElement('div')
    elem.className = 'scrolldown'
    elem.onclick = function() {
      navi[posis['appboxes']].abs_scroll(-1)
    }
    this.abs_scroller.appendChild(elem)
    
    this.menu.style.overflow = 'hidden'
  }
}

navbar.prototype.check_abs_height = function(force) {
  var abs = navi[posis['appboxes']].height
  var rnum = navi[posis['appboxes']].appboxes.scrollHeight
  if (ie) {
    if ((rnum / abs + '').indexOf('.') != -1) rnum += appbox_margin * 2
  }
  var num = rnum / abs
  if (num > 1) {
    navi[posis['appboxes']].appboxes.style.marginRight = abs_scroller_width + 3 + 'px'
    navi[posis['appboxes']].abs_scroller.style.display = 'block'
    if (force) this.abs_scroll(-Math.floor(wnds[scr.wndpos[0]].appbox.offsetTop / abs))
  }
  else {
    navi[posis['appboxes']].appboxes.style.marginRight = '0'
    navi[posis['appboxes']].abs_scroller.style.display = 'none'
    this.abs_scroll(-abs_scrolled)
  }
}

navbar.prototype.abs_scroll = function(am) {
  var abam = abs_scrolled + am * 1
  var abs = this.height
  var rnum = this.appboxes.scrollHeight
  if ((rnum / abs + '').indexOf('.') != -1) rnum += appbox_margin * 2
  var num = rnum / abs
  if (abs_scrolled + am < 1 && abam * -1 < num) {
    abs_scrolled = abam
    this.appboxes.style.marginTop = abs * abs_scrolled + 'px'
  }
}

navbar.prototype.setclock = function() {
  var time = new Date ()
  
  var hours = time.getHours()
  var minutes = time.getMinutes()
  
  hours = (hours < 10 ? "0" : "") + hours
  minutes = (minutes < 10 ? "0" : "") + minutes

  this.clock.innerHTML = hours + ':' + minutes
}

// CLASS#1_end: navbar()


// NEW CLASS STARTING //


// CLASS#2_start: screen()

function screen() {
  this.elem = document.createElement('div')
  this.elem.className = 'area'
  this.elem.style.width = '100%'
  wrapper.appendChild(this.elem)
  this.len = 0
  this.olen = 0
  this.wndpos = new Array()
  
  this.overlay = document.createElement('div')
  this.overlay.className = 'overlay'
  this.elem.appendChild(this.overlay)
  
  this.rethink()
  this.update()
}

screen.prototype.rethink = function() {
  var navil = navi.length
  var mh, th, borders, bl, border
  mh = 0
  th = 0
  for (var i = 0; i < navil; i++) {
    border = 0
    borders = navi[i].border
    bl = borders.length
    for (var ii = 0; ii < bl; ii += 2) {
      border += borders[ii]
    }
    mh += navi[i].height
    if (navi[i].pos[0] != -1)
      th += navi[i].height + border
    if (navi[i].pos[0] != -1 || navi[i].pos[2] != -1)
      mh += border
  }
  this.bi = mh
  this.elem.style.top = th + 'px'
}

screen.prototype.wh = function() {
  if (self.innerHeight) {
    h=self.innerHeight
    w=self.innerWidth
  }
  else if (document.documentElement && document.documentElement.clientHeight) {
    h=document.documentElement.clientHeight
    w=document.documentElement.clientWidth
  }
  else if (document.body) {
    h=document.body.clientHeight
    w=document.body.clientWidth
  }
  
  sh = h - this.bi
}

screen.prototype.change_focus = function(num, det) {
  if (det == undefined) var det = 0
  
  var num = num * 1
  for (var i = 0; i < this.len; i++) {
    if (this.wndpos[i] == num) this.wndpos.splice(i, 1)
  }
  if (det == 0)
    this.wndpos.splice(0, 0, num)
  else if (det == 1)
    this.wndpos.splice(this.len, this.len, num)
  else if (det == 2) {
    this.len--
    this.elem.removeChild(wnds[num].elem)
    navi[posis['appboxes']].appboxes.removeChild(wnds[num].appbox)
    
    for (i = 0; i < this.len; i++) {
      if (this.wndpos[i] > num) {
        wnds[this.wndpos[i]].renum(-1)
        this.wndpos[i]--
      }
    }
    
    if (moving_window > num) moving_window--
    else if (moving_window == num) this.move_end()
    
    if (adjusting_window > num) adjusting_window--
    else if (adjusting_window == num) this.adjust_end()
    
    delete wnds[num]
    wnds.splice(num, 1)
    
  }
  this.setindex()
}

screen.prototype.setindex = function() {
  for (var i = 1; i < this.len; i++) {
    wnds[this.wndpos[i]].elem.style.zIndex = this.len - i + 1
    wnds[this.wndpos[i]].elem.id = ''
    wnds[this.wndpos[i]].appbox.className = ''
  }
  if (this.len > 0) {
    wnds[this.wndpos[0]].elem.style.zIndex = this.len + 2
    wnds[this.wndpos[0]].elem.id = 'active'
    wnds[this.wndpos[0]].appbox.className = ''
    this.overlay.style.zIndex = this.len + 1
  }
  
  var vis = false
  for (i = 0; i < this.len; i++) {
    if (wnds[i].visible) vis = true
  }
  if (vis) wnds[this.wndpos[0]].appbox.className = 'current'
  
  navi[posis['appboxes']].check_abs_height(true)
}

screen.prototype.set_overlay = function() {
  this.overlay.style.display = 'block'
}

screen.prototype.del_overlay = function() {
  this.overlay.style.display = 'none'
}

screen.prototype.move_start = function(what) {
  moving_window = what * 1
  wnds[moving_window].cn('data_overlay').style.display = 'block'
  this.set_overlay()
  
  diff_x = x - wnds[moving_window].elem.offsetLeft
  diff_y = y - wnds[moving_window].elem.offsetTop
}

screen.prototype.move_end = function() {
  if (moving_window > -1)
    wnds[moving_window].cn('data_overlay').style.display = 'none'
  moving_window = -1
  this.blurfocus()
}

screen.prototype.adjust_start = function(what, dir) {
  adjusting_window = what * 1
  adjusting_dir = dir * 1
  wnds[adjusting_window].cn('data_overlay').style.display = 'block'
  this.set_overlay()
  
  if (adjusting_dir != 1 && adjusting_dir != 5) { 
    start_x = x
    start_w = wnds[adjusting_window].width
    diff_x = start_x - wnds[adjusting_window].elem.offsetLeft
  }
  if (adjusting_dir != 3 && adjusting_dir != 7) { 
    start_y = y
    start_h = wnds[adjusting_window].height
    diff_y = start_y - wnds[adjusting_window].elem.offsetTop
  }
}

screen.prototype.adjust_end = function() {
  if (adjusting_window > -1)
    wnds[adjusting_window].cn('data_overlay').style.display = 'none'
  adjusting_window = -1
  adjusting_dir = -1
  this.blurfocus()
}

screen.prototype.blurfocus = function() {
  this.del_overlay()
  highlightfix.focus()
  highlightfix.select()
}

screen.prototype.setwindow = function(a, b, c, d, e, f, g, h, i, j, k, l, m, n) {
  wnds[wnds.length] = new scr_window(a, b, c, d, e, f, g, h, i, j, k, l, m, n)
  
  this.wndpos.splice(0, 0, this.len)
  this.len++
  this.olen++
  this.setindex()
}

screen.prototype.move_window = function() {
  var cx = x - diff_x
  if (cx < -diff_x) cx = -diff_x
  else if (cx > w - diff_x) cx = w - diff_x
  var cy = y - diff_y
  if (cy < 0) cy = 0
  else if (cy > sh - scr.hheight) cy = sh - scr.hheight
  if (scr.len > moving_window) {
    wnds[moving_window].elem.style.left = cx + 'px'
    wnds[moving_window].elem.style.top = cy + 'px'
  }
}

screen.prototype.adjust_window = function() {
  if (adjusting_dir != 1 && adjusting_dir != 5) {
    var cx, cw, cxs
    cxs = false
    if (adjusting_dir == 0 || adjusting_dir == 6 || adjusting_dir == 7) {
      cx = x - diff_x
      cw = start_w + start_x - x
      if (x - diff_x < 0) {
        cx = 0
        cxs = true
      }
    }
    else {
      cx = start_x - start_w + start_w - diff_x
      cw = start_w + x - start_x
      if (x + start_w - diff_x > w) cxs = true
    }
    
    if (cw < width_min) cxs = true
    
    if (!cxs && scr.len > adjusting_window) {
      wnds[adjusting_window].elem.style.left = cx + 'px'
      wnds[adjusting_window].width = cw
    }
  }
  
  if (adjusting_dir != 3 && adjusting_dir != 7) {
    var cy, ch, cys
    cys = false
    if (adjusting_dir == 0 || adjusting_dir == 1 || adjusting_dir == 2) {
      cy = y - diff_y
      ch = start_h + start_y - y
      if (y - diff_y < 0) {
        cy = 0
        cys = true
      }
    }
    else {
      cy = start_y - start_y + start_y - diff_y
      ch = start_h + y - start_y
      if (y + start_h - diff_y > sh) cys = true
    }
    
    if (ch < height_min) cys = true
    
    if (!cys && scr.len > adjusting_window) {
      wnds[adjusting_window].elem.style.top = cy + 'px'
      wnds[adjusting_window].height = ch
    }
  }
  
  wnds[adjusting_window].update()
}

screen.prototype.set_coor = function(e) {
  if (!e) var e = window.event
  if (e.pageX || e.pageY) {
    x = e.pageX
    y = e.pageY
  }
  else if (e.clientX || e.clientY) {
    x = e.clientX + document.body.scrollLeft
    y = e.clientY + document.body.scrollTop
  }
  
  if (moving_window != -1)
    scr.move_window()
  else if (adjusting_window != -1)
    scr.adjust_window()
}

screen.prototype.update = function() {
  this.wh()
  this.elem.style.height = sh + 'px'
}

// CLASS#2_end: screen()


// NEW CLASS STARTING //


// CLASS#3_start: scr_window()

function scr_window(title, icon, state, options, width, height, xpos, ypos, resizeable) {
  if (title == undefined) return
  if (icon == undefined) var icon = false
  if (state == undefined || state == -1) var state = 1 // 0 = minimized, 1 = normal, 2 = maximized
  if (options == undefined || options == -1) var options = [1, 1, 1] // Both minimizable, maximizeable and closeable
  if (width == undefined || width == -1) var width = 500
  if (height == undefined || height == -1) var height = 350
  if (xpos == undefined || xpos == -1) var xpos = (w - width) / 2
  if (ypos == undefined || ypos == -1) var ypos = (sh - height) / 2
  if (resizeable == undefined || resizeable == -1) var resizeable = true
  
  if (width < width_min) width = width_min
  if (height < height_min) height = height_min
    
  this.title = title
  this.icon = icon
  this.options = options
  this.width = width
  this.height = height
  this.resizeable = resizeable
  
  this.num = scr.len
  this.onum = scr.olen
  
  this.appbox = document.createElement('div')
  this.appbox.rel = wnds.length
  this.appbox.onclick = function() {
    if (wnds[this.rel].visible) {
      if (wnds[this.rel].appbox.className == 'current')
        wnds[this.rel].minimize(this.rel)
      else
        scr.change_focus(this.rel)
    }
    else
      wnds[this.rel].minimize(this.rel)
    
  }
  this.appbox.innerHTML = title
  navi[posis['appboxes']].appboxes.appendChild(this.appbox)
    
  var elems, belems, el, tmp, i, c
  this.elem = document.createElement('div')
  this.elem.className = 'window'
  
  el = 13
  if (icon) el++
  
  tmp = 0
  if (options[0]) tmp++
  if (options[1]) tmp++
  if (options[2]) tmp++
  this.optboxes = tmp
  
  if (tmp > 0) el++
  elems = new Array(el)
  belems = new Array(tmp)
  
  // Borders
  for (i = 0; i < 8; i++) {
    elems[i] = document.createElement('div')
    elems[i].className = global_directions_dt[i]
    if (i != 1) {
      if (resizeable) {
        elems[i].rel = i + ''
        elems[i].onmousedown = function() {
          if (wnds[this.parentNode.rel].normal)
            scr.adjust_start(this.parentNode.rel, this.rel)
        }
        elems[i].onmouseup = function() {
          scr.adjust_end()
        }
      }
    }
  }
  
  // Title + text + icon + options
  elems[8] = document.createElement('div')
  elems[8].className = 'title'
  elems[8].innerHTML = this.title
  
  elems[9] = document.createElement('div')
  elems[9].className = 'handle'
  elems[9].onmousedown = function() {
    if (wnds[this.parentNode.rel * 1].normal) {
      scr.move_start(this.parentNode.rel * 1)
    }
  }
  elems[9].onmouseup = function() {
    scr.move_end()
  }
  elems[9].ondblclick = function() {
    wnds[this.parentNode.rel * 1].maximize()
  }
  
  elems[10] = document.createElement('div')
  elems[10].className = 'resize_handle'
  if (resizeable) {
    elems[10].rel = '1'
    elems[10].onmousedown = function() {
      if (wnds[this.parentNode.rel * 1].normal)
        scr.adjust_start(this.parentNode.rel * 1, this.rel * 1)
    }
    elems[10].onmouseup = function() {
      scr.adjust_end()
    }
  }
  else
    this.elem.className += ' nrsz'
  if (!ie) {
    elems[11] = document.createElement('object')
    elems[11].data = 'pages/links.php?title=' + escape(title) + '&num=' + this.onum
    elems[11].type = 'text/html'
  }
  else {
    elems[11] = document.createElement('iframe')
    elems[11].src = 'pages/links.php?title=' + escape(title) + '&num=' + this.onum
    elems[11].frameBorder = '0'
  }
  elems[11].className = 'data'
  
  elems[12] = document.createElement('div')
  elems[12].className = 'data_overlay'
  
  if (icon) {
    elems[13] = document.createElement('div')
    elems[13].className = 'icon'
    elems[13].style.backgroundImage = 'url(\'pages/links.php?title=' + escape(title) + '&type=png\')'
  }
  
  if (this.optboxes > 0) {
    tmp = elems.length - 1
    elems[tmp] = document.createElement('div')
    elems[tmp].className ='options'
    
    c = 0
    for (i = 0; i < 3; i++) {
      if (options[i]) {
        belems[i] = document.createElement('div')
        belems[i].className = global_options[i]
        if (global_options[i] == 'minimize') belems[i].onclick = function() {
          wnds[this.parentNode.parentNode.rel * 1].minimize()
        }
        else if (global_options[i] == 'maximize') belems[i].onclick = function() {
          wnds[this.parentNode.parentNode.rel * 1].maximize()
        }
        else belems[i].onclick = function() {
          wnds[this.parentNode.parentNode.rel * 1].close()
        }
        elems[tmp].appendChild(belems[i])
        c++
      }
    }
  }
  
  this.elem.rel = wnds.length
  
  this.elem.onmousedown = function() {
    scr.change_focus(this.rel * 1)
  }
  
  this.elem.style.left= xpos + 'px'
  this.elem.style.top = ypos + 'px'
  
  for (i = 0; i < el; i++) {
    this.elem.appendChild(elems[i])
  }
  this.len = this.elem.childNodes.length
  
  scr.elem.appendChild(this.elem)
  
  this.visible = true
  this.normal = true
  if (state == 0) this.minimize()
  
  this.update()
  this.update_appbox()
  
  if (state == 2) this.maximize()
}

scr_window.prototype.update = function() {
  var tmp, el
  
  el = this.cn('tl')
  el.style.width = scr.margin + 'px'
  el.style.height = scr.hheight + 'px'
  
  el = this.cn('t')
  el.style.left = scr.margin + 'px'
  el.style.width = this.width - scr.margin * 2 + 'px'
  el.style.height = scr.hheight + 'px'
  
  el = this.cn('tr')
  el.style.left = this.width - scr.margin + 'px'
  el.style.width = scr.margin + 'px'
  el.style.height = scr.hheight + 'px'
  
  el = this.cn('r')
  el.style.top = scr.hheight + 'px'
  el.style.left = this.width - scr.margin + 'px'
  el.style.width = scr.margin + 'px'
  el.style.height = this.height - scr.hheight - scr.margin + 'px'
  
  el = this.cn('br')
  el.style.top = this.height - scr.margin + 'px'
  el.style.left = this.width - scr.margin + 'px'
  el.style.width = scr.margin + 'px'
  el.style.height = scr.margin + 'px'
  
  el = this.cn('b')
  el.style.top = this.height - scr.margin + 'px'
  el.style.left = scr.margin + 'px'
  el.style.width = this.width - scr.margin * 2 + 'px'
  el.style.height = scr.margin + 'px'
  
  el = this.cn('bl')
  el.style.top = this.height - scr.margin + 'px'
  el.style.width = scr.margin + 'px'
  el.style.height = scr.margin + 'px'
  
  el = this.cn('l')
  el.style.top = scr.hheight + 'px'
  el.style.width = scr.margin + 'px'
  el.style.height = this.height - scr.hheight - scr.margin + 'px'
  
  el = this.cn('title')
  el.style.top = scr.margin + 'px'
  el.style.height = scr.hheight - scr.margin + 'px'
  if (this.icon) tmp = scr.bw + scr.margin_t
  else tmp = 0
  el.style.left = scr.margin + scr.margin_t + tmp + 'px'
  el.style.width = this.width - scr.margin * 2 - scr.margin_t * 2 - this.optboxes * (scr.bw + scr.margin_t) - tmp + 'px'

  el = this.cn('handle')
  el.style.top = scr.margin + 'px'
  el.style.height = scr.hheight - scr.margin + 'px'
  el.style.left = scr.margin + scr.bw + scr.margin_t + 'px'
  el.style.width = this.width - scr.margin * 2 - this.optboxes * (scr.bw + scr.margin_t) - tmp + 'px'

  el = this.cn('resize_handle')
  el.style.left = scr.margin + 'px'
  el.style.width = this.width - scr.margin * 2 + 'px'
  el.style.height = scr.margin + 'px'

  el = this.cn('data')
  el.style.top = scr.hheight + 'px'
  el.style.left = scr.margin + 'px'
  el.style.width = this.width - scr.margin * 2 + 'px'
  el.style.height = this.height - scr.hheight - scr.margin + 'px'
  
  el = this.cn('data_overlay')
  el.style.top = scr.hheight + 'px'
  el.style.left = scr.margin + 'px'
  el.style.width = this.width - scr.margin * 2 + 'px'
  el.style.height = this.height - scr.hheight - scr.margin + 'px'
  
  if (this.icon) {
    el = this.cn('icon')
    el.style.top = scr.margin + 'px'
    el.style.left = scr.margin + scr.margin_t + 'px'
    el.style.width = scr.bw + 'px'
    el.style.height = scr.bh + 'px'
  }

  el = this.cn('options')
  if (el) {
    el.style.top = scr.margin + 'px'
    el.style.left = this.width - this.optboxes * (scr.bw + scr.margin_t) - scr.margin + 'px'
    el.style.width = this.optboxes * (scr.bw + scr.margin_t) - scr.margin_t + 'px'
    el.style.height = scr.bh + 'px'
    
    var elc = el.childNodes
    var elcl = elc.length
    for (var i = 0; i < elcl; i++) {
      elc[i].style.left = i * (scr.bw + scr.margin_t) + 'px'
      elc[i].style.width = scr.bw + 'px'
    }
  }
}

scr_window.prototype.update_appbox = function() {
  this.appbox.style.height = navi[posis['appboxes']].height - appbox_padding * 2 - appbox_margin * 2 - appbox_border * 2 + 'px'
}

scr_window.prototype.cn = function(what) {
  var i = 0
  var ok = false
  var nodes = this.elem.childNodes
  var node = fallback
  while (i < this.len && !ok) {
    if (nodes[i].className == what) {
      node = nodes[i]
      ok = true
    }
    i++
  }
  return node
}

scr_window.prototype.settitle = function(title) {
  this.cn('title').innerHTML = title
  this.appbox.innerHTML = title
}

scr_window.prototype.minimize = function() {
  if (this.visible) {
    this.visible = false
    this.elem.style.display = 'none'
    scr.change_focus(this.num, 1)
  }
  else {
    this.visible = true
    this.elem.style.display = 'block'
    scr.change_focus(this.num)
  }
}

scr_window.prototype.maximize = function() {
  if (this.normal) {
    this.normal = false
    this.savedpos = [this.elem.offsetLeft, this.elem.offsetTop, this.width, this.height]
    this.elem.style.left = -scr.margin + 'px'
    this.elem.style.top = 0
    this.width = w + scr.margin * 2
    this.height = sh + scr.margin
    this.elem.className = 'window window_max'
  }
  else {
    this.normal = true
    this.elem.style.left = this.savedpos[0] + 'px'
    this.elem.style.top = this.savedpos[1] + 'px'
    this.width = this.savedpos[2]
    this.height = this.savedpos[3]
    this.elem.className = 'window'
    if (!this.resizeable) this.elem.className += ' nrsz'
  }
  this.update()
}

scr_window.prototype.close = function() {
  scr.change_focus(this.num, 2)
}

scr_window.prototype.renum = function(n) {
  this.num += n
  this.elem.rel = this.num
  this.appbox.rel = this.num
}

// CLASS#3_end: scr_window()



// THEME SUPPORT //

function settheme(what) {
  theme.href = 'themes/links.php?title=' + what + '&type=css'
  
  var http=new httpobj()
  http.url('themes/links.php')
  http.method('get')
  http.add('title', what)
  http.add('type', 'js')
  http.func("themevars(text)")
  send(http)
}

function themevars(vars) {
  eval(vars)
  
  // Reshow everything
  scr.rethink()
  scr.update()
  
  for (var i = 0; i < scr.len; i++) {
    wnds[i].update()
    wnds[i].update_appbox()
  }
  
  for (var i = 0; i < navi.length; i++) {
    navi[i].update()
  }
  
  setTimeout("wrapper.style.display = 'block'", 500)
  setTimeout("navi[posis['appboxes']].check_abs_height(false)", 1000)
}



// ONLOAD
window.onload = function() {
  // Get the head element
  head_con = document.getElementsByTagName('head')[0]
  
  // Theme support - .href will be added at the end of the onload function
  theme = document.createElement('link')
  theme.rel = 'stylesheet'
  theme.type = 'text/css'
  head_con.appendChild(theme)
  
  
  // wrapper holds everything
  wrapper = document.createElement('div')
  wrapper.style.display = 'none'
  document.body.appendChild(wrapper)
  
    
  // A lot of globals used in various functions
  global_directions = ['top', 'right', 'bottom', 'left']
  global_directions_length = global_directions.length
  global_directions_dt = ['tl', 't', 'tr', 'r', 'br', 'b', 'bl', 'l']
  global_directions_dt_length = global_directions.length
  global_options = ['minimize', 'maximize', 'close']
  hiding_drops = false
  posis = {}
  wnds = new Array()
  
  x = 0
  y = 0
  moving_window = -1
  adjusting_window = -1
  adjusting_dir = -1
  start_x = -1
  start_y = -1
  diff_x = 0
  diff_y = 0
  
  width_min = 150
  height_min = 100
  
  abs_scroller_width = 10
  appbox_padding = 2
  appbox_margin = 2
  appbox_border = 1
  abs_scrolled = 0
  
  // Ew
  if (navigator.appName == 'Microsoft Internet Explorer') ie = true
  else ie = false
  
  
  /* Prepares fixing a highligthing problem that occurs whenever
     you've moved or adjusted a window. */
  highlightfix = document.createElement('textarea')
  highlightfix.className = 'highlightfix'
  highlightfix.value = 'fix'
  wrapper.appendChild(highlightfix)
  
  // Extra security for some elements that just don't exist
  fallback = document.createElement('div')
  
  
  // navi = navigation bar = navbar. Here 2 are created.
  navi = []
  navi[0] = new navbar([[0, ''], -1, -1, [0, '']])
  navi[1] = new navbar([-1, -1, [0, ''], [0, '']])
  
  // Where to put different stuff..
  navi[0].support('dropdowns')
  navi[0].support('clock')
  navi[1].support('appboxes')
  
  // ..and actually putting it there
  navi[posis['dropdowns']].box('dropdowns', 'left')
  navi[posis['clock']].box('clock')
  navi[posis['appboxes']].box('appboxes', 'left')  
  navi[posis['appboxes']].box('abs_scroller')
  
  
  
  /* Create dropdown menus. You can change the way a window opens
     by writing a "#" after the title, followed by your variables */
     
  navi[posis['dropdowns']].drop('Matematik', [
  ['Trigonometri', [
    'Sinusrelationer',
    'Cosinusrelationer'
  ]], 
  ['Funktioner', [
    'Parabler', 
    'Lineære funktioner', 
    'Skæringspunkter'
  ]]
  ])
  
  navi[posis['dropdowns']].drop('Fysik', [
  'Enheder og betydning', 
  ['Standardformler', [
    'Fart og acceleration'
  ]], 
  ['Energi', [
    'Energi generelt', 
    'Arbejde', 
    'Varme'
  ]], 
  'Tryk', 
  'Newtons love'
  ])
  
  navi[posis['dropdowns']].drop('Værktøjer', [
  'Lommeregner', 
  'Noter#true,-1,-1,400,400,w-405,sh-405', 
  'Hjælp', 
  ['Algohol', [
  'Ændr tema', 
  'Om Algohol',
  'Nyheder',
  'Algostore'
  ]]
  ])
  
  // Create the screen area (the area on which the windows can move freely)
  scr = new screen()
  scr.wh()
  
  // Event actions
  document.onmousemove = scr.set_coor
  
  window.onresize = function() {
    scr.update()
    for (var i = 0; i < scr.len; i++) {
      if (!wnds[i].normal) {
        wnds[i].width = w + scr.margin * 2
        wnds[i].height = sh + scr.margin
        wnds[i].update()
      }
    }
    
    navi[posis['appboxes']].check_abs_height(false)
  }
  
  document.onmouseup = function() {
    if (moving_window > -1)
      scr.move_end()
    if (adjusting_window > -1)
      scr.adjust_end()
  }
  
  // Set the theme (will default to the default if you specify an unexisting theme)
  settheme('Default')
  
  // Open a small welcome window
  scr.setwindow('Velkommen', true, -1, -1, 300, 200)
}