/**
 * Use closure, to hide all local variables.
 */
(function() {

function referencedContainer(link) {
    return document.getElementById( link.href.replace(/^.*#([a-z]+)$/, "$1") );
}

function initDynamicContacts() {
    // if the page contains juhatus-nav
    var juhatusNav = document.getElementById("juhatus-nav");
    if (juhatusNav) {
        // get all links in juhatus-nav
        var links = juhatusNav.getElementsByTagName("a");

        // get containers, that those links reference
        var containers = map(links, referencedContainer );

        // assign onclick function to each link
        each(links, function(link) {
            link.onclick = function() {
                // when link is clicked, hide all containers
                each(containers, hide);
                // and make only the associated container visible
                show( referencedContainer(link) );

                // make all links not bold
                each(links, function(link){link.style.fontWeight = "normal";} );
                // make the clicked link itself bold
                link.style.fontWeight = "bold";

                return false;
            };
        });

        // now click the first element
        links[0].onclick();
    }
}


Handler.add(window, "load", initDynamicContacts);

})();