function toggleCollapse(heading_element, placeholder) {
	if (heading_element.hasClassName('collapsed-heading')) {
		heading_element.removeClassName('collapsed-heading');
		heading_element.addClassName('collapsible-heading');
		heading_element.nextSiblings()[0].removeClassName('collapsed');
	} else {
		heading_element.removeClassName('collapsible-heading');
		heading_element.addClassName('collapsed-heading');
		heading_element.nextSiblings()[0].addClassName('collapsed');
	}
}

function expandSection() {
	expandSectionWithURL(window.top.location.href);
}

function expandSectionWithURL(url){
	var hashIndex = url.lastIndexOf("#");
	if(hashIndex > -1) {
		var link = "id_" + url.substring(hashIndex+1, url.length);
		if($(link).className == "collapsible-heading") {
			//if already expanded, return.
			return;
		}
		toggleCollapse($(link))
	}
}

function setUpAnchors() {
	var i = 0;
	var anchor;

	while((anchor=document.getElementsByTagName('a').item(i))) {
		if(anchor.href.indexOf('#') != -1){
			anchor.onclick = function expand() { expandSectionWithURL(this.href); };
		}
		i++;
	}
}

if (window.addEventListener) {
        window.addEventListener("load", expandSection, false);	// firefox
		window.addEventListener("load", setUpAnchors, false);
} else if (window.attachEvent){
    	window.attachEvent("onload", expandSection);	// IE
    	window.attachEvent("onload", setUpAnchors);
}


