$(document).ready(function(){
	//get the container and target
	var links = $('#content a[href]:not(#sharestory a,[href^=#],[href^=mailto],[rel=nofollow])');

	if($(links).length){
		//create a container and heading for the footnotes
		var footnotesWrapper = $('<div>', {
			css: {
				clear: 'both'
			}
		}).addClass('footnote');
		var footnotesLabel = $('<h4>', {
			text: 'Links in This Document:'
		}).appendTo(footnotesWrapper);

		//create an OL to hold the footnotes
		var footnoteList = $('<ol>').appendTo(footnotesWrapper);

		$.each(links, function(i){
			var linkText = $(this).text();
			var linkValue = $(this).attr('href');
			if(linkValue.substring(0,1) === '/'){
				linkValue = document.location.host + linkValue;
			}
			//create element to hold span with class to hide except on print
			var newElement = $('<sup>', {
				text: ' ['+ ++i +']'
			}).addClass('print-footnote').appendTo($(this));

			var listEntry = $('<li>', {html: '<span>'+linkValue+'</span>'}).appendTo(footnoteList);
		});

		// append the heading and <ol> to the target
		$('#wrap-footer').append(footnotesWrapper);
	}
});
