// Modified from:
// http://alastairc.ac/2007/08/usability-enhancements-with-javascript/

// Add anchor background to each heading with an ID.
// Relies on jQuery, called by DOM ready.

function headingAnchors()
{
	var headings = $("h2[@id], h3[@id]");
	$(headings).each(function(i)
	{
		var heading = headings[i];		// This heading
		var hId = $(heading).attr("id");	// get the ID.

		// Create an anchor to add.
		var anchor = " <a href='#" + hId 
					  + "' class='headinganchor hidden'>&sect;</a>";

		// Add hover event to heading. Not sure this is a very effective use of jQuery.
		$(heading).append(anchor);
		$(heading).hover(function(){
			//alert("#" + hId + " > a");
			 $("#" + hId + " > a:last").removeClass("hidden");
		},function(){
		  $("#" + hId + " > a:last").addClass("hidden");
		});

		// Add keyboard events as equivelent
		$(heading).focus(function() { $("#" + hId + " > a").removeClass("hidden"); } );
		$(heading).blur(function() { $("#" + hId + " > a").addClass("hidden"); } );
		
	}); // end each
}

$(document).ready(function()
{
	headingAnchors();
});

