var currobj = null
var currpop = null

function setactive() {
	var obj=event.srcElement
	if (currpop) currobj = obj
	else currpop = obj
}

function waitandtest(imgName) {
	currobj = null
	setTimeout("testpop('" + imgName + "')",200)
}

function testpop(imgName) {
	if (currobj) return
	if (currpop) {
		//currpop.style.visibility="hidden"
		hideCurrentPopup()

		// Change to our non-rollover state
		//document.images[imgName].src = eval(imgName + ".src");
		currpop = null
	}
}





// 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
var xOffset = 30;
var yOffset = -5;

function showPopup (targetObjectId, eventObj) {
	// Displays a popup relative to current cursor position

    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 newXCoordinate = (eventObj.pageX)?eventObj.pageX + xOffset:eventObj.x + xOffset + ((document.body.scrollLeft)?document.body.scrollLeft:0);
	var newYCoordinate = (eventObj.pageY)?eventObj.pageY + yOffset:eventObj.y + yOffset + ((document.body.scrollTop)?document.body.scrollTop:0);
	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 showPopupreltoImg (targetObjectId, imgName, xoffset, yoffset) {
//alert(targetObjectId)
	// displays popup relative to an image
	hideCurrentPopup();

	// Now get the image coordinates
	var newXCoordinate = 0
	var newYCoordinate = 0
	if(document.getElementById) {
		var img = document.getElementById(imgName)
		if (!document.all) {
			newXCoordinate = img.offsetLeft
			newYCoordinate = img.offsetTop
		} else {
			i = topPos(img)
			nexYCoordinate = topPos(img)
			newXCoordinate = leftPos(img)
			newYCoordinate = i
		}
	} else if (document.layers) {
		newXCoordinate = document.images[imgName].x
		newYCoordinate = document.images[imgName].y
	} else if (document.all) {
		// IE 4
		var img = document.all(imgName)
		newXCoordinate = leftPos(img)
		newYCoordinate = topPos(img)
	}

	moveObject(targetObjectId, newXCoordinate+xoffset, newYCoordinate+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;
	}

} // showPopupImage




function moveobjectRelativeToImage (targetObjectId, imgName, xoff, yoff) {

	// Now get the image coordinates
	var newXCoordinate = 0
	var newYCoordinate = 0

	if(document.getElementById) {

		var img = document.getElementById(imgName)
		if (!document.all) {
			newXCoordinate = img.offsetLeft
			newYCoordinate = img.offsetTop


		} else {
			i = topPos(img)
			nexYCoordinate = topPos(img)
			newXCoordinate = leftPos(img)
			newYCoordinate = i

		}
	} else if (document.layers) {
		newXCoordinate = document.images[imgName].x
		newYCoordinate = document.images[imgName].y

	} else if (document.all) {
		// IE 4
		var img = document.all(imgName)
		newXCoordinate = leftPos(img)
		newYCoordinate = topPos(img)

	}
//alert("Current image x = " + newXCoordinate)
//alert("Current image Y = " + newYCoordinate)


	moveObject(targetObjectId, newXCoordinate+xoff, newYCoordinate+yoff);


} 


function setCaption(targetObjectId, caption) {
	if (document.getElementById) {
		var obj = document.getElementById(targetObjectId)
		if(document.all) {
			obj.innerText = caption
		} else {
			obj.childNodes[0].nodeValue = caption
		}

	} else if (document.all) {
		var obj = document.all[targetObjectId]
		obj.innerText = caption
	}
	
}




function hideCurrentPopup() {
//alert("hiddding....")
    // 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






// ***********************
// hacks and workarounds *
// ***********************

// initialize hacks whenever the page loads
//window.onload = initializeHacks;

// setup an event handler to hide popups for generic clicks on the document
document.onclick = hideCurrentPopup;

function initializeHacks() {
    // this ugly little hack resizes a blank div to make sure you can click
    // anywhere in the window for Mac MSIE 5
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	window.onresize = explorerMacResizeFix;
    }
    resizeBlankDiv();
    // this next function creates a placeholder object for older browsers
    createFakeEventObj();
}

function createFakeEventObj() {
    // create a fake event object for older browsers to avoid errors in function call
    // when we need to pass the event object to functions
    if (!window.event) {
	window.event = false;
    }
} // createFakeEventObj

function resizeBlankDiv() {
    // resize blank placeholder div so IE 5 on mac will get all clicks in window
    if ((navigator.appVersion.indexOf('MSIE 5') != -1) 
	&& (navigator.platform.indexOf('Mac') != -1)
	&& getStyleObject('blankDiv')) {
	getStyleObject('blankDiv').width = document.body.clientWidth - 20;
	getStyleObject('blankDiv').height = document.body.clientHeight - 20;
    }
}

function explorerMacResizeFix () {
    location.reload(false);
}
















// Utility functions
function getObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId);
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId);
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getObject

function getStyleObject(objectId) {
    // cross-browser function to get an object's style object given its id
    if(document.getElementById && document.getElementById(objectId)) {
	// W3C DOM
	return document.getElementById(objectId).style;
    } else if (document.all && document.all(objectId)) {
	// MSIE 4 DOM
	return document.all(objectId).style;
    } else if (document.layers && document.layers[objectId]) {
	// NN 4 DOM.. note: this won't find nested layers
	return document.layers[objectId];
    } else {
	return false;
    }
} // getStyleObject

function changeObjectVisibility(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
//alert(objectId)
//alert(styleObject)
    if(styleObject) {
	styleObject.visibility = newVisibility;
//alert(styleObject.visibility)
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectVisibility


function changeObjectDisplay(objectId, newVisibility) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
	styleObject.display = newVisibility;
	return true;
    } else {
	// we couldn't find the object, so we can't change its visibility
	return false;
    }
} // changeObjectDisplay


function moveObject(objectId, newXCoordinate, newYCoordinate) {
//alert(objectId + ":" + newXCoordinate + ":" + newYCoordinate)
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
		if (document.layers) {
			styleObject.left = newXCoordinate;
			styleObject.top = newYCoordinate;
//alert(newXCoordinate)
//alert(newYCoordinate)
		} else if (document.getElementById || document.all) {
			styleObject.left = newXCoordinate + "px";
			styleObject.top = newYCoordinate + "px";
		}

	return true;
    } else {

	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject




function moveObjectLeft(objectId, newXCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
		if (document.layers) {
			styleObject.left = newXCoordinate;
		} else if (document.getElementById || document.all) {
			styleObject.left = newXCoordinate + "px";
		}

	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject


function moveObjectTop(objectId, newYCoordinate) {
    // get a reference to the cross-browser style object and make sure the object exists
    var styleObject = getStyleObject(objectId);
    if(styleObject) {
		if (document.layers) {
			styleObject.top = newYCoordinate;
		} else if (document.getElementById || document.all) {
			styleObject.top = newYCoordinate + "px";
		}

	return true;
    } else {
	// we couldn't find the object, so we can't very well move it
	return false;
    }
} // moveObject





function topPos(el) {
	return doPosLoop(el, "Top");
}

function leftPos(el) {
	return doPosLoop(el, "Left");
}

function doPosLoop(el, val) {
	var temp = el;
	var x = eval("temp.offset" + val);
	while ((temp.tagName!="BODY") && (temp.offsetParent.style.position != "absolute")) {
		temp = temp.offsetParent;
		x += eval("temp.offset" + val);
	} return x;
}

