var isIE = document.attachEvent != null;
var isGecko = !document.attachEvent && document.addEventListener;

var isIE = document.all;
var light, cont, hand;

setLight = function() {
	if (!light) {
		light = document.getElementById('light');
		cont = document.getElementById('cont');
		hand = (document.getElementById('hand')) ? document.getElementById('hand') : cont;
	}

	if (document.body.scrollHeight > document.body.clientHeight) {
		var maxHeight = Math.max(cont.clientHeight, hand.clientHeight);
		if (maxHeight == cont.clientHeight) {
			var maxHeight_initiator = cont;
			var other = hand;
		} else {
			var maxHeight_initiator = hand;
			var other = cont;
		}
		light.style.height = maxHeight;
		other.style.height = maxHeight;
	} else {
		light.style.height = '100%';
		cont.style.height = '100%';
		hand.style.height = '100%';
	}

	if (document.body.scrollWidth > document.body.clientWidth) {
		light.style.width = cont.clientWidth;
	} else {
		light.style.width = '100%';
	}
}
window.onresize = function() {if (isIE) setLight();}
var a = setInterval(setLight, 1);

var currentHand = null;

function showHand_content(id) {
	paper = document.getElementById(id);
	if (!paper.container) paper.container = document.getElementById('handContent_' + id);
	showHand(paper);
}
function showHand(paper) {
	currentHand = paper;
	paper.img = paper.getElementsByTagName('img')[0];
	paper.img.srcName = new RegExp('n_' + paper.id);
	paper.img.src = paper.img.src.replace(paper.img.srcName, 'x');
	paper.setAttribute('href', paper.id + '.html');
	paper.container.style.display = 'block';
	hand.style.display = 'block';
	if (isIE) {
		document.attachEvent('onclick', hideHand);
		document.getElementById('handContent').attachEvent('onclick', prohibition);
	}
	if (isGecko) {
		document.addEventListener('click', hideHand, false);
		document.getElementById('handContent').addEventListener('click', prohibition, false);
	}
}

function hideHand() {
	var paper = currentHand;
	paper.img = paper.getElementsByTagName('img')[0];
	paper.img.src = paper.img.src.replace(/x/, ('n_' + paper.id));
	paper.setAttribute('href', paper.id + '.html');
	paper.container.style.display = 'none';
	hand.style.display = 'none';
	if (isIE) document.body.detachEvent('onclick', hideHand);
	if (isGecko) document.body.removeEventListener('click', hideHand, true);
}
function prohibition(event) {
	if (isIE) event.cancelBubble = true;
	if (isGecko) event.stopPropagation(); 
}
/* AJAX ;) */
window.request = function(elem, source) {
	window.requestIsOn = true;
	this.requestTargetElem = elem;
	this.requestTargetElem.innerHTML = '';
	window.iFrame = document.createElement('iframe');
	window.iFrame.style.display = 'none';
	window.iFrame.src = source;
	elem.appendChild(window.iFrame);
}
window.setInner = function(str) {
	this.requestTargetElem.innerHTML = str;
	window.requestIsOn = false;
	window.iFrame.src = '';
}
function request_hand(elem, caller, action) {
	caller.action = action;
	window.request(elem, caller.getAttribute('id'));
}
window.setInner_hand = function(str) {
	window.setInner(str);
	window.requestIsOn = false;
	if (action) eval(action + '(' +  + ')');
}
