// NOTE: init() must be assigned to onLoad event handler in the body tag.
// Global variable "refs" required: Array of strings. refs[0] = "References:"; the rest are
//	one reference per array entry, starting with te reference number. Since zero is taken
//	by the section heading, indixesof the remaining references match reference numbers.
// version 2 - onmouseover and onmouseout assigned by script, not in every tag. NS4 only.
// version 3 - works on IE4
//           - Displays on IE3, but not on NS3 (script inside table screws it up) (24k)
// version 4 - graceful degradation on non Javascript browsers
//           - displays properly on NS3 and NS4 with CSS and JS turned off 
//           - reference data repeated in HTML (30k)
// version 5 EXPERIMENTAL! - try to have the reference information be copied from the HTML for the popups.
// version 6 - derives from version 4 - Javascript moved to external file.

// global variables
var isNS = isIE = is4up = false;
var refs;	// array of references
var pT;	// positionable thingy

if (navigator.appName == "Netscape") isNS = true;
if (navigator.appName == "Microsoft Internet Explorer") isIE = true;


if (parseInt(navigator.appVersion) >= 4){
	is4up=true;
}

// alert("isNS = " + isNS + "\nisIE = " + isIE + "\nis4up = " + is4up);

function popOn(evt){
	var topVal,leftVal,targetString;
	if (isNS) {
		topVal = eval(evt.pageY + 6);
		leftVal = eval(evt.pageX - 125);
		targetString = evt.target;
	}
	if (isIE) {
		topVal = eval(document.body.scrollTop + event.clientY + 19);	// event.y wrong on IE4Mac
		leftVal = eval(document.body.scrollLeft + event.clientX - 125);
		targetString = event.srcElement;
	}
	// keep box in viewable area
	if (leftVal < 2) {
		leftVal = 2;
	}
	if (leftVal > 375) {
		leftVal = 375;
	}
	// keep ref box from going off bottom of screen?
	// test topVal vs (document.body.clientTop + document.body.clientHeight) in IE ?

	pT.top = topVal;
	pT.left = leftVal;
	var numPattern = new RegExp("#([0-9]+)","g");
	numPattern.exec(targetString);	// could count characters rather than using RegExp
	var refNum = parseInt(RegExp.$1,10);
	var str = refs[refNum];
	if (isNS){
		pT.document.open();
		pT.document.write('<span CLASS="ref">' + str + '<\/span>');
		pT.document.write(" ");
		pT.document.close();
		pT.document.close();
	}
	if (isIE){
		document.all.ht.innerHTML = str;
	}
	pT.visibility = "visible";
	return true;
}

function popOff(evt){
	pT.visibility = "hidden";
}

function init(){
	if ( is4up ){	// initalize pT
		var doc = (isNS) ? 'document' : 'document.all';
		var style = (isNS) ? '' : '.style';
		pT = eval(doc + '.ht' + style);
		for (var i=0;i<document.links.length;i++){	// initialize mouseover handlers
	//		if (document.links[i].text == parseInt(document.links[i].text,10)){
			if (document.links[i].href.match(/#([0-9]+)/)){	// links to reference anchors
				document.links[i].onmouseover=popOn;
				document.links[i].onmouseout=popOff;
			}
		}
	}
}

