document.write('<link rel="stylesheet" type="text/css" href="jsenabled.css">');

/* Utility */

function getObject(id) {
	if(document.getElementById)
		return document.getElementById(id);
	if(document.all)
		return document.all[id];
	if(document.layers)
		try {
			return document.layers[id];
		} catch(e) {
			return null;
		}
	return null;
}

function addOnload(fn) {
	if(window.addEventListener)
		window.addEventListener("load",fn,false);
	else if(window.attachEvent)
		window.attachEvent("onload",fn);
	else {
		var oldOnload = window.onload;
		window.onload = function() {
			oldOnload();
			fn();
		}
	}
}


/* Menu */

function toggleSubMenu(where) {
	var style = where.nextSibling.style;
	style.display = style.display ? "" : "block";
	where.blur();
}


/* Insertion */

function autoInsertEndIcon() {
	if(!getObject("headinfo"))
		return;
	var container = getObject("contentinner"), node = container.lastChild;
	while(node.nodeName == "#text")
		node = node.previousSibling;
	var img = document.createElement("img");
	img.src =  "img/lilibaraki.gif";
	img.alt =  "(end)";
	img.id =  "articleend";
	if(node.nodeName.toLowerCase() == "p")
		node.appendChild(img);
	else
		container.appendChild(img);
}
addOnload(autoInsertEndIcon);

function autoInsertTOC() {
	if(!getObject("headinfo"))
		return;
	var h3s = getObject("contentinner").getElementsByTagName("h3");
	if(h3s.length < 2)
		return;
	
	minimizeup = new Image(9,9); minimizeup.src = "img/minimizeup.gif";
	function minUp() { getObject("minbutton").src = minimizeup.src; }
	minimizedn = new Image(9,9); minimizedn.src = "img/minimizedn.gif";
	function minDn() { getObject("minbutton").src = minimizedn.src; }
	restoreup = new Image(9,9); restoreup.src = "img/restoreup.gif";
	function restUp() { getObject("restbutton").src = restoreup.src; }
	restoredn = new Image(9,9); restoredn.src = "img/restoredn.gif";
	function restDn() { getObject("restbutton").src = restoredn.src; }
	function minimize() {
		getObject("autotoc").style.visibility = "hidden";
		getObject("smalltoc").style.display = "block";
	}
	function restore() {
		getObject("autotoc").style.visibility = "visible";
		getObject("smalltoc").style.display = "none";
	}
		
	function findTextNode(node) {
		var result;
		for(var i=0, child; (child = node.childNodes[i]); i++) {
			if(child.nodeName == "#text")
				return child.nodeValue;
			result = findTextNode(child);
			if(result != "")
				return result;
		}
		return "";
	}
	
	var tocwrapper = document.createElement("div"), toc, ol = document.createElement("ol"), div, img;
	var anchor, li, body = document.getElementsByTagName("body")[0], wrapper = getObject("wrapper");
	if(wrapper.insertAdjacentHTML)
		wrapper.insertAdjacentHTML("AfterBegin","<a name='top'></a>");
	else {
		anchor = document.createElement("a");
		anchor.name = "top";
		body.insertBefore(anchor,body.firstChild);
	}
	tocwrapper.id = "tocwrapper";
	
	tocwrapper.appendChild(toc = document.createElement("div"));
	toc.id = "autotoc";
	toc.appendChild(div = document.createElement("div"));
	div.id = "toplink"
	div.appendChild(img = document.createElement("img"));
	img.src = "img/minimizeup.gif";
	img.alt = "(minimize)";
	img.height = "9";
	img.width = "9";
	img.id = "minbutton";
	img.onclick = minimize;
	img.onmouseup = img.onmouseout = minUp;
	img.onmousedown = minDn;
	div.appendChild(anchor = document.createElement("a"));
	anchor.href = "#top";
	anchor.appendChild(document.createTextNode("To top"));
	
	toc.appendChild(div = document.createElement("div"));
	div.id = "tocbody";
	div.appendChild(ol);
	for(var i=1, h3; (h3 = h3s[i-1]); i++)
		if(h3.firstChild) {
			if(h3.insertAdjacentHTML)
				h3.insertAdjacentHTML("AfterBegin","<a name='" + i + "'></a>");
			else {
				anchor = document.createElement("a");
				anchor.name = i;
				h3.insertBefore(anchor,h3.firstChild);
			}
			ol.appendChild(li = document.createElement("li"));
			li.appendChild(anchor = document.createElement("a"));
			anchor.href = "#" + i;
			anchor.appendChild(document.createTextNode(findTextNode(h3)));
		}
	
	tocwrapper.appendChild(div = document.createElement("div"));
	div.id = "smalltoc";
	div.appendChild(img = document.createElement("img"));
	img.src = "img/restoreup.gif";
	img.alt = "(restore)";
	img.height = "9";
	img.width = "9";
	img.id = "restbutton";
	img.onclick = restore;
	img.onmouseup = img.onmouseout = restUp;
	img.onmousedown = restDn;
	
	body.appendChild(tocwrapper);
}
addOnload(autoInsertTOC);


/* StatCounter */

sc_project = 3634910;
sc_invisible = 1;
sc_partition = 43;
sc_security = "e785068b";


/* Other */

function openPicture(url, picWidth, picHeight) {
	window.open(url, "_blank", "width="+(picWidth+20)+",height="+(picHeight+20)+",left=100,top=50");
	return false;
}

function stripe() {
	var parent = getObject("contentinner"), alternate = true, j, div;
	for(var i=0, node; (node = parent.childNodes[i]); i++)
		if(node.className == "articleref") {
			if(alternate) {
				div = document.createElement("div");
				div.className = "alternate";
				parent.insertBefore(div, node);
				div.appendChild(node);
				for(j = 1; j <= 4; j++) {
					div = document.createElement("div");
					div.className = "corner corner" + j;
					node.appendChild(div);
				}
			}
			alternate = !alternate;
		}
}
addOnload(stripe);

