/* By PG. Takes exisiting anchors in headers and duplicates. 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. 
This version is used for Gateway Hub, Capacity Planner and Global Docs */

$(document).ready(function() {
		function duplicateAnchors() {
			var $a1 = $(':header').find('a[data-mc-generated-bookmark]');
			$a1.each(function() {
					var $aname = $(this).attr('name');
					var $parentH = $(this).parent();
					$(this).attr('class', 'anchor_offset');
					$parentH.append($('<a class="icon-bookmark" title="Link to this header" href="#' + $aname + '"></a>'));
				})
		}

		duplicateAnchors()

		function injectStyles(rule) {
			var div = $("<div />", {
			html: '&shy;<style>' + rule + '</style>'
			}).appendTo("body");
			}

		injectStyles('h1 > a.anchor_offset, 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;}');

		function otherAnchors() {
			var $a2 = $(':header').find('a:not(.icon-bookmark):not(.anchor_offset)');
			$a2.attr('class', 'anchor_offset')
		}

		otherAnchors()

		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"});
		}
		
	});