﻿// Contains functions for enabling information pop-up panels.
var lastPopupId;
var lastPopupClickerId;

function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
	do {
			curleft += obj.offsetLeft;
			if (obj.offsetParent) {
			    curleft -= obj.scrollLeft;
			}
		} while (obj = obj.offsetParent);}
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
	do {
			curtop += obj.offsetTop;
			if (obj.offsetParent) {
			    curtop -= obj.scrollTop;
			}
		} while (obj = obj.offsetParent);}
	return curtop;
}

function showhidePopup (id, clickerId) {
    var obj;
    var objCI;
    var objLast;
    var objCILast;
    obj = document.getElementById(id);
    objCI = document.getElementById(clickerId);
    if (obj && objCI) {
        if (obj.style.visibility=='hidden') {
            obj.style.visibility='visible';
            obj.style.top=findPosY(objCI);
            obj.style.left=findPosX(objCI) + 16;
            objCI.src='images/collapseleft.jpg';
            objLast = document.getElementById(lastPopupId);
            objCILast = document.getElementById(lastPopupClickerId);
            if ((objLast && objCILast) && (objLast!==obj)) {
                lastPopupId='';
                lastPopupClickerId='';
                if (objLast.style.visibility=='visible') {
                    showhidePopup(objLast.id,objCILast.id);
                }
            }
            lastPopupId = id;
            lastPopupClickerId = clickerId;
        }
        else {
            obj.style.visibility='hidden';
            obj.style.top=findPosY(objCI);
            obj.style.left=findPosX(objCI) + 16;
            objCI.src='images/collapseright.jpg';
            lastPopupId='';
            lastPopupClickerId='';
        }
    }
}