/////////////////
// MENU SCRIPT //
/////////////////

var timesover=0;
var timerID = null;
//var boolFirstMenuFlag = true;
var boolTimerOn = false;
var intTimecount = 450;
var intRunCount = 0;
var intTabActive = 999;
var intNumTabs = 7; // number of tabs
var asTabs = new Array();
	asTabs[0] = "home";
	asTabs[1] = "aboutus";
	asTabs[2] = "ministries";
	asTabs[3] = "spevents";
	asTabs[4] = "location";
	asTabs[5] = "youth";
	asTabs[6] = "contact";
	


function doInitializeMenu() {
	//window.console.log('doInitializeMenu');
	for (i=0; i<intNumTabs; i++)
	{
		//window.console.log('loop = ' + i);
		if(document.getElementById("menuitem-" + asTabs[i]).className=="mainmenuitem active")
		{	
			//window.console.log('intTabActive = ' + i);
			intTabActive = i;
		}
		else
		{	
			//window.console.log('asTabs [ '+ i +' ] is not active' );
		}
	}
}

function settimeover(){
timesover=1;
}

function doMenuOn(id) {
	//window.console.log('doMenuOn( ' + id +' )');
	
	/* initialize the menu to figure out which tab is set to active */
	if (intRunCount < 1)
	{
		//window.console.log('initialize the menu to figure out which tab is set to active');
		doInitializeMenu();
		intRunCount++;
	}

	
	//if (boolFirstMenuFlag == true)
	//{

	/*hide any menus that might be open*/
	if (document.getElementById("menuitem-" + id).className == "mainmenuitem active" && timesover==0)
	{
		//window.console.log('hide any menus that might be open');
		timesover=1;
	}
	else
	{
		//window.console.log('display the menu itself');
		timesover=1;
		doHideAll();
		/* if statement to check if the submenu acutally exists, because the home menu doesn't have one */
		if(document.getElementById("submenu-" + id))
		{	
			//window.console.log('display the submenu itself');
			document.getElementById("submenu-" + id).style.display = "block"; /*turn on the submenu*/
		}
		
		/*change the style of the tab to the hover style*/	
		//window.console.log('change the style of the tab to the hover style');
		
		document.getElementById("menuitem-" + id).className = "mainmenuitem hover"; 
	
		/* stop the timer */
		doStopTime(); 
	}
	//}
}
function doMenuOff(id) {
	//window.console.log('doMenuOff');
	for (i=0; i<intNumTabs; i++)
	{
			if(document.getElementById("menuitem-" + asTabs[i]).className=="mainmenuitem active")
			{
				//window.console.log('the item [' + i +' ] is not active');
				timesover=1;
			}
	}


	/*start the timer */
	doStartTime(); 
}
function doSubMenuOn(){
	/* stop the timer */
	doStopTime(); 
}
function doSubMenuOff(){
	 /* start the timer */
	 doStartTime();
}

function doHideAll(){
	
	//window.console.log('doHideAll');
	
	for (i=0; i<intNumTabs; i++)
	{
		/* if statement to check if the submenu exists before we try to hide it */
		if(document.getElementById("submenu-" + asTabs[i]))
		{	
			//window.console.log('Hide submenu' + i);
			document.getElementById("submenu-" + asTabs[i]).style.display = "none"; /* hide the submenu */
		}		
		/*set all tabs to the inactive style */
		
		//window.console.log('set all tabs to the inactive style');
		document.getElementById("menuitem-" + asTabs[i]).className="mainmenuitem inactive";
	}
	/*set the active tab to the active style*/
	if (intTabActive < 99)
	{
		//window.console.log('set all tabs to the inactive style - ver 2');
		document.getElementById("menuitem-" + asTabs[intTabActive]).className="mainmenuitem active";
	}
}
function doStopTime(){
	if (boolTimerOn){
		clearTimeout(timerID);
        timerID = null;
        boolTimerOn = false;
	}

}
function doStartTime(){
	if (boolTimerOn == false) {
		timerID=setTimeout( "doHideAll()" , intTimecount);
		boolTimerOn = true;
	}
}

///////////////////////
// NEW WINDOW SCRIPT //
///////////////////////

function newWindow(url, label,width,height,scroll){
	window.open(url,label,"width="+width+",height="+height+",toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,margin=0");
}