var curr;
var reftext;
var aj;

function AJAX(isxml) {
	this.xmlhttp;
	this.isxml = isxml;
	this.func;
	try {
		this.xmlhttp = new XMLHttpRequest();
	}
	catch (e) {
		try {
			this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			try {
				this.xmlhttp = new ActiveXObject("Msxml.XMLHTTP");
			}
			catch (e)  {
				this.xmlhttp = null;
			}
		}
	}
	if (this.xmlhttp) {
		this.ajactive = false;
	}
}

AJAX.prototype = {
	supportsAJAX : function() { 
		return (typeof(this.xmlhttp) !== "undefined"); 
	},
	get : function(url, func, async) {
		this.func = func;
		this.xmlhttp.open("GET", url + "?ts=" + Math.random() * 100000, async);
		this.xmlhttp.onreadystatechange = AJAX.handleResp;
		this.xmlhttp.send(null);
		this.ajactive = true;
	},
	getRespObj : function() {
		return (this.isxml ? this.xmlhttp.responseXML : this.xmlhttp.responseText);
	},
	docReady : function() {
		return (this.xmlhttp.readyState == 4);
	}
}

AJAX.handleResp = function(e) {
	if (aj.docReady()) {
		aj.func(aj.getRespObj());
	}
}

function showRef(xmlDoc) {
	if (xmlDoc) {
		var refbody = xmlDoc.getElementsByTagName('rbody')[0].firstChild.nodeValue;
		var refname = xmlDoc.getElementsByTagName('rname')[0].firstChild.nodeValue;
		var refid = xmlDoc.getElementsByTagName('rname')[0].getAttribute('id');
		if (refid == curr.id) {
			reftxt.innerHTML = refbody + refname;
		}
	}
}

window.onload = function() {
	curr = document.getElementById("NatalieBlake");
	reftxt = document.getElementById("reftext");
	aj = new AJAX(true);
	if (!aj.supportsAJAX()) {
		alert("Your browser does not support AJAX. Please use an up-to-date browser to view the references");
		return;
	}
	var reflis = document.getElementById("reflist").getElementsByTagName('li');
	for (var i = 0; i < reflis.length; ++i) {
		reflis[i].onmouseover = function() { if (curr.id == this.firstChild.id) return; curr.parentNode.className = ''; this.className = 'curref'; curr = this.firstChild; aj.get("./" + curr.id + ".xml", showRef, true); };
	}
}
