
if(window.onload && document.addEventListener)
	document.addEventListener('DOMContentLoaded',window.onload,0)

function pp(r) {
	if(pp._y) return
	pp._y=1
	var d = document
	if(!d.getElementById) return

	var t = d.getElementById("paper")
	if(t) {
		var c = d.createElement("td")
		c.style.background = "url("+r+"i/h.gif)"
		c.style.height = "2px"

		var c1 = c.cloneNode(1)
		c1.style.width = "32px"

		with(t.rows[0]) {
			deleteCell(2); deleteCell(1); deleteCell(0)
			appendChild(c1.cloneNode(1))
			appendChild(c.cloneNode(1))
			appendChild(c1)
		}

		c.colSpan = 3

		for(var i=1;;) {
			i++
			r = t.rows[i++]
			if(!r) break

			r.deleteCell(0)
			r.appendChild(c.cloneNode(1))
		}
	}

	/* wikipedize */

	var l=d.getElementsByTagName("a")
	var w=[], n=0, i,e,s
	for(i=0; i<l.length; i++)
		if(l[i].className=="wik")
			w[n++] = l[i]
	for(i=0; i<n; i++) {
		e = w[i]
		s = e.getAttribute("title")
		if(!s) {
			if(e.childNodes.length!=1 || e.firstChild.nodeType!=3)
				continue
			s = e.firstChild.nodeValue
		}
		e.setAttribute('title','Wikipedia: \n'+s)
		s = s.replace(/ /g,"_")
		s = s.substr(0,1).toUpperCase() + s.substr(1)
		e.setAttribute('href','//en.wikipedia.org/wiki/'+s+'?no-fucken-banner-please')
	}

	/* add home */
	var h = "http://wizard.ae.krakow.pl/~jb/"
	if(d.location != h) {
		var a = d.createElement("a")
		a.href = h
		a.id = "home"
		a.appendChild(d.createTextNode("~jb"))
		d.body.insertBefore(a,d.body.firstChild)
	}

	window.onresize = heights
	window.onload = heights

	if(window.do_onload)
		do_onload()

	heights()
}

function heights()
{
	var t=document.getElementById('paper')
	var a=[],c,h
	for(var i=1;i<t.rows.length;i+=2) {
		c=t.rows[i].cells[1]
		h = c.offsetHeight
		if(h==ch(h)) continue
		c.height=''
		a.push(c)
	}
	while(c = a.shift()) {
		h = ch(c.offsetHeight)
		c.height = h
	}

	function ch(h) {return h+27-((h+2)%27)}
}

