window.onload = initAll;

function initAll() {
    setupToggleView();
}

function setupToggleView() {
    // first, get all the divs
    var divs = document.getElementsByTagName("div");

    // Step through them
    for (i=0; i<divs.length; i++) {

        // I only want ones in the "section" class
        if (divs[i].className.indexOf("section") > -1) {
            var dome = divs[i].childNodes;
            var toggler = null;
            var nodes = new Array();
            for (j=0; j<dome.length; j++) {
                var child = dome[j];
                // skip non-tags
                if (child.nodeType !=1) {
                    continue;
                }
                // skip first h2 (but keep track of it)
                if ((toggler == null) && (child.nodeName == "H2")) {
                    toggler=child;
                    continue;
                }
                // add to the list of things to change
                nodes[nodes.length] = child;
            }

            // set up stuff
            if (toggler != null) {
                toggler.toggleThese = nodes;
                toggler.onclick = toggleView;
            }
        }
    }
}

// change what is visible based on a list of nodes
function toggleView() {
    for (i=0; i<this.toggleThese.length; i++) {
        var node = this.toggleThese[i];
        node.style.display = ((node.style.display == '') ? 'none' : '');
    }
}
