/* 
	for the interactive historical context page.
	we install special rollovers on the small photos,
	and extend the "popopen" functionality to handle
	SWAPPING popopens, not TOGGLING them.
*/

// the open DETAIL box (below, on click), and the open INFO box (on the right, on rollover)
var curDetailID='', curInfoID='', masterTimer=0;

// this is our special preProcess handler for the popopen business. here
// we toggle the previously-open DETAIL box, and set a class on the newly
// opening box (for a strong hilight). "opening" is always true (closing
// is done manually, in togglePopper below)
//
function popopen( openingElt, opening) {
	var newID = openingElt.id;
	if ( curDetailID == newID)
		return true;

	if ( curDetailID.length > 0) {
		var oldElt = document.getElementById(curDetailID);
		oldElt.togglePopper();	// hide the old
		setCls(oldElt,'popopen');
	}
	curDetailID = newID;
	setCls(openingElt,'popopen on');
}

// mouseover routine -- shows the INFO box (and hides the old one)
//
function showInfo( newID) {
	clearTimeout( masterTimer);
	if ( curInfoID == newID)
		return;
	
	if ( curInfoID.length > 0)
		document.getElementById(curInfoID+'Info').style.display = "none";
	document.getElementById(newID+'Info').style.display = "block";
	curInfoID = newID;
}

// mouseout routine -- redisplay the CLICKED item in the info section (after a spell)
//
function startCountdown() {
	if ( curDetailID.length > 0) {
		clearTimeout( masterTimer);
		masterTimer = setTimeout("showInfo('"+curDetailID+"')", 500);
	}
}

// add pre & post processing hooks to the popopen links
function setupContextLinks() {
	var maxPeopleCt=25, i, a;
	
	for ( i=1; i<=maxPeopleCt; ++i) {
		a = document.getElementById('a'+i);
		if (!a) break;
		a.preProcess = function(opening) { return popopen(this, opening); }
		a.postProcess = function(opening) { if(opening) fadingHilight(this.id+'Pop',8,70,"#FFE3ED","#FFFFFF"); }
		a.onmouseover = function() { showInfo(this.id); }
		a.onmouseout = function() { startCountdown(); }
	}
}

// this is why this JS must be loaded at the end of the document
addLoadEvent(setupContextLinks);
