
// Preload the primary navigation.
var imgHouseflies_off = new Image();
	imgHouseflies_off.src = (ENV.Web.Root + "images/global/primary_navigation/houseflies.gif");
var imgHouseflies_on = new Image();
	imgHouseflies_on.src = (ENV.Web.Root + "images/global/primary_navigation/houseflies_f2.gif");
	
var imgFoodchain_off = new Image();
	imgFoodchain_off.src = (ENV.Web.Root + "images/global/primary_navigation/foodchain.gif");
var imgFoodchain_on = new Image();
	imgFoodchain_on.src = (ENV.Web.Root + "images/global/primary_navigation/foodchain_f2.gif");

var imgAmerican_off = new Image();
	imgAmerican_off.src = (ENV.Web.Root + "images/global/primary_navigation/american.gif");
var imgAmerican_on = new Image();
	imgAmerican_on.src = (ENV.Web.Root + "images/global/primary_navigation/american_f2.gif");
	
var imgCockroach_off = new Image();
	imgCockroach_off.src = (ENV.Web.Root + "images/global/primary_navigation/cockroach.gif");
var imgCockroach_on = new Image();
	imgCockroach_on.src = (ENV.Web.Root + "images/global/primary_navigation/cockroach_f2.gif");
	
var imgGeneticallyEngineeredMice_off = new Image();
	imgGeneticallyEngineeredMice_off.src = (ENV.Web.Root + "images/global/primary_navigation/genetically_engineered_mice.gif");
var imgGeneticallyEngineeredMice_on = new Image();
	imgGeneticallyEngineeredMice_on.src = (ENV.Web.Root + "images/global/primary_navigation/genetically_engineered_mice_f2.gif");

var imgVideos_off = new Image();
	imgVideos_off.src = (ENV.Web.Root + "images/global/primary_navigation/videos.gif");
var imgVideos_on = new Image();
	imgVideos_on.src = (ENV.Web.Root + "images/global/primary_navigation/videos_f2.gif");
	
var imgBooks_off = new Image();
	imgBooks_off.src = (ENV.Web.Root + "images/global/primary_navigation/books.gif");
var imgBooks_on = new Image();
	imgBooks_on.src = (ENV.Web.Root + "images/global/primary_navigation/books_f2.gif");
	
var imgInterviews_off = new Image();
	imgInterviews_off.src = (ENV.Web.Root + "images/global/primary_navigation/interviews.gif");
var imgInterviews_on = new Image();
	imgInterviews_on.src = (ENV.Web.Root + "images/global/primary_navigation/interviews_f2.gif");

var imgExhibitions_off = new Image();
	imgExhibitions_off.src = (ENV.Web.Root + "images/global/primary_navigation/exhibitions.gif");
var imgExhibitions_on = new Image();
	imgExhibitions_on.src = (ENV.Web.Root + "images/global/primary_navigation/exhibitions_f2.gif");

var imgBiography_off = new Image();
	imgBiography_off.src = (ENV.Web.Root + "images/global/primary_navigation/biography.gif");
var imgBiography_on = new Image();
	imgBiography_on.src = (ENV.Web.Root + "images/global/primary_navigation/biography_f2.gif");
	
var imgPress_off = new Image();
	imgPress_off.src = (ENV.Web.Root + "images/global/primary_navigation/press.gif");
var imgPress_on = new Image();
	imgPress_on.src = (ENV.Web.Root + "images/global/primary_navigation/press_f2.gif");
	
var imgContact_off = new Image();
	imgContact_off.src = (ENV.Web.Root + "images/global/primary_navigation/contact.gif");
var imgContact_on = new Image();
	imgContact_on.src = (ENV.Web.Root + "images/global/primary_navigation/contact_f2.gif");
	
	
// Load the secondary navigaiton images.

var imgSNPhotographs_off = new Image();
	imgSNPhotographs_off.src = (ENV.Web.Root + "images/global/secondary_navigation/photographs.gif");
var imgSNPhotographs_on = new Image();
	imgSNPhotographs_on.src = (ENV.Web.Root + "images/global/secondary_navigation/photographs_f2.gif");

var imgSNAudio_off = new Image();
	imgSNAudio_off.src = (ENV.Web.Root + "images/global/secondary_navigation/audio.gif");
var imgSNAudio_on = new Image();
	imgSNAudio_on.src = (ENV.Web.Root + "images/global/secondary_navigation/audio_f2.gif");

var imgSNFoodchain2_off = new Image();
	imgSNFoodchain2_off.src = (ENV.Web.Root + "images/global/secondary_navigation/foodchain2.gif");
var imgSNFoodchain2_on = new Image();
	imgSNFoodchain2_on.src = (ENV.Web.Root + "images/global/secondary_navigation/foodchain2_f2.gif");

