var COLLAPSABLE_PARENT_NAME = "collapsable";
var COLLAPSABLE_PARENT_TYPE = "li";
var COLLAPSABLE_CHILD_TYPE = "ul";

var COLLAPSABLE_EXPAND = " [+]";
var COLLAPSABLE_SHRINK = " [-]";

init = function() {
	if(document.getElementById && document.createTextNode) {
		var entries = document.getElementsByTagName(COLLAPSABLE_PARENT_TYPE);
		for(i=0;i<entries.length;i++)
			if (entries[i].className==COLLAPSABLE_PARENT_NAME)
				assignCollapse(entries[i]);
	}
}

assignCollapse = function (div) {
	div.firstChild.setAttribute('expand', COLLAPSABLE_EXPAND);
	div.firstChild.setAttribute('shrink', COLLAPSABLE_SHRINK);
	div.firstChild.setAttribute('state', -1);
	div.firstChild.innerHTML = div.firstChild.innerHTML + COLLAPSABLE_EXPAND;

	div.firstChild.onclick=function(){ 
		var state = -(1*this.getAttribute('state'));
		this.setAttribute('state', state);
		this.parentNode.getElementsByTagName(COLLAPSABLE_CHILD_TYPE)[0].style.display=state==1?'none':'block';
		this.innerHTML = this.innerHTML.substring(0,this.innerHTML.length - this.getAttribute(state==1?'shrink':'expand').length) + this.getAttribute(state==1?'expand':'shrink');
		return false;
	};					
	div.firstChild.onclick();
}

/* for Mozilla/Opera9 */
if (document.addEventListener) {
    document.addEventListener("DOMContentLoaded", init, false);
}

/* for Internet Explorer */
/*@cc_on @*/
/*@if (@_win32)
    document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>");
    var script = document.getElementById("__ie_onload");
    script.onreadystatechange = function() {
        if (this.readyState == "complete") {
            init(); // call the onload handler
        }
    };
/*@end @*/

/* for Safari */
if (/WebKit/i.test(navigator.userAgent)) { // sniff
    var _timer = setInterval(function() {
        if (/loaded|complete/.test(document.readyState)) {
            init(); // call the onload handler
        }
    }, 10);
}

/* for other browsers */
//window.onload = init;
