
function flipSubMenu(cellid, tableid) {
	var table = document.getElementById(tableid);
	if (table.style.visibility == 'visible') {
		hideSubMenu(tableid);
	}
	else {
		showSubMenu(cellid, tableid);
	}
}

function showSubMenu(cellid, tableid) {
	hideAllSubMenus();
    var cell = document.getElementById(cellid);
    var coors = findPos(cell);
    var table = document.getElementById(tableid);
    table.style.visibility = 'visible';
    table.style.top = (coors[1]) + 'px';
    table.style.left = (coors[0] + 175) + 'px';
}

function hideSubMenu(tableid) {
    var table = document.getElementById(tableid);
    if (table != null) {
	    table.style.visibility = 'hidden';
    }
}

function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft,curtop];
}

function highlightCell(tag) {
	var cell = document.getElementById(tag + 'linkcell');
	cell.style.backgroundColor = "#E7E7E7";
	highlightArrow(tag + 'Arrow');
}

function dehighlightCell(tag) {
	var cell = document.getElementById(tag + 'linkcell');
	cell.style.backgroundColor = "transparent";
	dehighlightArrow(tag + 'Arrow');
}

function highlightArrow(arrowId) {
	var arrow = document.getElementById(arrowId);
	arrow.style.backgroundColor = "#E7E7E7";
}

function dehighlightArrow(arrowId) {
	var arrow = document.getElementById(arrowId);
	arrow.style.backgroundColor = "transparent";
}

function hideAllSubMenus() {
	hideSubMenu('teammenu');
	hideSubMenu('playermenu');
	hideSubMenu('teamrankmenu');
	hideSubMenu('playerrankmenu');
	hideSubMenu('draftmenu');
	hideSubMenu('risingstarmenu');
	hideSubMenu('matchmenu');
	hideSubMenu('brownlowmenu');
	hideSubMenu('laddermenu');
	hideSubMenu('attendancemenu');
	hideSubMenu('supercoachmenu');
	hideSubMenu('dreamteammenu');
	hideSubMenu('coachmenu');
}