var imgSNSex_off = new Image();
	imgSNSex_off.src = (ENV.Web.Root + "images/global/secondary_navigation/sex.gif");
var imgSNSex_on = new Image();
	imgSNSex_on.src = (ENV.Web.Root + "images/global/secondary_navigation/sex_f2.gif");
	
var imgSNPinkies_off = new Image();
	imgSNPinkies_off.src = (ENV.Web.Root + "images/global/secondary_navigation/pinkies.gif");
var imgSNPinkies_on = new Image();
	imgSNPinkies_on.src = (ENV.Web.Root + "images/global/secondary_navigation/pinkies_f2.gif");

var imgSNSignedBook2_off = new Image();
	imgSNSignedBook2_off.src = (ENV.Web.Root + "images/global/secondary_navigation/signed_book2.gif");
var imgSNSignedBook2_on = new Image();
	imgSNSignedBook2_on.src = (ENV.Web.Root + "images/global/secondary_navigation/signed_book2_f2.gif");
	
var imgSNResidents_off = new Image();
	imgSNResidents_off.src = (ENV.Web.Root + "images/global/secondary_navigation/residents.gif");
var imgSNResidents_on = new Image();
	imgSNResidents_on.src = (ENV.Web.Root + "images/global/secondary_navigation/residents_f2.gif");
	
var imgSNImpostors_off = new Image();
	imgSNImpostors_off.src = (ENV.Web.Root + "images/global/secondary_navigation/imposters.gif");
var imgSNImpostors_on = new Image();
	imgSNImpostors_on.src = (ENV.Web.Root + "images/global/secondary_navigation/imposters_f2.gif");

var imgSNExecutions_off = new Image();
	imgSNExecutions_off.src = (ENV.Web.Root + "images/global/secondary_navigation/executions.gif");
var imgSNExecutions_on = new Image();
	imgSNExecutions_on.src = (ENV.Web.Root + "images/global/secondary_navigation/executions_f2.gif");

var imgSNVideo_off = new Image();
	imgSNVideo_off.src = (ENV.Web.Root + "images/global/secondary_navigation/video.gif");
var imgSNVideo_on = new Image();
	imgSNVideo_on.src = (ENV.Web.Root + "images/global/secondary_navigation/video_f2.gif");

var imgSNSculptures_off = new Image();
	imgSNSculptures_off.src = (ENV.Web.Root + "images/global/secondary_navigation/sculptures.gif");
var imgSNSculptures_on = new Image();
	imgSNSculptures_on.src = (ENV.Web.Root + "images/global/secondary_navigation/sculptures_f2.gif");

var imgSNDrawings_off = new Image();
	imgSNDrawings_off.src = (ENV.Web.Root + "images/global/secondary_navigation/drawings.gif");
var imgSNDrawings_on = new Image();
	imgSNDrawings_on.src = (ENV.Web.Root + "images/global/secondary_navigation/drawings_f2.gif");
	
var imgSNSignedBook_off = new Image();
	imgSNSignedBook_off.src = (ENV.Web.Root + "images/global/secondary_navigation/signed_book.gif");
var imgSNSignedBook_on = new Image();
	imgSNSignedBook_on.src = (ENV.Web.Root + "images/global/secondary_navigation/signed_book_f2.gif");
	
var imgSNInstallation_off = new Image();
	imgSNInstallation_off.src = (ENV.Web.Root + "images/global/secondary_navigation/installation.gif");
var imgSNInstallation_on = new Image();
	imgSNInstallation_on.src = (ENV.Web.Root + "images/global/secondary_navigation/installation_f2.gif");	
	
var imgSNPrint_off = new Image();
	imgSNPrint_off.src = (ENV.Web.Root + "images/global/secondary_navigation/print.gif");
var imgSNPrint_on = new Image();
	imgSNPrint_on.src = (ENV.Web.Root + "images/global/secondary_navigation/print_f2.gif");
	
var imgSNRadio_off = new Image();
	imgSNRadio_off.src = (ENV.Web.Root + "images/global/secondary_navigation/radio.gif");
var imgSNRadio_on = new Image();
	imgSNRadio_on.src = (ENV.Web.Root + "images/global/secondary_navigation/radio_f2.gif");
	
var imgSNFoodchain_off = new Image();
	imgSNFoodchain_off.src = (ENV.Web.Root + "images/global/secondary_navigation/foodchain.gif");
var imgSNFoodchain_on = new Image();
	imgSNFoodchain_on.src = (ENV.Web.Root + "images/global/secondary_navigation/foodchain_f2.gif");
	
var imgSNCockroach_off = new Image();
	imgSNCockroach_off.src = (ENV.Web.Root + "images/global/secondary_navigation/cockroach.gif");
