var gActiveChapter = 0;

function getEl(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	} else if (document.all) {
		return document.all[id];
	} else {
		return null;
	}
}

function getTags(name) {
	if (document.getElementsByTagName) {
		return document.getElementsByTagName(name);
	} else if (document.all.tags) {
		return document.all.tags(name);
	} else {
		return null;
	}
}


function overChapter(id) {
	var img = getEl("button"+id);
	if(img){
		old = img.src;
		if("_x" != old.substr(old.length - 6, 2))
			img.src = old.substr(0, old.length - 4) + "_x" + old.substr(old.length - 4, 4);
	}	
}

function outChapter(id) {
	if(id == gActiveChapter) return;
	
	var img = getEl("button"+id);
	if(img){
		old = img.src;
		if("_x" == old.substr(old.length - 6, 2))
			img.src = old.substr(0, old.length - 6) + old.substr(old.length - 4, 4);
	}	
}

function clickChapter(id) {
	lastActiveChapter = gActiveChapter;
	gActiveChapter = id;

	overChapter(gActiveChapter);		
	outChapter(lastActiveChapter);

	var out,img,id;
	for (var i = 0; i < nodeNum; i++) {
		id = nodeTable[i];
		out = getEl("table"+id);
		img = getEl("button"+id);
		if (out && img) {
			if(id == gActiveChapter)
				out.style.display = "block";
			else	
				out.style.display = "none";
		}
	}
}

function overSubButton(id) {
	var img = getEl("subbutton"+id);
	if(img){
		old = img.src;
		if("_x" != old.substr(old.length - 6, 2))
			img.src = old.substr(0, old.length - 4) + "_x" + old.substr(old.length - 4, 4);
	}	
}

function outSubButton(id) {
	if(id == gActiveChapter) return;
	
	var img = getEl("subbutton"+id);
	if(img){
		old = img.src;
		if("_x" == old.substr(old.length - 6, 2))
			img.src = old.substr(0, old.length - 6) + old.substr(old.length - 4, 4);
	}	
}


var nodeTable = new Array();
var nodeNum = 0;
function menuLoad() 
{
	var e,id,out,img;
	var nodes = getTags("h4");
	//var nodes = document.getElementsByTagName("h4");
	if (nodes) {
		//alert(nodes);
		for (var ii = 0; ii < nodes.length; ii++) {
			e = nodes[ii];
			id = String(e.id);
			var img = getEl("button"+id);
			var table = getEl("table"+id);
			if (img && table) {
				table.style.display = "none";
				nodeTable[nodeNum] = id;
				nodeNum++;
				//alert("hide");
			}
		}
	}
}


window.onload=menuLoad;


