var hide  = true;

function showHide(obj,msg)
{
	var x = document.getElementById('popup');
	hide = !hide;
	x.style.visibility = (hide) ? 'hidden' : 'visible';
	setPopup(obj,'popup',msg);
}

function setPopup(obj,layer,msg)
{
	var coors = findPos(obj);
	if (layer == 'popup') coors[1] -= 50;
	var x = document.getElementById(layer);

	if (msg == 'things to be happy about')
		x.style.top = (coors[1] + 80) + 'px';
	else if (msg == 'things to be happy about today')
		x.style.top = (coors[1] + 120) + 'px';
	else
		x.style.top = (coors[1] + 40) + 'px';

	if ((msg == 'return to village') && (obj.style.position != 'relative'))
		x.style.left = (coors[0] + 350) + 'px';
	else
		x.style.left = (coors[0] + 40) + 'px';

	//if (msg == 'about this book' || msg == 'purchase on Amazon')
	//	x.style.left = (coors[0] + 375) + 'px';	
	
	if (msg == 'things to be happy about')
		msg = "<strong>" + msg + "</strong>";
	
	x.innerHTML = msg;
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
