var ns4up = (document.layers) ? 1 : 0;
var ie4up = (document.all) ? 1 : 0;
var mozup = (!document.all && document.getElementById) ? 1 : 0;

var nummenus = 5;						// Number of menus
var titlearray = new Array();			// An array for the title objects
var submenuarray = new Array();			// An array for the submenu objects
if (ns4up) {							// Set visibility for NN, Moz and IE
	visible = 'show';
	hidden = 'hide';
} else if (ie4up || mozup) {
	visible = 'visible';
	hidden = 'hidden';
}

// Fills the arrays with title and submenu objects
for (var i = 0; i < nummenus; i++) {
	titlearray[i] = ('title' + i);
	submenuarray[i] = ('submenu' +i);
}

// Changes image when category is clicked
function picopen(n) {
	title = ('title' + n);
	pic = ('pic' + n);
	if (ns4up) {
		document.layers[title].document.images[pic].src = "opened.gif";
	}
	if (document.all) {
		document.all(pic).src = "opened.gif";
	}
	if (mozup) {
		document.getElementById(title).firstChild.src = "opened.gif";
	}
}

function picclose(n) {
	title = ('title' + n);
	pic = ('pic' + n);
	if (ns4up) {
		document.layers[title].document.images[pic].src = "closed.gif";
	}
	if (ie4up) {
		document.all(pic).src = "closed.gif";
	}
	if (mozup) {
		document.getElementById(title).firstChild.src = "closed.gif";
	}
}

function toggle(n,move) {
	menu = ('submenu' + n);
	if (ns4up) {
		submenu = document.layers[menu];
	}
	if (ie4up) {
		submenu = document.all(menu).style;
	}
	if (mozup) {
		submenu = document.getElementById(menu).style;
	}
	if (submenu.visibility == visible) {
		submenu.visibility = hidden;
		picclose(n);
		for (var i = (n+1); i < nummenus; i++) {
			if (ns4up) {
				document.layers[titlearray[i]].top -= move;
				document.layers[submenuarray[i]].top -= move;
			}
			if (ie4up) {
				document.all(titlearray[i]).style.pixelTop -= move;
				document.all(submenuarray[i]).style.pixelTop -= move;
			}
			if (mozup) {
				posa = parseInt(document.getElementById(titlearray[i]).style.top, 10);
				posb = parseInt(document.getElementById(submenuarray[i]).style.top, 10);
				document.getElementById(titlearray[i]).style.top   = posa-move;
				document.getElementById(submenuarray[i]).style.top = posb-move;
			}
		}
	} else {
		submenu.visibility = visible;
		picopen(n);
		for (var i = (n+1); i < nummenus; i++) {
			if (ns4up) {
				document.layers[titlearray[i]].top += move;
				document.layers[submenuarray[i]].top += move;
			}
			if (ie4up) {
				document.all(titlearray[i]).style.pixelTop += move;
				document.all(submenuarray[i]).style.pixelTop += move;
			}
			if (mozup) {
				posa = parseInt(document.getElementById(titlearray[i]).style.top, 10);
				posb = parseInt(document.getElementById(submenuarray[i]).style.top, 10);
				document.getElementById(titlearray[i]).style.top   = posa+move;
				document.getElementById(submenuarray[i]).style.top = posb+move;
			}
		}
	}
	lastmenu = submenu;
}


