// JavaScript Document
// dragons_menu.js
// by Michael Lofgren, created 15/04/2004
// Purpose: Provide the functions required for controlling the Dragons
// 	web site's navigation system.

var menuheight = 196; 	//height of menu in pixels = 160 + 36
var menuwidth = 126;		//width of menu in pixels		
var delayperpixel = 2; 	//ms per scroll pixel delayed

//var curpagemenuid = 0; //menuid for current page. defaults to home/main menu

//scrolltomenu(menuid) scrolls from the current menu to the new menu
//menuid = 0-5, 0=main menu, others are sub menus
function scrollToMenu(menuid)
{
	if (top.menuFrame) menuwindow = top.menuFrame;
	else menuwindow = window;

	var stsecs;
	
	stsecs = (new Date()).valueOf(); //starting time in secs
	//Scroll the current menu up out of view.
	for (i=1; i<=menuheight; i++) {
		while ((new Date()).valueOf() - stsecs < i*delayperpixel) {
			menuwindow.scrollBy(0, 0);
		}
	
		//Uses relative function so doesn't matter what the current
		//menu is.
		menuwindow.scrollBy(0, 1);
	}
	
	//Display correct menuTitle by scrolling to the right place
	if (top.menuTitle) {
		top.menuTitle.scroll(menuwidth*menuid, 0);
	}
	
	//Move menuFrame to the right menu column, ready to be scrolled
	//back into view. 
	menuwindow.scroll(menuwidth*menuid, menuheight);
	
	stsecs = (new Date()).valueOf(); //restart the clock
	//Scroll menu down so that new menu is in view
	for (i=1; i<=menuheight; i++) {
		while ((new Date()).valueOf() - stsecs < i*delayperpixel) {
			menuwindow.scrollBy(0, 0);
		}
		
		menuwindow.scrollBy(0, -1);
	}
} //end scrollToMenu()


//Use the value of top.navmenuid to instantaneously set the right menu for a page.
//NB: Slow scrolling is not used in this function.
function loadCurPageMenu()
{
	readPageConfig(); //read cookie

	if (top.menuFrame) menuwindow = top.menuFrame;
	else menuwindow = window;

	//alert("load(): "+top.navmenuid+" "+top.location);

	//Display correct menuTitle by scrolling to the right place
	if (top.menuTitle) {
		top.menuTitle.scroll(menuwidth*top.navmenuid, 0);
	}
	
	//Move menuFrame to the right menu column. 
	menuwindow.scroll(menuwidth*top.navmenuid, 0);
} //end loadCurPageMenu()

//configNavBarMenu() stores the menuid associated with the given menustr. 
//top.navmenuid sets the menu that will be displayed. This is also stored
//in the pageconfig cookie.
//Inputs: menustr is the title of the menu to be displayed
function configNavBarMenu(menustr)
{
	readPageConfig(); //reads cookie
	switch(menustr) {
		case "Dragons Home":				top.navmenuid = 0; break
		case "About Us": 					top.navmenuid = 1; break
		case "Competitions": 			top.navmenuid = 2; break
		case "Tournaments": 				top.navmenuid = 3; break
		case "Dragons Info": 			top.navmenuid = 4; break
		case "Volleyball Resources": 	top.navmenuid = 5; break
		case "Login": 						top.navmenuid = 6; break
		default: 							//top.navmenuid = 0; //navmenuid remains unchanged
	}
	setPageConfig(); //stores data in cookie	
	//alert("set(): "+top.navmenuid+" "+top.location);
} //end configNavBarMenu()
