// based on http://www.brandspankingnew.net/specials/footnote_2.html
// not tested with multiple footnotes

var notes;
var active;
function formatFootnotes()
{
	var cont = document.getElementById("primary");
	var noteholder = document.getElementById("footnotes");
	var spans = cont.getElementsByTagName("span");

	notes = 0;
	active = 0;
	for (i=0;i<spans.length;i++)
	{
		if (spans[i].className == "footnote")
		{
			notes++;
			noteholder.innerHTML += "<div class='footnote' id='ftn"+notes+"'>" + notes + ". " + spans[i].innerHTML + "</div>";
			spans[i].innerHTML = "<span onclick='showFootnote(\"ftn"+notes+"\")' title='view sidenote' class='ftnlink'>" + notes + "</span>";
		}
	}
}
function showFootnote(ftnID)
{
	// hide active footnote would be good to set timer for highlighting, else turn off highlighing when another is clicked
	if (active)
		document.getElementById(active).className = "dormant";	
	  active = ftnID;	
	  // highlight new footnote
	  document.getElementById(active).className = "highlighted";
}

function addLoadEvent(func) {
  // execute functions on page load
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}
addLoadEvent(formatFootnotes);