

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = document.getElementById(objectId);
    if(styleObject) {
	styleObject.style.visibility = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility

function moveObject(objectId, newXCoordinate, newYCoordinate) 
{
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = document.getElementById(objectId);
    
    if(styleObject) 
    {
	    styleObject.style.left = newXCoordinate + "px";
	    styleObject.style.top = newYCoordinate + "px";
	    
	    return true;
    } 
    else 
    {
	    // we couldn't find the object, so we can't very well move it
	    return false;
    }
} // moveObject


// store variables to control where the popup will appear relative to the cursor position
// positive numbers are below and to the right of the cursor, negative numbers are above and to the left

function showPopup (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 
	    var posx = 0;
	    var posy = 0;
	    
	    if (!eventObj) 
	        var e = window.event;
	    
	    if (eventObj.pageX || eventObj.pageY) 	
	    {
		    posx = eventObj.pageX;
		    posy = eventObj.pageY;
	    }
	    else if (eventObj.clientX || eventObj.clientY) 	
	    {
		    posx = eventObj.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
		    posy = eventObj.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
	
	    // posx and posy contain the mouse position relative to the document
        moveObject(targetObjectId, posx + xOffset, posy + yOffset);
	    // 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




