$(document).ready(function(){
	$("span.footnote").hide();
    
    $("span.footnote").click(function(){
        $(this).hide();
    });
    
    $("a.footref").click(function(){
		var footspan = $(this).siblings("span.footnote");
        var content = window.document.getElementsByTagName("body")[0];
        footspan.toggle();

		//Get height of footnote box, and if the box would appear off the bottom of the screen
        //scroll window by that amount + 5 pixels.
        var fsobj = footspan.get(0);
		var fh = fsobj.clientHeight;  // Get height of span.footnote box
        //If the box is visibile (height > 0) and the bottom of the box is at the bottom
        //of the window, then scroll.
        if (fh > 0 && fsobj.offsetTop + fh >= content.scrollHeight) window.scrollBy(0,fh + 5);
	  	return false;
	});
});
