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
}