
function showPopup (obj, targetObjectId, eventObj, xOffset, yOffset) {
    if(eventObj) {
	// hide any currently-visible popups
	hideCurrentPopup();
	// stop event from bubbling up any farther
	eventObj.cancelBubble = true;
	// move popup div to current cursor position 
	// (add scrollTop to account for scrolling for IE)	
	
	var curElementLocation = findPos(obj);
	
	var newXCoordinate = curElementLocation[0] + xOffset;
	var newYCoordinate = curElementLocation[1] + yOffset;
		
	moveObject(targetObjectId, newXCoordinate, newYCoordinate);

	// and make it visible
	if( changeObjectVisibility(targetObjectId, 'visible') ) {
	    // if we successfully showed the popup
	    // store its Id on a globally-accessible object
	    window.currentlyVisiblePopup = targetObjectId;
	    return true;
	} else {
	    // we couldn't show the popup, boo hoo!
	    return false;
	}
    } else {
	// there was no event object, so we won't be able to position anything, so give up
	return false;
    }
} // showPopup

function hideCurrentPopup() {
    // note: we've stored the currently-visible popup on the global object window.currentlyVisiblePopup
    if(window.currentlyVisiblePopup) {
	changeObjectVisibility(window.currentlyVisiblePopup, 'hidden');
	window.currentlyVisiblePopup = false;
    }
} // hideCurrentPopup

//================================================

function findPos(obj) {
	var curleft = curtop = 0;
	
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		
		while (obj = obj.offsetParent) {
	       
		    //the div with ID wrap is the container element that all items are contained in and where left and top styles appear to use for positioning
		    //so when we get to it, we break out of the loop
		    if (obj.id == "wrap")
		    {
		        break;
		    }
		    
		    curleft += obj.offsetLeft;
		    curtop += obj.offsetTop;
		}
	}
	
	//alert (curleft + " : " + curtop);
	
	return [curleft,curtop];
}

//=========================================
/*
function getPosition(e) {
    e = e || window.event;
   
    var cursor = {x:0, y:0};   
    
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
        
        alert ("ff " + cursor.x + " : " + cursor.y);
        
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        
        alert (de.scrollTop);
        
        cursor.x = e.clientX + de.scrollLeft; //+ (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY+ de.scrollTop; // + (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
        
        alert ("ie " + cursor.x + " : " + cursor.y);
    }   
    
    return cursor;
}
*/
//========================================


// ***********************
// hacks and workarounds *
// ***********************

// setup an event handler to hide popups for generic clicks on the document
document.onclick = hideCurrentPopup;







