function popupImage(filepath, width, height, e) {
	var x;
	var y;
	var xx = 46;
	var yy = 38;
	var mouse_x, mouse_y, client_width, client_height, scroll_left, scroll_top;
	if (delayCloseImage.interval) return;
	if (!popupImage.imgNode) {
		if (document.all) {
			mouse_x = event.x;
			mouse_y = event.y;
			client_width = document.body.clientWidth;
			client_height = document.body.clientHeight;
			scroll_left = document.body.scrollLeft;
			scroll_top = document.body.scrollTop;
			popupImage.imgNode = document.createElement('img');
			popupImage.imgNode.attachEvent('onclick', delayCloseImage);
			popupImage.imgNode.attachEvent('onmouseout', deleteImage);
		} else if (document.implementation) {
			mouse_x = e.pageX - window.pageXOffset;
			mouse_y = e.pageY - window.pageYOffset;
			client_width = innerWidth;
			client_height = innerHeight;
			scroll_left = window.pageXOffset;
			scroll_top = window.pageYOffset;
			popupImage.imgNode = document.createElement('img');
			popupImage.imgNode.addEventListener('click', delayCloseImage, true);
			popupImage.imgNode.addEventListener('mouseout', deleteImage, true);
		} else {
			return;
		}
	}
	if (mouse_x < client_width / 2) {
		if (mouse_x + xx + width > client_width) yy *= 2;
	} else {
		if (mouse_x - xx - width < 0) yy *= 2;
	}
	if (mouse_y < client_height / 2) {
		if (mouse_y + yy + height > client_height) xx *= 2;
	} else {
		if (mouse_y - yy - height < 0) xx *= 2;
	}
	if (mouse_x < client_width / 2) {
		x = mouse_x + xx;
		if (x + width > client_width) x = client_width - width;
	} else {
		x = mouse_x - xx - width;
		if (x < 0) x = 0;
	}
	if (mouse_y < client_height / 2) {
		y = mouse_y + yy;
		if (y + height > client_height) y = client_height - height;
	} else {
		y = mouse_y - yy - height;
		if (y < 0) y = 0;
	}
	x += scroll_left;
	y += scroll_top;
	with(popupImage) {
		imgNode.setAttribute('src', filepath);
		if (width && height) {
			imgNode.setAttribute('width', width);
			imgNode.setAttribute('height', height);
		}
		imgNode.style.position = 'absolute';
		imgNode.style.left = x + 'px';
		imgNode.style.top = y + 'px';
		imgNode.style.borderColor = '#0099FF';
		imgNode.style.borderWidth = '2px';
		imgNode.style.borderStyle = 'solid';
		imgNode.style.margin = '0';
		document.body.appendChild(imgNode);
	}
}
function deleteImage() {
	document.body.removeChild(popupImage.imgNode);
	delete popupImage.imgNode;
}
function delayCloseImage() {
	delayCloseImage.interval = true;
	setTimeout("delayCloseImage.interval=false", 600);
	deleteImage();
}
function closeImage(e) {
	var x;
	var y;
	var a;
	var b;
	if (window.createPopup) {
		x = event.x + document.body.scrollLeft;
		y = event.y + document.body.scrollTop;
		a = 2;
		b = 5;
	} else if (document.implementation) {
		x = e.pageX;
		y = e.pageY;
		a = 0;
		b = 3;
	} else {
		return;
	}
	with(popupImage) {
		if (imgNode) {
			if (x < parseInt(imgNode.style.left) + a || x > parseInt(imgNode.style.left) + imgNode.width + b || y < parseInt(imgNode.style.top) + a || y > parseInt(imgNode.style.top) + imgNode.height + b) {
				deleteImage();
			}
		}
	}
}
function popupText(text, e) {
	var y;
	var yy = 36;
	var mouse_x, mouse_y, client_width, client_height, scroll_left, scroll_top;
	if (delayCloseText.interval) return;
	if (!popupText.txtNode) {
		if (document.all) {
			mouse_y = event.y;
			client_height = document.body.clientHeight;
			scroll_left = document.body.scrollLeft;
			scroll_top = document.body.scrollTop;
			popupText.txtNode = document.createElement('div');
			popupText.txtNode.attachEvent('onclick', delayCloseText);
			popupText.txtNode.attachEvent('onmouseout', deleteText);
		} else if (document.implementation) {
			mouse_y = e.pageY - window.pageYOffset;
			client_height = innerHeight;
			scroll_left = window.pageXOffset;
			scroll_top = window.pageYOffset;
			popupText.txtNode = document.createElement('div');
			popupText.txtNode.addEventListener('click', delayCloseText, true);
			popupText.txtNode.addEventListener('mouseout', deleteText, true);
		} else {
			return;
		}
	}
	with(popupText) {
		txtNode.innerHTML = text;
		txtNode.style.position = 'absolute';
		txtNode.style.backgroundColor = '#eeeeee';
		txtNode.style.borderColor = '#0099FF';
		txtNode.style.borderWidth = '2px';
		txtNode.style.borderStyle = 'solid';
		txtNode.style.lineHeight = '1.3em';
		txtNode.style.margin = '0';
		txtNode.style.padding = '5px';
		txtNode.style.left = scroll_left + 'px';
		document.body.appendChild(txtNode);
		if (mouse_y < client_height / 2) {
			y = mouse_y + yy;
			if (y + txtNode.offsetHeight > client_height) y = client_height - txtNode.offsetHeight;
			if (y < 0) y = 0;
		} else {
			y = mouse_y - yy - txtNode.offsetHeight;
			if (y < 0) y = 0;
		}
		y += scroll_top;
		txtNode.style.top = y + 'px';
	}
}
function deleteText() {
	document.body.removeChild(popupText.txtNode);
	delete popupText.txtNode;
}
function delayCloseText() {
	delayCloseText.interval = true;
	setTimeout("delayCloseText.interval=false", 400);
	deleteText();
}
function closeText(e) {
	var x;
	var y;
	var a;
	var b;
	if (window.createPopup) {
		x = event.x + document.body.scrollLeft;
		y = event.y + document.body.scrollTop;
		a = 2;
		b = 5;
	} else if (document.implementation) {
		x = e.pageX;
		y = e.pageY;
		a = 0;
		b = 3;
	} else {
		return;
	}
	with(popupText) {
		if (txtNode) {
			if (x < parseInt(txtNode.style.left) + a || x > parseInt(txtNode.style.left) + txtNode.offsetWidth + b || y < parseInt(txtNode.style.top) + a || y > parseInt(txtNode.style.top) + txtNode.offsetHeight + b) {
				deleteText();
			}
		}
	}
}
