function extraCSS() {
	var extraCSS = document.createElement('link');
	extraCSS.setAttribute('href','annotations_js.css');
	extraCSS.setAttribute('rel','stylesheet');
	extraCSS.setAttribute('type','text/css');
	document.getElementsByTagName('head')[0].appendChild(extraCSS);
}
function addAnnotTitle() {
	var annot_title = document.createElement('div');
	annot_title.setAttribute('id', 'annot_title');
	annot_title.appendChild(document.createTextNode(""));
	document.getElementsByTagName('body')[0].appendChild(annot_title);
}
function addEvents() {
	var aclinks, i;
	aclinks = document.getElementsByTagName('a');
	for (i=0; i<aclinks.length;i++) {
		var aclink = aclinks[i];
		if (/annotation/.test(aclink.className)) {
			aclink.onmouseover = function() { return showAnnotation( this ); };
			aclink.onfocus = function() { return showAnnotation( this ); };
			aclink.onmouseout = function() { return hideAnnotation( this ); };
			aclink.onblur = function() { return hideAnnotation( this ); };
		} 
	}
}
function showAnnotation( annot_link ) {
	var pos = findPos(annot_link);
	var annot_title = document.getElementById('annot_title');
	var annot_link_width = annot_link.width;
	annot_title.appendChild(document.createTextNode(annot_link.title));
	annot_title.style.left=(pos[0]+annot_link.offsetWidth)+'px';
	annot_title.style.top =(pos[1])+'px';
	return false;
}
function hideAnnotation( annot_link ) {
	var annot_title = document.getElementById('annot_title');
	annot_title.style.left='-9999em';
	while( annot_title.firstChild ) {annot_title.removeChild(annot_title.firstChild);}
	return false;
}
function findPos(obj) {
	var curleft = 0;
	var curtop = 0;
	if (obj.offsetParent) {
		do {
		curleft += obj.offsetLeft;
		curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}
function addLoadEvent(func) {
	var oldonload = window.onload;
	if(typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}
addLoadEvent(addEvents);
addLoadEvent(extraCSS);
addLoadEvent(addAnnotTitle);
