$(document).ready(function() {
				
	/* Duplicate existing anchors in headers. Creates anchor with bookmark/permalink (class="icon-bookmark"),
	and offsets the existing anchor by -150px (class="anchor-offset") to account for fixed bar at top of each webpage. */
		
	function duplicateAnchors() {
		var $a1 = $(':header').not('h1').find('a').not('.old_type_bm');
		$a1.each(function() {
		var $aname = $(this).attr('name');
		$(this).attr('class', 'anchor_offset');
		$(this).attr('id', '')			
		$(this).before($('<a class="icon-bookmark" title="Link to this header" href="#'+$aname+'"></a>'));
	})
	}			
		
	duplicateAnchors()
	
	// Provide style for duplicated anchors.	
		
	function injectStyles(rule) {
		var div = $("<div />", {
		html: '&shy;<style>' + rule + '</style>'
		}).appendTo("body");    
		}

		injectStyles('h2 > a.anchor_offset, h3 > a.anchor_offset, h4 > a.anchor_offset, h5 > a.anchor_offset, h6 > a.anchor_offset{display: block;position:relative;top:-200px;visibility:hidden;}');
		
	// Highlight the correct part of the document after accessing a link from the GSE CSH.
		
	if (window.location.search.includes("cshid")) {
		$(":header a[href='" + window.location.hash + "']").closest("div").css({"background-color":"#FFFFCC"});
		$("a[name='" + window.location.hash.replace('#', '') + "']").closest("tr").css({"background-color":"#FFFFCC"});
	}	
});