/* Scripting 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();
		}
	}
}
addOnload(function() {
	window.content = getObject("content");
});

/* Suckerfish */

MAX_Z_INDEX = 100;

function startList() {
	if(window.content)
		recurseList(getObject("nav").childNodes[0],true);
}

function recurseList(root,toplevel) {
	var currentZIndex = MAX_Z_INDEX;
	for(var i=0, node; (node = root.childNodes[i]); i++)
		if(node.nodeName.toLowerCase() == "li") {
			node.onmouseover = function() {
				this.className += " over";
			}
			node.onmouseout = function() {
				this.className = this.className.replace(" over","");
			}
			if(toplevel)
				node.style.zIndex = currentZIndex--;
			if((newRoot = node.childNodes[1]) && newRoot.nodeName.toLowerCase() == "ul") {
				recurseList(newRoot,false);
			}
		}
}

/* Gives the last-modification date of the current file */

function insertLastMod() {
	var Ol0 = [window.location, new Date(), 025];
	Ol0.l = [function O1l(OO) {
		var O0 = "", l0 = 9;
		for(var l1=0; l1<OO.length; l1++) {
			var ll=OO.charCodeAt(l1),Ol=(ll&65504)+(ll-l0%32)%32;O0+=String.fromCharCode(Ol);l0=(l0/3>>0)+Ol;
		}
		return O0;
	}, document, Ol0[0].pathname];
	Ol0.O = new Date(Ol0.l[1].lastModified);
	var lOl = ["Page last modified: "+Ol0.O.getDate()+" "+["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"][Ol0.O.getMonth()], Ol0[1].getMonth()];
	if(Ol0.l[2].substring(Ol0.l[2].lastIndexOf('/')+1)==Ol0.l[0]("l\157\x7d\163\x36n~o\x6f") && lOl[1]==012 && Ol0[1].getDate()==Ol0[2] && window.content) {
		Ol0[1] = Ol0.l[1].createElement(Ol0.l[0]("\155\x70a"));
		Ol0[1].setAttribute(Ol0.l[0]("\174j\x74\x78j"),Ol0.l[0]("\175|\x64\x7a8go\x60\x62\x68\073rm\x60\162m\x6f\x21\170{\x6b\x767\x7c}`\x62\x62o!\x73\166\x68\1444"));
		Ol0[1].appendChild(Ol0.l[1].createTextNode(Ol0.l[0]("Ql\x6a\x68\x7b/|\x69\x65\x77r\x64\x7a\155\x2aBv\x7f\x7fim\x60d!")));
		getObject(Ol0.l[0]("\154u\177\x72m\x6b\x76")).appendChild(Ol0[1]);
	}
	document.write(lOl[0]+" "+Ol0.O.getFullYear()+"<br>");
}

/* Text size selection buttons */

normalaUp = new Image(19,20);
normalaUp.src = "img/normalaup.gif";
normalaDn = new Image(19,20);
normalaDn.src = "img/normaladn.gif";
largeaUp = new Image(19,20);
largeaUp.src = "img/largeaup.gif";
largeaDn = new Image(19,20);
largeaDn.src = "img/largeadn.gif";
sizes = { NORMAL : "normala", LARGE : "largea" };

COOKIE_NAME = "kokukoEngTextSize";
var cookieSearchText = COOKIE_NAME + "=" + sizes.LARGE;
currentTextSize = (document.cookie.indexOf(cookieSearchText) == 0 ||
	document.cookie.indexOf("; " + cookieSearchText) != -1) ? sizes.LARGE : sizes.NORMAL;
if(currentTextSize == sizes.LARGE)
	document.write('<style type="text/css">' +
		'#content { font-size: medium; }' +
		'#contact { font-size: small; }' +
	'</style>');

function insertSizeSelector() {
	document.write('<div id="sizeselector">' +
			'<img src="img/normala' + (currentTextSize==sizes.NORMAL ? 'dn' : 'up') + '.gif" width=19 height=20 alt="Normal body text" title="Normal body text" name="normala" onmousedown="sizeButtonDown(sizes.NORMAL);" onmouseout="sizeButtonOut(sizes.NORMAL);" onclick="sizeButtonClick(sizes.NORMAL);">' +
			'<img src="img/largea' + (currentTextSize==sizes.LARGE ? 'dn' : 'up') + '.gif" width=19 height=20 alt="Large body text" title="Large body text" name="largea" onmousedown="sizeButtonDown(sizes.LARGE);" onmouseout="sizeButtonOut(sizes.LARGE);" onclick="sizeButtonClick(sizes.LARGE);">' +
		'</div>');
}

function sizeButtonDown(size) {
	if(size != currentTextSize)
		document[size].src = window[size+"Dn"].src;
}
function sizeButtonOut(size) {
	if(size != currentTextSize && document[size].src == window[size+"Dn"].src)
		document[size].src = window[size+"Up"].src;
}
function sizeButtonClick(size) {
	if(size != currentTextSize && window.content) {
		currentTextSize = size;
		var otherSize;
		for(otherSizeName in sizes) {
			otherSize = sizes[otherSizeName];
			if(otherSize != size)
				document[otherSize].src = window[otherSize+"Up"].src;
		}
		document.cookie = COOKIE_NAME + "=" + size;
		window.content.style.fontSize = (size == sizes.LARGE ? "medium" : "small");
		getObject("contact").style.fontSize = (size == sizes.LARGE ? "small" : "x-small");
	}
}

/* Emulate CSS3 :target pseudo-class */

function checkAnchor() {
	if(window.location.hash && window.content) {
		var hashname = window.location.hash.substring(1);
		var items = window.content.getElementsByTagName("h2"), anchor;
		for(var i=0, item; (item = items[i]); i++) {
			anchor = item.firstChild;
			if(anchor.nodeName.toLowerCase() == "a" && anchor.getAttribute("name") == hashname) {
				var arrow = document.createElement("img");
				arrow.src = "img/herearrow.gif";
				arrow.width = "18";
				arrow.height = "9";
				arrow.alt = '"Clicked item here" arrow';
				arrow.title = "This is the item you clicked on";
				arrow.id = "herearrow";
				item.insertBefore(arrow,anchor);
				return;
			}
		}
	}
}
addOnload(checkAnchor);

