// display menu tracker
var dispMenu = 0;

// CSS menu index
css_index = 1;

//Number of Menu Items
// for this version of the code to work numTopMenu must = numSubMenu
var numTopMenu = 6;
var numSubMenu = 6;
var numSubMenuItemsPerGrp = 5;

// item indexes in css file
var topMenuOffset = 0;
var subMenuOffset = (numTopMenu * 2) + topMenuOffset;
var subMenuItemOffset = subMenuOffset + (numSubMenu * 2);

// var for show/hide by id
var ns4 = (document.layers);
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);
var ns6 = (!document.all && document.getElementById);



//store array of images to be preloaded
var myImages = new Array('../../../graphics/accsa07/topMenuBullet.jpg',  '../graphics/topMenu1b.jpg', '../graphics/topMenu2b.jpg', '../graphics/topMenu3b.jpg', '../graphics/topMenu4b.jpg', '../graphics/topMenu5b.jpg', '../graphics/topMenu6b.jpg', '../graphics/topMenu1a.jpg', '../graphics/topMenu2a.jpg', '../graphics/topMenu3a.jpg', '../graphics/topMenu4a.jpg', '../graphics/topMenu5a.jpg', '../graphics/topMenu6a.jpg');


	var theRules = new Array();
	if (document.styleSheets[css_index].cssRules){
		theRules = document.styleSheets[css_index].cssRules;}
	else if (document.styleSheets[css_index].rules){
		theRules = document.styleSheets[css_index].rules;
	}




preloadMenuImages();

//--------------------------------------------------------
//MAIN FUNCTION: Preload Menu Images
function preloadMenuImages() {
     if (document.layout_graphics.icons) {
          for (var i = 0; i < myImages.length; i++) {
               (new Image()).src = myImages[i];
          }
     }
}


//--------------------------------
// SUBFUNCTION: Show Division

function ShowDiv (id){
	// Netscape 4
	if(ns4){
		document.layers[id].visibility = "show";
	}
	// Explorer 4
	else if(ie4){
		document.all[id].style.visibility = "visible";
	}
	// W3C - Explorer 5+ and Netscape 6+
	else if(ie5 || ns6){
		document.getElementById(id).style.visibility = "visible";
	}
}

//--------------------------------
// SUBFUNCTION: Hide Division
function HideDiv(id){
	// Netscape 4
	if(ns4){
		document.layers[id].visibility = "hide";
	}
	// Explorer 4
	else if(ie4){
		document.all[id].style.visibility = "hidden";
	}
	// W3C - Explorer 5+ and Netscape 6+
	else if(ie5 || ns6){
		document.getElementById(id).style.visibility = "hidden";
	}
}


//--------------------------------------------------------
function TopMenu(action, topMenuNum){

	if (action == 'show'){	
		HideAllMenus(); // hide all submenus
		HighlightTopMenu(-1,'default'); // change all top level backgrounds to default
		HighlightTopMenu(topMenuNum, 'hover'); // change background for top level highlight
	
	
	if (dispMenu ==0) { // If the submenu hasn't been displayed
			
				// -------- Remove Registration and Call for papers submenu -------
				if (topMenuNum == 2 || topMenuNum == 4) {
					return;
				}	
				// -------------------
			ShowHideSubMenu(topMenuNum, 'show'); //show subMenu
		}
		dispMenu = 1; // change menu tracker
	}


	if (action == 'hide') {
		dispMenu = 0;
		setTimeout("KillMenu(" + topMenuNum + ",'hide');",800,"JavaScript"); // Kill Menu
	}
}

//--------------------------------------------------------
function SubMenu(action, topMenuNum, subMenuItem) {
	if (action == 'show'){
		dispMenu = 1;
		HighlightSubMenu (topMenuNum, subMenuItem, 'hover');		
	}
	if (action == 'hide'){
		dispMenu = 0;
		HighlightSubMenu (topMenuNum, subMenuItem, 'default');
		setTimeout("KillMenu(" + topMenuNum + ",'hide');",800,"JavaScript"); // Kill Menu
	}
}




//--------------------------------------------------------

function KillMenu(topMenuNum) {
	if (dispMenu == 0) {
		ShowHideSubMenu(topMenuNum, 'hide');
		HighlightTopMenu(topMenuNum, 'default');
	}
}

function HideAllMenus() {
	for (i=1; i < numSubMenu+1; i++) {
		ShowHideSubMenu(i, 'hide');
	}
}

//--------------------------------------------------------
function ShowHideSubMenu(menuNum, action) {
	// note: menuNum is the _submenu_ number
	// computer subMenu index
	index = subMenuOffset + (menuNum * 2) - 1;
	
//	var theRules = new Array();
//	if (document.styleSheets[css_index].cssRules)
//		theRules = document.styleSheets[css_index].cssRules;
//	else if (document.styleSheets[css_index].rules)
//		theRules = document.styleSheets[css_index].rules;
//	else return
	
	if (action == 'show') {
		theRules[index].style.visibility = 'visible';
	}
	else if (action == 'hide') {
		theRules[index].style.visibility = 'hidden';
	}
}

//--------------------------------------------------------
function HighlightTopMenu(menuNum, action) {	
	// change all top level menus to default background
	if (menuNum == -1) { 
		for (i=1; i<=numTopMenu; i++) {
			HighlightTopMenu (i, 'default');
		}
		return;
	}

	// change single item to default background
	if (action == 'hover') {
		aImg = '../../../graphics/accsa07/topMenuBullet.jpg';
		bImg = '../graphics/topMenu'+ menuNum + 'b.jpg';
	}
	if (action == 'default') {
		aImg = '';
		bImg = '../graphics/topMenu'+ menuNum + 'a.jpg';
	}
	
	urlA = "url('" + aImg + "')";
	urlB = "url('" + bImg + "')";

	// note: menuNum is the _TOP menu_ number
	// computer subMenu index
	index_a = topMenuOffset + (menuNum-1 * 2) + menuNum;
	index_b = topMenuOffset + (menuNum-1 * 2) + menuNum +1;
	
//	var theRules = new Array();
//	if (document.styleSheets[css_index].cssRules)
//		theRules = document.styleSheets[css_index].cssRules
//	else if (document.styleSheets[css_index].rules)
//		theRules = document.styleSheets[css_index].rules
//	else return
	
	theRules[index_a].style.backgroundImage = urlA;
	theRules[index_b].style.backgroundImage = urlB;
}

//--------------------------------------------------------
function HighlightSubMenu(topMenuNum, subMenuItem, action) {
	var default_color = '#D0D0D0';
	var hover_color = '#8F857F';
	var change_color;
	
	if (action == 'hover') {
		change_color = hover_color;
	}
	if (action == 'default') {
		change_color = default_color;
	}

	// note: menuNum is the _SUB menu_ number
	// ONLY WORKS IF TopMenuNum = SubMenuNum
	// computer subMenu index
	index = subMenuItemOffset + ((topMenuNum-1) * numSubMenuItemsPerGrp) + subMenuItem-1;
//	index=29;
	
//	var theRules = new Array();
//	if (document.styleSheets[css_index].cssRules)
//		theRules = document.styleSheets[css_index].cssRules
//	else if (document.styleSheets[css_index].rules)
//		theRules = document.styleSheets[css_index].rules
//	else return
	
	theRules[index].style.backgroundColor = change_color;
}

