// JavaScript Document

var Over_Dropdown = new Array ();
var Over_Menu = new Array ();

var FADE_TIME = 250.0;
var TimeToFade = FADE_TIME;
var FadeTimer;
var ClearTimer;
var ClearMenuTimer;
var CurrentMenuElement = "";
var currentMenuObject = 0;
var CurrentMenuOffset = 0;
var DropDownPresent = 0;

function fade(eid, fadeOut)
{
  var Currently_Fading = 0;
  var element = document.getElementById(eid);
  if(element == null)
	return;
   
  if(element.FadeState == null)
  {
	if(element.style.opacity == null
		|| element.style.opacity == ''
		|| element.style.opacity == '1')
	{
	  element.FadeState = 2;
	}
	else
	{
	  element.FadeState = -2;
	}
  }
  if(element.FadeState == 1 || element.FadeState == -1)
  {
//	element.FadeState = element.FadeState == 1 ? -1 : 1;
	element.FadeTimeLeft = TimeToFade - element.FadeTimeLeft;
	Currently_Fading = 1;
  }
  else
  {
	element.FadeTimeLeft = TimeToFade;
  }
   
  if (fadeOut == 1) {
	element.FadeState = -1;
  } else {
	element.FadeState = 1;
  }
  
  if (!Currently_Fading) {
//		element.FadeState = element.FadeState == 2 ? -1 : 1;
	FadeTimer = setTimeout("animateFade(" + new Date().getTime() + ",'" + eid + "','" + fadeOut + "')", 33);
  }  
}

function animateFade(lastTick, eid, fadeOut)
{  
  var curTick = new Date().getTime();
  var elapsedTicks = curTick - lastTick;
 
  var element = document.getElementById(eid);
 
  if(element.FadeTimeLeft <= elapsedTicks)
  {
	element.style.opacity = element.FadeState == 1 ? '1' : '0';
	element.style.filter = 'alpha(opacity = '
		+ (element.FadeState == 1 ? '100' : '0') + ')';
	element.FadeState = element.FadeState == 1 ? 2 : -2;

	if (element.FadeState == -2) {
		if (currentMenuObject) {
			currentMenuObject.style.backgroundColor="transparent";
			currentMenuObject = 0;
		}
		element.style.display = 'none';
		DropDownPresent = 0;
	} else {
		element.style.filter = '';
	}
	return;
  }
 
  element.FadeTimeLeft -= elapsedTicks;
  var newOpVal = element.FadeTimeLeft/TimeToFade;
  if(element.FadeState == 1)
	newOpVal = 1 - newOpVal;

  element.style.opacity = newOpVal;
  element.style.filter = 'alpha(opacity = ' + (newOpVal*100) + ')';
 
  FadeTimer = setTimeout("animateFade(" + curTick + ",'" + eid + "')", 33);
}

function showDropdown (menuElement)
{
	var element = document.getElementById(CurrentMenuElement);
	clearTimeout (FadeTimer);
	clearTimeout (ClearTimer);
	if (currentMenuObject) {
		element.style.display = 'block';
		DropDownPresent = 1;
		fade (CurrentMenuElement, 0);
	}
	element.style.paddingLeft = (CurrentMenuOffset + 80) + 'px';
	element.style.width = (890 - CurrentMenuOffset + 10) + 'px';
	
}

function clearDropDownSnap ()
{
	var element = document.getElementById(CurrentMenuElement);
	clearTimeout (FadeTimer);
	clearTimeout (ClearTimer);
	if (element) {
		element.style.opacity = 0;
		element.style.filter = 'alpha(opacity = 0)';
		element.FadeTimeLeft = 0;
		element.FadeState = -2;
		element.style.display = 'none';
	}
	if (currentMenuObject) {
		currentMenuObject.style.backgroundColor="transparent";
		currentMenuObject = 0;
	}
	DropDownPresent = 0;
}

function showDropDownSnap (eid)
{
	var element = document.getElementById(eid);
	clearTimeout (FadeTimer);
	clearTimeout (ClearTimer);
	if (element) {
		element.style.display = 'block';
		element.style.opacity = 1;
//			element.style.filter = 'alpha(opacity = 100)';
		element.style.filter = '';
		element.FadeTimeLeft = 0;
		element.FadeState = 2;
	}
	DropDownPresent = 1;
	element.style.paddingLeft = (CurrentMenuOffset + 80)  + 'px';
	element.style.width = (890 - CurrentMenuOffset + 10) + 'px';
}

function clearDropDown (menuIndex)
{
	if (!Over_Dropdown[menuIndex] && !Over_Menu[menuIndex]) {
		fade (CurrentMenuElement, 1);
//		    var el = document.getElementById('Menu_Dropdown_Bg');
//			el.style.display = 'none';
	}
}

function menuOver(object, dropDown, elName, menuIndex)
{ 
	if (!Over_Menu[menuIndex]) {
		Over_Menu[menuIndex] = 1;
		CurrentMenuOffset = object.offsetLeft - 1;
		if (dropDown) {
			// Clear any current or fading dropdown present.
			if (DropDownPresent) {
				clearDropDownSnap ();
				currentMenuObject = object;
				CurrentMenuElement = 'Menu_Dropdown_Bg_' + elName;
				clearTimeout (ClearTimer);
				showDropDownSnap (CurrentMenuElement);
			} else {
				currentMenuObject = object;
				CurrentMenuElement = 'Menu_Dropdown_Bg_' + elName;
				clearTimeout (ClearTimer);
				showDropdown (CurrentMenuElement);
			}
		} else {
			clearDropDownSnap ();
		}
	}
}

function menuOut(object, dropDown, menuIndex)
{
//		object.className='Menu_Inner';
	Over_Menu[menuIndex] = 0;
	if (dropDown) {
		currentMenuObject.style.backgroundColor="#64000F";
		clearTimeout (ClearTimer);
		ClearTimer = setTimeout ("clearDropDown(" + menuIndex + ")", 100);
	}
}

function inDropDown (object, menuIndex)
{
	if (currentMenuObject) {
		currentMenuObject.style.backgroundColor="#64000F";
		Over_Dropdown[menuIndex] = 1;
		clearTimeout (ClearTimer);
	}
}

function outDropDown (object, menuIndex)
{
	Over_Dropdown[menuIndex] = 0;
	clearTimeout (ClearTimer);
	if (currentMenuObject) {
		ClearTimer = setTimeout ("clearDropDown(" + menuIndex + ")", 1500);
	}
}

