// Sweet Javascript Menu
// by Jordan Cote
var x // x and y used in for loops below
var y
var t = 0	// timer
var activeCol = 0 // sets the active column (menu)
var cols
var rows


// menu layout
function setMenus(menus) { // set the number of main menu items here
	cols=menus
	rows=new Array(cols)
}

function setItems(menu,items) { // set the number of items in said menu
	rows[menu] = items
}

function clear() { // totally clear menus
		for (y=0;y<cols;y++) { // hide everything else
				for (x=1;x<rows[y];x++) {
					hide(String(y)+String(x))
				}
		}
		for (x=0;x<cols;x++) { // dim all other top cells
				lowlight(String(x)+String(0))
		}
}
function menuClr(col) {
	t=setTimeout("clear()",250) // set the timeout here
	activeCol = col
}

function loadClr() {
	t=setTimeout("clear()",0)
}

function menuGo(col,row) {		
	if (row == 0) { // one of the top cells, the ones that drop menus
		if (t!=0) {
			clearTimeout(t) // dont let the universal clear take place, this'll be taken care of
			t=0
		}
		
		highlight(String(col)+String(row)) // semi-permanantly highlight active cell
		
		for (x=0;x<cols;x++) { // dim all other top cells
			if (x != col) {
				lowlight(String(x)+String(0))
			}
		}

		for (x=1;x<rows[col];x++) {	// drop the menu
			show(String(col)+String(x))
		}
	
		for (y=0;y<cols;y++) { // hide everything else
			if (y != col) {
				for (x=1;x<rows[y];x++) {
					hide(String(y)+String(x))
				}
			}
		}
	} else if (col == activeCol) { // inside a menu, dont deconstruct it when switching cells in same column
		if (t!=0) {
			clearTimeout(t)
			t=0
		}
	}	
}

function highlight(id) {
		document.getElementById(id).style.background="#0055FF"
}
function lowlight(id) {
		document.getElementById(id).style.background="#0000FF"
}

function hide(id) {
	document.getElementById(id).style.visibility="hidden"
}
function show(id) {
	document.getElementById(id).style.visibility="visible"
}


// heres the menu layout, in numbers
// you have to set this!!
// ...and keep it updated
setMenus(5)
setItems(0,4)
setItems(1,3)
setItems(2,3)
setItems(3,2)
setItems(4,2)
loadClr()

