// the section label that should remain highlighted - set in page specific js block
var currentSectionLabel;

function showDropDown(dropdown){
	// highlight the label
	//document.getElementById(dropdowns[dropdown][5]).style.backgroundColor = '#FFFF00';
	//document.getElementById(dropdowns[dropdown][5]).style.color = '#FFFFFF';
	// set flags in the dropdowns array indicating to the animation function that the menu should be sliding in
	dropdowns[dropdown][1] = true;
	dropdowns[dropdown][2] = false;
	// if no menus are being animated in, start them up
	if( inStopped == true ){
		intervalIdIn = window.setInterval('animateIn()',10);
		inStopped = false;
	}
}

function hideDropDown(dropdown){
	// set flags in the dropdowns array indicating to the animation function that the menu should be sliding out
	dropdowns[dropdown][1] = false;
	dropdowns[dropdown][2] = true;
	// reset the delay counter
	dropdowns[dropdown][4] = delay;
	// if no menus are being animated out, start them up
	if( outStopped == true ){
		intervalIdOut = window.setInterval('animateOut()',10);
		outStopped = false;
	}
}

// array storing info about each dropdown
// this is: [ top (y position), animating in flag, animating out flag, offscreen position, delay counter, associated topnav ]
	var dropdowns = new Array();
	dropdowns['FATsubmenu-cn'] = new Array(-5,false,false,-85,0,'FATmainmenu-cn');
	dropdowns['FATsubmenu-sa'] = new Array(-5,false,false,-105,0,'FATmainmenu-sa');
	dropdowns['FATsubmenu-sacat'] = new Array(-5,false,false,-85,0,'FATmainmenu-sacat');
	dropdowns['FATsubmenu-im'] = new Array(-5,false,false,-85,0,'FATmainmenu-im');
	dropdowns['FATsubmenu-ic'] = new Array(-5,false,false,-85,0,'FATmainmenu-ic');
	var intervalIdIn;
	var intervalIdOut;
	var inStopped = true;
	var outStopped = true;
// iterations before the scroll out starts
	var delay = 10;
// onscreen pos in pixels
	var limit = 385;

function animateIn(){
	var doStop=true;
	for (drop in dropdowns){
		if( dropdowns[drop][1]==true){
			doStop = false;
			if(dropdowns[drop][0] < limit){
				dropdowns[drop][0]+=10;
				document.getElementById(drop).style.top=dropdowns[drop][0]+'px';
				document.getElementById(drop).style.visibility="visible";
			}
		}
	}
	if ( doStop == true ){
		window.clearInterval(intervalIdIn);inStopped = true;
		//alert("In interval cleared");
	}
}

function animateOut(){
	var doStop = true;
	for (drop in dropdowns){
		if( dropdowns[drop][2] == true ){
			doStop = false;
			// if the counter < 0 and top > lower limit, move the layer
			if( dropdowns[drop][0] > dropdowns[drop][3] && dropdowns[drop][4] < 0 ){
				dropdowns[drop][0] -= 10;
				document.getElementById(drop).style.top = dropdowns[drop][0] + 'px';
			}
			// decrement the counter if necessary
			if( dropdowns[drop][4] >= 0 ){
				dropdowns[drop][4]--;
			}
			// if we're about to do a scrollout, unhighlight the menu label
			if( dropdowns[drop][4] == 0 ){
				if( dropdowns[drop][5] != currentSectionLabel ){
					document.getElementById(dropdowns[drop][5]).style.backgroundColor = '';
					//document.getElementById(dropdowns[drop][5]).style.color = '#ffffff';
				}
			}
			// clean up if menu has reached its offscreen position
			if( dropdowns[drop][0] <= dropdowns[drop][3] ){
				document.getElementById(drop).style.visibility = "hidden";
				dropdowns[drop][2] = false;
			}
		}
	}
	if ( doStop == true ){
		window.clearInterval(intervalIdOut);
		outStopped = true;
		//alert("Out interval cleared");
	}
}
