/**************************************************************
SCRIPT INFO
Title: Simple Dropdown Menu Script
Version: 1.0
Author: Ben Alexander
Last Modified: 08/09/2003
****************************************************************
VERSION HISTORY
1.0 Simple procedural version using 2 setInterval processes
****************************************************************
OVERVIEW
The script defines two event handlers (showDropDown and
hideDropDown) which set flags to indicate that a menu should
be scrolled in or out. These are picked up by two
periodically called functions which adjust the positions of
the menus to create the animation effect. These two funtions
themselves are controlled by two boolean flags which indicate
whether the processes should be started again. The scroll out is
delayed, in order to smooth out flickers, by means of a counter
which the animateOut function decrements to 0 before starting to
adjust the layer position.
****************************************************************
TO DO
The script should be rewritten using an object oriented style
***************************************************************/

// 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 = '';
	//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-about'] = new Array(-5,false,false,-85,0,'FATmainmenu-about');
dropdowns['FATsubmenu-events'] = new Array(-5,false,false,-85,0,'FATmainmenu-events');
dropdowns['FATsubmenu-money'] = new Array(-5,false,false,-105,0,'FATmainmenu-money');
dropdowns['FATsubmenu-schools'] = new Array(-5,false,false,-85,0,'FATmainmenu-schools');
dropdowns['FATsubmenu-buy'] = new Array(-5,false,false,-85,0,'FATmainmenu-buy');

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 = 20;

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");
	}
}
