var strBaseHref = 'http://' + window.location.hostname + '/';

var intMainMenuItems = 5;
var intMaxSubMenuItems = 7;
var intTimeoutSecs = 2;

var bgLight = '#FFFFDD';
var bgDark = '#7E0001';
var bgMed = '#FFFFDD';
var fontLight = 'FFFFDD';
var fontDark = '#7E0001';
var fontHi = '#FFFFDD';

var intervalID = new Array();
var timeOut;

var intMenuHeight = 50;
var intMenuPadding = 0;

var objCurMainMenu;
var intCurMainMenu;

var aryItemsLabel0 = new Array('About', 'Affiliations', 'Biography', 'Mission Statement', 'Resources', 'Contact Us');
var aryItemsURL0 = new Array('company/', 'company/affiliations.php','company/biography.php','company/mission.php','/resources/','company/contact.php');

var aryItemsLabel1 = new Array('Individual Counseling', 'Finding your Way');
var aryItemsURL1 = new Array('services/individual.php', 'services/finding.php');

var aryItemsLabel2 = new Array('');
var aryItemsURL2 = new Array('');


var aryItemsLabel3 = new Array('Food Pyramid', 'BMI', '2011 Health Trends', 'Sugar Sponges', 'Welcome to the Mesothelioma Community', 'Decoding Food Labels', 'Getting the Shakes', 'New Year, New You', 'Food Crimes', 'The Diet Maze', 'State of Nutrition', 'Blood Sugar Control');
var aryItemsURL3 = new Array('info/food-pyramid.php', 'info/bmi.php', 'info/2011-health-trends.php', 'info/sugar-sponges-red-blood-cells.php', 'info/mesothelioma-and-extraordinary-challenging-diseases.php', 'info/food-labeling.php', 'info/getting-the-shakes.php', 'info/new-years-resolution.php', '20meals.html', 'info/diet_maze.php', 'info/state_of_nutrition.php', 'info/blood_sugar.php');

var aryItemsLabel4 = new Array('');
var aryItemsURL4 = new Array('');

var zoomWin; 

function showSubMenu(intWhich) {
	stopTimer();

/*
	if ( (intWhich != 0) || (window.location.pathname == '/') || (window.location.pathname == '/index.php') ) {
		setBGColor('itemcontainer0', '');
		setBGColor('itemcontainer1', '');
		setBGColor('itemcontainer2', '');
		setBGColor('itemcontainer3', '');
		setBGColor('itemcontainer4', '');
		setBGColor('itemcontainer5', '');
	} else {
		setBGColor('itemcontainer0', 'white');
		setBGColor('itemcontainer1', 'white');
		setBGColor('itemcontainer2', 'white');
		setBGColor('itemcontainer3', 'white');
		setBGColor('itemcontainer4', 'white');
		setBGColor('itemcontainer5', 'white');
	}
	
*/
	// loop through the number of main menu items & change all others as appropriate
	for (i=0;i<intMainMenuItems;i++) {
			
		var m = getRawObject('mainNav' + i);

		if (intWhich == i) {
			// change the font color of the main menu item	
			setColor(m, fontDark);

			// change the bgcolor of the main menu item
			setBGColor(m, bgLight);

			// move the submenu to be placed under the main menu
			moveMenuItems(m, intWhich)

			// set status bar text to main menu text
			setStatusBar(m.innerHTML);
				
			// save curMainMenu data for use later
			objCurMainMenu = m;
			intCurMainMenu = intWhich;
			
		} else {
			// hide/revert other menus to original state
			setColor(m, fontLight);
			setBGColor(m, bgDark);
		}
		
	}
}

function moveMenuItems(m, intWhich) {

	var objItem;
	var objInnerItem;
	var offsetTop;
		
	var aryLabel = eval('aryItemsLabel' + intWhich);
	var aryURL = eval('aryItemsURL' + intWhich);

	if (! m) {
		offsetTop = getObjectHeight(m);
	} else {
		offsetTop = m.offsetTop + getObjectHeight(m);
	}

	
	for (j=0;j<intMaxSubMenuItems;j++) {
		objItem = 'itemcontainer' + j;
		objInnerItem = 'item' + j;
		
		shiftTo(objItem, m.offsetLeft, m.offsetTop);
		//shiftTo(objInnerItem, m.offsetLeft, m.offsetTop);
		
		if (aryLabel.length > 0) {
			if (aryLabel[j] && aryURL[j]) {
				// set the text of the menu item
				setText(objInnerItem, aryLabel[j]);

				show(objItem);
				show(objInnerItem);

				// start the glide down
				intervalID[j] = setInterval("moveItemDown('" + objItem + "', '" + objInnerItem + "', " + j + ", " + offsetTop +")", 5);
				offsetTop += getObjectHeight(objItem);
			} else {
				hide(objItem);
				hide(objInnerItem);
			}
		}
	}
}

function gotoPage(page) {
	top.location.href = strBaseHref + page;
}

