// Add the style to hide the sublinks as quick as possible
document.open();
document.write("<style>div.definition_description_list{display:none;}</style>");
document.close();

// getElementsByTagNameWithClassName
// (this one doesn't handle class attributes that have more than one className in them)
function getElementsByTagNameByClassName(element, tagname, classname) {
    var nodes = [];
    var count = 0;
    var list = element.getElementsByTagName(tagname);
    for (var i = 0; i < list.length; ++i) {
        if (list[i].className == classname) {
            nodes[count] = list[i];
            ++count;
        }
    }
    return nodes;
}

// toggle display
function toggle(e) {
    if (!e) {
        e = window.event;
    }
    if (e.target == null) {
        e.target = e.srcElement;
    }
    if (e.preventDefault) {
        e.preventDefault();
    }
    if (e.target.parentNode && e.target.parentNode.parentNode) {
        var p = e.target.parentNode.parentNode;
        var ddlist = getElementsByTagNameByClassName(p, "div", "definition_description_list");
        if (ddlist.length > 0) {
            // When toggling, IE7 is a little slow in reading the display value
            ddlist[0].style.display = (ddlist[0].style.display != "block") ? "block" : "none";
        }
    }
    return false;
}

window.onload = function() {
    // expand the menu for the current page
    var loc = document.location.toString();
    var page = loc.substr(loc.lastIndexOf('/') + 1);
    var a = document.getElementsByTagName("a");
    for (var i = 0; i < a.length; ++i) {
        if ((a[i].getAttribute("href") == page || a[i].getAttribute("href") == document.location) && a[i].parentNode && a[i].parentNode.parentNode) {
            var p = a[i].parentNode.parentNode;
            if (p.className == "definition_description_list") {
                p.style.display = "block";
            }
        }
    }
    
    // add onclick listeners
    var tog = getElementsByTagNameByClassName(document, "div", "definition_list_group");
    for (var i = 0; i < tog.length; ++i) {
        var dts = getElementsByTagNameByClassName(tog[i], "div", "definition_term");
        if (dts.length > 1) {
            var link = dts[1].getElementsByTagName("a");
            if (link.length != 0) {
                link[0].onclick = toggle;
            }
        }
    }
};