/* Simple DOM-based collapsable list system.
 * (C) Josh Gough, 2001
 * http://www.ultravioletconsulting.com
 */

function openContent(objContent, objIndicator) {
	objIndicator.className = "indicatorOpen";
	objContent.className = "contentOpen";
	// modify the inner html for the indicator
	//objIndicator.innerHTML = "[-]";
}

function closeContent(objContent, objIndicator) {
	objIndicator.className = "indicatorClosed";
	objContent.className = "contentClosed";
	// modify the inner html for the indicator
	//objIndicator.innerHTML = "[+]";
}


function toggleContent(position) {	
	var  objIndicator = getIndicatorDiv(position);
	var currClass = objIndicator.className;
	
	if (currClass == "indicatorClosed") {
		openContent(document.getElementById("content" + position), objIndicator);
	} else {
		closeContent(document.getElementById("content" + position), objIndicator);
	}
}

function openAllContent(parentId) {
	var container = document.getElementById(parentId);
	var divs = getOnlyElements(container.childNodes);
	for (var i = 0; i < divs.length; i++) {
		var div = divs[i];
		if (div.getAttribute("id").indexOf("panel") == 0) {
			openContent(getContentDiv(i+1),getIndicatorDiv(i+1));

		}
	}
}

function closeAllContent(parentId) {
	var container = document.getElementById(parentId);
	var divs = getOnlyElements(container.childNodes);
	for (var i = 0; i < divs.length; i++) {
		var div = divs[i];
		if (div.getAttribute("id").indexOf("panel") == 0) {
			closeContent(getContentDiv(i+1), getIndicatorDiv(i+1));
		}
	}
}

function getContentDiv(num) {
	return document.getElementById("content" + num);
}

function getIndicatorDiv(num) {
	return document.getElementById("indicator" + num);
}

function getOnlyElements(aryElems) {
	var ary = [];
	var j = 0;
	for (var i = 0; i < aryElems.length; i++)
	{
		if (aryElems[i].nodeType == 1) { // hard coded ELEMENT_TYPE
			ary[j++] = aryElems[i];			
		}
	}
	return ary;
}

/* Sample code:

<div id="listContainer">
<div id="header1"><span class="indicatorClosed" id="indicator1" onclick="toggleContent(1, this)">[+]</span><span>DOM</span></div>
<div id="content1" class="contentClosed">
	is good, but Opera is bad.
</div>

</div>
*/