function buildContentsBox() {
    contentsBox = $('content-contents');
    if (!contentsBox) {
        // nothing to do
        return;
    }

    // get H2 headings in content
    items = $$('#content h2, #content h3, #content h4');
    if (!items) {
        // nothing to do
        return;
    }

    // get headings in order
    contentChildren = $('content').getElementsByTagName('*');
    items = new Array();
    $each(
        contentChildren,
        function(item, index, object) {
            if (item.tagName == 'H2' || item.tagName == 'H3' || item.tagName == 'H4') {
                items.push(item);
            }
        },
        this
    );

    // itterate over items
    contentsBox.innerHTML = 'Contents';
    contentsBox.innerHTML += '<ul>';
    $each(
        items,
        function(item, index, object) {
            contentsBox.innerHTML += '<li>';

            // add spaces 
            spaces = (item.tagName.charAt(1) - 2) * 2;
            while (spaces > 0) {
                contentsBox.innerHTML += '&nbsp;';
                spaces--;
            }

            // complete link and add anchor
            contentsBox.innerHTML += '<a href="#contents-' + index + '">' + item.innerHTML + '</a></li>';
            item.innerHTML += '<a name="contents-' + index + '"></a>';
        },
        this
    );
    contentsBox.innerHTML += '</ul>';
}