/* ================================================== */
/* menu functions */
/* ================================================== */

var speed_normal = 2500;	// change this to adjust the menu timing

// shouldn't need to edit past here

var current_menu = null;
var current_menu_id = "";
var locked_menu = 0;
var checkIt;
var speed_fast = 50;

function showSubMenu( menu_id )
{
   if( current_menu != null )
   {
      hideSubMenu();
   }
   
   //lockMenu();
   
   current_menu_id = menu_id;
   current_menu = document.getElementById( menu_id );
   current_menu.style.visibility = "visible";
   checkUserInput( speed_normal );
}

function hideSubMenu()
{
   if( current_menu != null )
   {
      current_menu_id = "";  
      current_menu.style.visibility = "hidden";
      current_menu = null;
   }
}

function lockMenu()
{
   locked_menu = 1;
   checkUserInput( speed_normal );
}

function unlockMenu()
{
   locked_menu = 0;
   checkUserInput( speed_fast );
}

function checkUserInput( speed )
{
	if( checkIt )
	{
	   clearTimeout( checkIt );
	}
	
	if( locked_menu == 0 )
	{
	   checkIt = setTimeout( 'hideSubMenu()', speed );
	}
}

function activateMenu( which_object, which_menu )
{
    // 1. position the menu	
	if( browser == "IE" )
	{
		var the_object = document.getElementById( which_object );
		var width = the_object.width;
		var height = the_object.height;
		
		switch( which_object )
		{
			case "safaris":
				var x_position = document.getElementById( "page-container" ).offsetLeft + 54;
				break;
			case "programs":
				var x_position = document.getElementById( "page-container" ).offsetLeft + 110;
				break;
			case "africa":
				var x_position = document.getElementById( "page-container" ).offsetLeft + 255;
				break;
  			case "media":
				var x_position = document.getElementById( "page-container" ).offsetLeft + 470;
				break;
			case "merch":
				var x_position = document.getElementById( "page-container" ).offsetLeft + 563;
				break;
		}
		
		document.getElementById( which_menu ).style.pixelLeft = x_position;
	}
	else
	{		
		var the_object = document.getElementById( which_object );
		var width = the_object.width;
		var height = the_object.height;
		var x_position = the_object.x;
	
		// only works when the 'left' property is an inline style in the DIV
		document.getElementById( which_menu ).style.left = x_position + 'px';
	}

	// 2. show the menu
	showSubMenu( which_menu );
}


/* ================================================== */
/* browser detection */
/* ================================================== */
var platform;
var browser;

function checkBrowser()
{
	if( navigator.userAgent.indexOf( 'Mac' ) != -1 )
	{
		platform = "mac";
  	}
  	else
  	{
  		platform = "win";
  	}

  	if( navigator.appName.indexOf( 'Microsoft' ) != -1 )
  	{
  		browser = "IE";
  	}
  	else if( document.layers )
  	{
  		browser = "N4";
  	}
  	else
  	{
  		browser = "W3C";
  	}
}