var imgSNCockroach_on = new Image();
	imgSNCockroach_on.src = (ENV.Web.Root + "images/global/secondary_navigation/cockroach_f2.gif");

var imgSafari_off = new Image();
	imgSafari_off.src = (ENV.Web.Root + "images/global/primary_navigation/play_safari_video.gif");
var imgSafari_on = new Image();
	imgSafari_on.src = (ENV.Web.Root + "images/global/primary_navigation/play_safari_video_f2.gif");
	
var imgCaption_off = new Image();
	imgCaption_off.src = (ENV.Web.Root + "images/global/primary_navigation/caption-leaf-cutter.gif");
var imgCaption_on = new Image();
	imgCaption_on.src = (ENV.Web.Root + "images/global/primary_navigation/caption-leaf-cutter_f2.gif");	

var imgFindExhibit_off = new Image();
	imgFindExhibit_off.src = (ENV.Web.Root + "images/global/primary_navigation/find_exhibit.gif");
var imgFindExhibit_on = new Image();
	imgFindExhibit_on.src = (ENV.Web.Root + "images/global/primary_navigation/find_exhibit_f2.gif");

	
function SwapImages(){
	var intIndex = 0;
	
	// Loop over arguments to swap out images.
	for (intIndex = 0 ; intIndex < arguments.length ; intIndex+=2){
		document.images[ arguments[intIndex] ].src = arguments[intIndex + 1].src;	
	}
}




function DropDownMenuSystem(strInstanceName, intDelay){
	this.InstanceName = strInstanceName;
	this.Delay = intDelay;
	this.Interval = null;
	this.Menus = new Array();
}


DropDownMenuSystem.prototype.AddMenu = function(strMenuName){
	this.Menus[this.Menus.length] = strMenuName;
}

DropDownMenuSystem.prototype.PrimaryNavOver = function(strNavItem, imgNavItem){
	var strMenuName = ("menu_" + strNavItem);
	var strNavName = strNavItem;
	
	// Check to see if we should swap the image.
	if (ENV.Section.PrimaryGroup != strNavItem){
		SwapImages(strNavItem, imgNavItem);
	}
	
	// Check to see if this has a menu.
	if (this.HasMenu(strMenuName)){
		// Close all menus except this one.
		this.CloseAllMenus(strMenuName);	
		
		// Show this menu.
		this.OpenMenu(strMenuName);
	} else {
		// Initiate the closing.
		this.InitiateClosing();
	}
}

DropDownMenuSystem.prototype.PrimaryNavOut = function(strNavItem, imgNavItem){
	var strMenuName = ("menu_" + strNavItem);
	var strNavName = strNavItem;
	
	// Check to see if we should swap the image.
	if (ENV.Section.PrimaryGroup != strNavItem){
		SwapImages(strNavItem, imgNavItem);
	}
}

DropDownMenuSystem.prototype.MenuOver = function(strMenuName){
	// Clear any menu closing interval.
	clearTimeout(this.Interval);
}

DropDownMenuSystem.prototype.MenuOut = function(strMenuName){
	// Initiate the closing.
	this.InitiateClosing();
}

DropDownMenuSystem.prototype.OpenMenu = function(strMenuName){
	var objMenu = document.getElementById(strMenuName);
	
	if (objMenu){
		objMenu.style.display = "block";
	}
}

DropDownMenuSystem.prototype.InitiateClosing = function(){
	// Initiate the menu closing.
	this.Interval = setTimeout((this.InstanceName + ".CloseAllMenus()"), this.Delay);
}

DropDownMenuSystem.prototype.CloseMenu = function(strMenuName){
	var objMenu = document.getElementById(strMenuName);
	
	if (objMenu){
		objMenu.style.display = "none";
	}
}

DropDownMenuSystem.prototype.CloseAllMenus = function(strException){
	var intIndex = 0;
	
	// Clear any menu closing interval.
	clearTimeout(this.Interval);
	
	// Loop over items to close them.
	for (intIndex = 0 ; intIndex < this.Menus.length ; intIndex++){
		// Check to see if we have an exception.
		if (!strException || (this.Menus[intIndex] != strException)){
			this.CloseMenu(this.Menus[intIndex]);
		}
	}
}

DropDownMenuSystem.prototype.HasMenu = function(strMenuName){
	var intIndex = 0;
	
	// Loop over items to see if we have a menu for this item.
	for (intIndex = 0 ; intIndex < this.Menus.length ; intIndex++){
	
		if (this.Menus[intIndex] == strMenuName){
			// We found a match, return.
			return(true);
		}
	}
	
	// No menus were found.
	return(false);
}



var Menus = new DropDownMenuSystem("Menus", 500);

Menus.AddMenu("menu_cockroach");
Menus.AddMenu("menu_foodchain");
Menus.AddMenu("menu_houseflies");
