
/* Returns the first sibling after node that satisfies predicate, or
 * null if there is no such sibling. */

function nextQualifiedSibling(node,predicate) {
    var sibling = node.nextSibling;
    while ( sibling && !predicate(sibling) ) {
	sibling = sibling.nextSibling;
    }
    return sibling;
}

function nextElementSibling(node) {
     var sibling = node.nextSibling;
     while( sibling && sibling.nodeType != 1 ) {
	 sibling = sibling.nextSibling;
     }
     return sibling;
}
     
function makeToggle(toggle,togglee) {
    var toggleeSibling = togglee.nextSibling;
    var toggleeParent  = togglee.parentNode;
    var msg = document.createTextNode(" (less)");
    var a   = document.createElement("a");
    a.appendChild(msg);
    a.className = "toggleButton";
    toggle.appendChild(a);
    toggle.onclick = function() {
	if ( msg.data == "(more)" ) {
	    msg.data = "(less)";
	    toggleeParent.insertBefore(togglee,toggleeSibling);
	} else {
	    msg.data = "(more)";
	    toggleeParent.removeChild(togglee);
	}
    };
}

/* The onload function simply grabs the "dt" elements in the "dl" with
 * id "announcements", installs a nextToggler for the onclick
 * property, and, importantly, calls it. This call to the listener
 * performs the hiding action, so that the appropriate elements are
 * hidden when the page first loads, but would be shown if JavaScript
 * were disabled. */
window.onload = function() {
    var dts = document.getElementById("Latest_GCF_News").getElementsByTagName("dt");
    for ( var i = 0; i < dts.length; i++ ) {
	var dd = nextQualifiedSibling(dts[i], function(node) { 
		return (node.nodeType == 1 // 1 == Node.ELEMENT_NODE
			&& node.tagName.toLowerCase() == "dd");
	    });
	if ( dd ) {
	    makeToggle(dts[i],dd);
	    dts[i].onclick();
	}
    }
}