// 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-mall-1'] = new Array(-5,false,false,-185,0,'FATmainmenu-mall-1');
	dropdowns['FATsubmenu-mall-2'] = new Array(-5,false,false,-185,0,'FATmainmenu-mall-2');
	dropdowns['FATsubmenu-mall-3'] = new Array(-5,false,false,-185,0,'FATmainmenu-mall-3');
	dropdowns['FATsubmenu-mall-4'] = new Array(-5,false,false,-185,0,'FATmainmenu-mall-4');
	dropdowns['FATsubmenu-mall-5'] = new Array(-5,false,false,-185,0,'FATmainmenu-mall-5');
	dropdowns['FATsubmenu-mall-6'] = new Array(-5,false,false,-185,0,'FATmainmenu-mall-6');
	dropdowns['FATsubmenu-mall-7'] = new Array(-5,false,false,-185,0,'FATmainmenu-mall-7');
	dropdowns['FATsubmenu-mall-8'] = new Array(-5,false,false,-185,0,'FATmainmenu-mall-8');
	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 = 120;

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");
	}
}
