/**
 * @version		1.0
 * @author		Timothy Groves	desk [at] brandspankingnew.net
 * @package		formatFootnotes JavaScript Standard Version * @since		26/01/2006
 */

var articles = 0;

function formatFootnotes(root,contID,noteID)
{
	// check for DOM capabilities
	if (!document.getElementById)
		return false;

	var cont = document.getElementById(contID);
	var noteholder = document.getElementById(noteID);
	var spans = cont.getElementsByTagName("span");
	
	var notes = 0;
	articles++;
	
	for (i=0;i<spans.length;i++)
	{
		if (spans[i].className == "footnote")
		{
			// get content of span
			var noteNode = spans[i].cloneNode( true );
			
			// remove css styling
			noteNode.className = "";
		
			// create a new div to hold the footnote
			var newEle = document.createElement( "div" );

			notes++;
			
			newEle.appendChild( document.createTextNode( notes + ". " ) );
			newEle.appendChild( noteNode );
			
			// add backlink
			blink = document.createElement("a");
			blink.href = root+"#ftnlink"+articles+"_"+notes;
			blink.innerHTML = " [&uarr;]";
			newEle.appendChild( blink );
			 
			noteholder.appendChild( newEle );
			
			// add id & style
			noteholder.lastChild.id = "ftn"+articles+"_"+notes;
			noteholder.lastChild.className = "footnote";
			
			
			// insert link into span
			var newEle = document.createElement( "a" );
			newEle.href = root+"#"+noteID;
			newEle.title = "";
			newEle.id = "ftnlink"+articles+"_"+notes;
			newEle.className = "ftnlink";
			
			newEle.appendChild( document.createTextNode( "["+notes+"]" ) );
			
			// empty span
			while (spans[i].childNodes.length)
				spans[i].removeChild( spans[i].firstChild );
			
			spans[i].appendChild( newEle );
			
		} else if (spans[i].className == "footnoteref") {
		
			// remove css styling
			spans[i].className = "footnote";
		
			notes = spans[i].firstChild.nodeValue;
			
			// insert link into span
			var newEle = document.createElement( "a" );
			newEle.href = root+"#"+noteID;
			newEle.title = "";
			newEle.id = "ftnlink"+articles+"_"+notes;
			newEle.className = "ftnlink";
			
			newEle.appendChild( document.createTextNode( "["+notes+"]" ) );
			
			// empty span
			while (spans[i].childNodes.length)
				spans[i].removeChild( spans[i].firstChild );
			
			spans[i].appendChild( newEle );
		}
	}
	
}
