// topmenu array options - needs to match $topmenu is index.php (excluding the elements without sub menus
var topmenu = new Array('about', 'WCHN partners', 'publications', 'committees');

// hides all top menus
function hideTopMenus() {
	for (i=0; i<topmenu.length; i++) {
		document.getElementById('subtop_'+topmenu[i]).style.visibility = 'hidden'; 
	}
}


function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


function buttonAct (ider, acter, menu) {
	if (menu == 'top') { topButtonAct (ider, acter); }
	else { sideButtonAct (ider, acter); }
}

function topButtonAct (ider, acter) {

	topider = ider.split('_');
	obj = document.getElementById(ider);
	styleObj = document.getElementById(ider).style;
	if (acter == 'over') { 
		styleObj.textDecoration = 'underline'; 
		styleObj.cursor = 'hand'; 
		styleObj.cursor = 'pointer';
		if (obj.className != "subSideElement") { hideTopMenus(); }
		cox = findPosX(obj);
		coy = findPosY(obj);
		showSub(cox,coy,ider);
	}
	else if (acter == 'out') { 
		styleObj.textDecoration = 'none';
	}
	else if (acter == 'open') {
		hideTopMenus();
		cox = findPosX(obj);
		coy = findPosY(obj);
		showSub(cox,coy,ider);
	}
	else if (acter =='nothing') { 
		hideTopMenus();
		get_id = ider.split('_');
		area = get_id[1].replace(/ /g, "_");
		location.href = '/' + area + '/index.htm';
	}
	else {
		alert(ider);
	}
	
}

function showSub(cox,coy,ider) {
	get_id = ider.split('_');
	subid = 'sub' + get_id[0] + '_' + get_id[1];
	subObj = document.getElementById(subid);
	if (subObj) {
		subObj.style.left = cox+'px';
		subObj.style.top = coy+23+'px';
		subObj.style.visibility = 'visible';
	}
}


function sideButtonAct (ider, acter) {	
	
	get_id = ider.split('_');
	if ((acter == "over") || (acter == "out")) {
		if (acter == "over") { 
			newb = "/_img/cube_highlight.gif"; 
			colcol = "#666";
			textdec = "underline";
		}
		
		if (acter == "out") { 
			if (get_id[2] % 3 == 1) { newb = "/_img/cube_blue.gif"; }
			if (get_id[2] % 3 == 2) { newb = "/_img/cube_orange.gif"; }
			if (get_id[2] % 3 == 0) { newb = "/_img/cube_red.gif"; }
			colcol = "#000";
			textdec = "none";
		}
		
		if (get_id[0] != "subs") { 
			var cuber = ider+'_cube';
			document.getElementById(cuber).src = newb; 
		}
		document.getElementById(ider).style.textDecoration = textdec;
		document.getElementById(ider).style.color = colcol;
	}
	else {
	
		hideTopMenus();
		
		if (acter == "open") { 	
			// need to somehow turn them all off ... 
			all_subs = new Array('overview');
					
			ch = document.getElementById("subs_"+get_id[1]).style.display;
			if (ch == "none") { dh = "block"; }
			else { dh = "none"; }
			document.getElementById("subs_"+get_id[1]).style.display = dh;
		}
		else { 
			if (get_id.length == 2) { get_id[2] = "index"; }
			area = get_id[1].replace(/ /g, "_");
			if (get_id[0] != "subs") { file = "index"; }
			else { file = get_id[2].replace(/ /g, "_"); }
			file = file.toLowerCase();
			window.location.href = "/" + area + "/" + file + ".htm";
		}
	}
}
	