function loadPage(intSubmenu) {
	var strURL = eval('aryItemsURL' + intCurMainMenu + '[' + intSubmenu + ']');
	top.location.href = strBaseHref + strURL;
}

function moveItemDown(theObject, theInnerObject, intIndex, stopPoint) {
	var obj = getRawObject(theObject);
	var objInner = getRawObject(theInnerObject);
	if (getObjectTop(obj) >= stopPoint) {
		clearInterval(intervalID[intIndex]);
	} else {
		shiftBy(obj,0, 10);
	}
}

function revertMenu(m) {
	// takes objects as arguments & reverts them to non-mouseover status
	setColor(m, fontLight);
	setBGColor(m, bgDark);
}

function closeSubMenu() {
	revertMenu(objCurMainMenu);
	
	// loop through submenu & set hidden
	for (j=0;j<intMaxSubMenuItems;j++) {
		objItem = 'itemcontainer' + j;
		objInnerItem = 'item' + j;
		hide(objItem);
		hide(objInnerItem);
	}	

	window.clearTimeout(timeOut);
	clearStatusBar();
}


function stopTimer() {
	if (timeOut) {
		window.clearTimeout(timeOut);
	}
}
function restartTimer() {
	stopTimer();
	startTimer();
}

function startTimer() {
	timeOut = window.setTimeout("closeSubMenu()",intTimeoutSecs * 1000);
}

function focusItem(obj) {
	stopTimer();

	setColor(obj, fontHi);
	setBGColor(obj, bgDark);
	setStatusBar(obj.innerHTML);
}

function blurItem(obj) {
	restartTimer();
	setColor(obj, fontDark);
	setBGColor(obj, bgLight);
	clearStatusBar();
}

function checkInit() {

	if (isCSS) {
		document.forms.theForm.isCSS.checked = true;
	}
	
	if (isW3C) {
		document.forms.theForm.isW3C.checked = true;
	}
	
	if (isIE4) {
		document.forms.theForm.isIE4.checked = true;
	}
	
	if (isNN4) {
		document.forms.theForm.isNN4.checked = true;
	}
	
	if (isIE6CSS) {
		document.forms.theForm.isIE6CSS.checked = true;
	}

}

function openVidPage() {

	var vidWin;

	var winHeight = 420;
	var winWidth  = 355;

	var winTop    = parseInt((screen.availHeight - winHeight ) / 2);
	var winLeft   = parseInt((screen.availWidth - winWidth) / 2);

	var winBars = 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=no,resizable';
	var winSize = 'width=' + winWidth + ',height=' + winHeight; 
	var winLoc  = 'screenX=' + winLeft + ',screenY=' + winTop + ',left=' + winLeft + ',top=' + winTop;

	var winOpts = winBars + ',' + winSize + ',' + winLoc;

	vidWin = window.open('/popVideo.html','vidPage',winOpts,true);
	
	vidWin.focus();
	return true;
}

function darkOnLight(obj) {
	setColor(obj, fontDark);
	setBGColor(obj, bgLight);
	// setStatusBar(obj.innerHTML);
}

function lightOnDark(obj) {
	setColor(obj, fontLight);
	setBGColor(obj, bgDark);
	// clearStatusBar();
}

function zoom(gFile, gWidth, gHeight) {
	//  take file name, width & height & build popup for zooming graphic
	
	if (!gFile || !gWidth || !gHeight) {
		// we don't have enough information - don't do anything
		return;
	}

	// build the popup box

	var allowScroll = 'no';
	
	var zoomTop = 0;
	var zoomLeft = 0;

	var zoomWidth;
	var zoomHeight;
	
	if (gWidth >= screen.availWidth - 10) {
		zoomWidth = screen.availWidth - 10;
		zoomHeight = gHeight + 20;
		allowScroll = 'yes';
		
	} else {
		zoomWidth = gWidth + 10;
		zoomHeight = gHeight + 10;
		
		zoomLeft = parseInt((screen.availWidth - zoomWidth) / 2);
	}
	zoomTop = parseInt((screen.availHeight - zoomHeight) / 2);


	var zoomBars = 'directories=no,location=no,menubar=no,status=no,' +
		'titlebar,toolbar=no,scrollbars=' + allowScroll + ',resizable=no';
		
	var zoomSize = 'width=' + zoomWidth + ',height=' + zoomHeight; 
	var zoomLoc = 'screenX=' + zoomLeft + ',screenY=' + zoomTop + ',left=' + 
		zoomLeft + ',top=' + zoomTop;

	var zoomOpts = zoomBars + ',' + zoomSize + ',' + zoomLoc;
	
	zoomWin = window.open('','zoomWin',zoomOpts,true);
	zoomWin.document.write('<html><head><title>Zoom</title></head>');
	zoomWin.document.write('<body topmargin=0 rightmargin=0 bottommargin=0 leftmargin=0>');
	zoomWin.document.write('<img src="' + gFile);
	zoomWin.document.write('" width="' + gWidth + '"');
	
	zoomWin.document.write('>');
	zoomWin.document.write('</body></html>');
	zoomWin.document.close();
	zoomWin.focus();
}

