var matrixAll = function(display) {
	var matrix = document.getElementById("matrixContainer").childNodes[0];
	var head = matrix.childNodes[1].childNodes[0];
	while(head.nextSibling) {
		var head = head.nextSibling;
		if(head.className==="newhead") {
			if(display && head.childNodes[0].className!=="opened" || !display && head.childNodes[0].className==="opened") {
				matrixHeadClick(head.childNodes[0],false);
			}
		}
	}
};

var matrixHeadClick = function(obj,e) {
	var head = obj.parentNode;
	var hide = head.nextSibling.style.display=="none" ? false : true;
	obj.style.backgroundImage = "url(/inc/img/"+(hide ? "closed" : "opened")+".gif)";
	head.childNodes[0].className = hide ? "closed" : "opened";
	head.childNodes[1].childNodes[0].style.visibility = hide ? "visible" : "hidden";
	head.childNodes[2].childNodes[0].style.visibility = hide ? "visible" : "hidden";
	while(head.nextSibling && head.nextSibling.className!="newhead") {
		var head = head.nextSibling;
		head.style.display = hide ? "none" : "table-row";
	}
};

window.onload = function() {
	var matrix = document.getElementById("matrixContainer").childNodes[0];
	var firstHead = matrix.childNodes[1].childNodes[0].nextSibling;
	with(firstHead.childNodes[0].style) {
		background = "url(/inc/img/opened.gif) 0 10px no-repeat";
		paddingLeft = "22px";
		cursor = "pointer";
	}
	firstHead.childNodes[0].className = "opened";
	firstHead.childNodes[1].childNodes[0].style.visibility = "hidden";
	firstHead.childNodes[2].childNodes[0].style.visibility = "hidden";
	firstHead.childNodes[0].onmousedown = function(e) {
		if(!e) var e = event ? event : window.event;
		if(e.preventDefault) e.preventDefault();
		matrixHeadClick(this,e);
		return false;
	};
	var head = firstHead.nextSibling;
	if(head.childNodes.length) head.childNodes[0].style.paddingLeft = "30px";
	var hide = false;
	while(head.nextSibling) {
		var head = head.nextSibling;
		if(head.className==="newhead") {
			hide = true;
			with(head.childNodes[0].style) {
				background = "url(/inc/img/closed.gif) 0 10px no-repeat";
				paddingLeft = "22px";
				cursor = "pointer";
			}
			head.childNodes[0].onmousedown = function(e) {
				if(!e) var e = event ? event : window.event;
				if(e.preventDefault) e.preventDefault();
				matrixHeadClick(this,e);
				return false;
			}
		}else if(hide) {
			head.style.display = "none";
		}
		if(head.className!="newhead") {
			if(head.childNodes.length) head.childNodes[0].style.paddingLeft = "30px";
		}
	}
};
