
function iCab_CollectAnchorsInWindow(win) {
    var anchors = "";
    if (win && win.document) {
        var treewalker = document.createTreeWalker(win.document.body, NodeFilter.SHOW_ELEMENT, null, false);
        while (treewalker.nextNode()) {
            var element = treewalker.currentNode;
            var name = element.tagName.toLowerCase();
            if ((name == "h1" || name == "h2" || name == "h3" || name == "h4" || name == "h5" || name == "h6") && iCab_IsVisible(element)) {
                var title = element.innerText
                if (anchors != "") {
                    anchors += "&";
                }
                anchors += encodeURIComponent(title)
            }
        }
    }
    return anchors;
}

function iCab_ShowAnchor(index, win) {
    if (win && win.document) {
        var treewalker = document.createTreeWalker(win.document.body, NodeFilter.SHOW_ELEMENT, null, false);
        while (treewalker.nextNode()) {
            var element = treewalker.currentNode;
            var name = element.tagName.toLowerCase();
            if ((name == "h1" || name == "h2" || name == "h3" || name == "h4" || name == "h5" || name == "h6") && iCab_IsVisible(element)) {
                index--;
                if (index < 0) {
                    element.scrollIntoViewIfNeeded(true);
                    var defaultStyle = element.style.backgroundColor;
                    if (!defaultStyle) {
                        defaultStyle = ""
                    }
                    setTimeout(function() { element.style.backgroundColor = "rgba(234, 234, 0, 0.2)"; }, 50);
                    setTimeout(function() { element.style.backgroundColor = "rgba(234, 234, 0, 0.4)"; }, 100);
                    setTimeout(function() { element.style.backgroundColor = "rgba(234, 234, 0, 0.6)"; }, 150);
                    setTimeout(function() { element.style.backgroundColor = "rgba(234, 234, 0, 0.8)"; }, 200);
                    setTimeout(function() { element.style.backgroundColor = "rgba(234, 234, 0, 1.0)"; }, 250);
                    setTimeout(function() { element.style.backgroundColor = "rgba(234, 234, 0, 0.7)"; }, 850);
                    setTimeout(function() { element.style.backgroundColor = "rgba(234, 234, 0, 0.5)"; }, 900);
                    setTimeout(function() { element.style.backgroundColor = "rgba(234, 234, 0, 0.3)"; }, 950);
                    setTimeout(function() { element.style.backgroundColor = defaultStyle; }, 1000);
                    break
                }
            }
        }
    }
}

function iCab_IsVisible(element) {
    var style = getComputedStyle(element);
    if (style.display === 'none') return false;
    if (style.visibility !== 'visible') return false;
    if (style.opacity == 0) return false;
    if (element.getBoundingClientRect().width === 0) return false;
    if (element.getBoundingClientRect().height === 0) return false;
    return true;
}


function iCab_ShowAnchorAt(index) {
    iCab_ShowAnchor(index, window)
}


var iCab_AllAnchors = iCab_CollectAnchorsInWindow(window);
iCab_AllAnchors;


