// JavaScript Document

var popupLinks = {
	"workingForests": [
		["A Renewable Resource", "arenewableresource.html"],
		["Reforestation", "reforestation.html"],
		["Habitat Protection", "habitatprotection.html"],
		["Forest Health", "foresthealth.html"],
		["Timber Harvest", "timberharvest.html"],
		["Forest Products", "forestproducts.html"],
		["Technology", "technology.html"],
		["Steep Slope Protection", "steepslopeprotection.html"],
		["workingforests.html"]
	],
				"aRenewableResource": [
					["arenewableresource.html"]											 
				],
				"reforestation": [
					["reforestation.html"]
				],
				"habitatProtection": [
					["Roads and Culverts", "roadsandculverts.html"],
					["Steep Slopes", "steepslopes.html"],
					["Buffer Zones", "bufferzones.html"],
					["habitatprotection.html"]
				],
							"roadsAndCulverts": [
								["roadsandculverts.html"]										 
							],
							"steepSlopes": [
								["steepslopes.html"]								
							],
							"bufferZones": [
								["bufferzones.html"]								
							],
				"forestHealth": [
					["Wildfire", "wildfire.html"],
					["Animal Damage", "animaldamagecontrol.html"],
					["foresthealth.html"]
				],
							"wildfire": [
								["wildfire.html"]						 
							],
							"animalDamageControl": [
								["animaldamagecontrol.html"]												
							],
				"timberHarvest": [
					["timberharvest.html"]									
				],
				"forestProducts": [
					["forestproducts.html"]									 
				],
				"technology": [
					["technology.html"]							 
				],
				"steepSlopeProtection": [
					["steepslopeprotection.html"]							 
				],
				
	"sustainableForestry": [
		["Fish &amp; Wildlife", "fishandwildlife.html"],
		["Cool, Clean Water", "coolcleanwater.html"],
		["Habitat", "habitat.html"],
		["Forest Certification", "forestcertification.html"],
		["sustainableforestry.html"]
	],
				"fishAndWildlife": [
					["Fish", "fish.html"],
					["Wildlife", "wildlife.html"],
					["Amphibians", "amphibians.html"],					
					["Birds", "birds.html"],
					["Northern Spotted Owl", "northernspottedowl.html"],
					["fishandwildlife.html"]										
				],
							"fish": [
								["fish.html"]
							],
							"mammals": [
								["wildlife.html"]
							],
							"amphibians": [
								["amphibians.html"]
							],							
							"birds": [
								["birds.html"]
							],
							"northernSpottedOwl": [
								["northernspottedowl.html"]
							],
				"coolCleanWater": [
					["coolcleanwater.html"]						 
				],
				"habitat": [
					["habitat.html"]						
				],
				"forestCertification": [
					["Tree Farm Program", "treefarmprogram.html"],
					["forestcertification.html"]												
				],
							"treeFarmProgram": [
								["treefarmprogram.html"]
							],
				
	"science": [
		["Adaptive Management", "adaptivemanagement.html"],
		["Cooperative Monitoring, Evaluation, and Research", "cooperativemonitoring.html"],
		["science.html"]
	],
				"adaptiveManagement": [
					["adaptivemanagement.html"]											 
				],
				"cooperativeMonitoring": [
					["cooperativemonitoring.html"]													
				],
				
	"policy": [
	
	
		["Forests &amp; Fish Law", "http://www.forestsandfish.com/about.htm" ],
		["Forests &amp; Fish Law Results", "http://www.forestsandfish.com/results.htm" ],
		["Forests &amp; Fish Law Resources", "http://www.forestsandfish.com/resources.htm" ],
		/*["Forests &amp; Fish Law", "forestsandfishlaw.html"],*/
		["Habitat Conservation Plan", "habitatconservationplans.html"],
		["Regulatory Environment", "regulatoryenvironment.html"],
		//["Legislative Highlights", "legislative.html"],
		["Climate Change", "climatechange.html"],
		["Biomass", "biomasspolicy.html"],
		["policy.html"]
	],
				"forestsAndFishLaw": [
					["forestsandfishlaw.html"]											
				],
				"forestsAndFishLaw2": [
					["forestsandfishlaw.html"]											
				],
				"forestsAndFishLaw3": [
					["forestsandfishlaw.html"]											
				],
				"habitatConservationPlans": [
					["habitatconservationplans.html"]														 
				],
				"regulatoryEnvironment": [
					["regulatoryenvironment.html"]													
				],
				/*
				"legislativeHighlights": [
					["legislative.html"]
				],
				*/
				"climateChange": [
					["climatechange.html"]
				],

				"biomassPolicy": [
					["biomasspolicy.html"]
					],


	"education": [
		["Environmental Education", "environmentaleducation.html"],
		["About Washington's Forests", "aboutwaforests.html"],
		["education.html"]
	],
				"environmentalEducation": [
					["environmentaleducation.html"]													 
				],
				"aboutWAForests": [
					["Private Forestland", "privateforestland.html"],
					["Government Forestland", "governmentforestland.html"],
					["Forest Regions", "forestregions.html"],
					["Tree Species", "treespecies.html"],
					["aboutwaforests.html"]
				],
							"privateForestland": [
								["privateforestland.html"]											
							],
							"governmentForestland": [
								["governmentforestland.html"]												 
							],
							"forestRegions": [
								["forestregions.html"]								
							],
							"treeSpecies": [
								["treespecies.html"]								
							],
				
	"newsAndResources": [
		["News", "news.html"],
		["Forests &amp; Fish Update", "forestsandfishnewsletters.html"],
		["FYI Research Summary", "fyiresearchsummaries.html"],
		["Booklets &amp; Brochures", "brochure.html"],
		["Annual Meetings", "annualmeetings.html"],
		["Annual Reports", "/ar/"],
		["Forestry Links", "links.html"],
		["Photo Album", "photoalbum.html"],
		["news.html"]
	],
				"news": [
					["news.html"]				 
				],
				"links": [
					["links.html"]
				],
				"brochure": [
					["brochure.html"]
				],
				"FYIResearchSummaries": [
					["fyiresearchsummaries.html"]
				],
				"annualMeetings": [
					["annualmeetings.html"]
				],
				"WFPAAnnualReports": [
					["/ar/"]
				],
				"forestsAndFishNewsletters": [
					["forestsandfishnewsletters.html"]
				],
				"photoAlbum": [
					["photoalbum.html"]
				],
				
	"about": [
		["Member Companies", "membercompanies.html"],
		["Values of Membership", "valueofmembership.html"],
		["Membership Benefits", "membershipbenefits.html"],
		["aboutwfpa.html"]
	],
				"memberCompanies": [
					["membercompanies.html"]
				],
				"valueOfMembership": [
					["valueofmembership.html"]
				],
				"membershipBenefits": [
					["Communications", "communications.html"],
					["Environmental Education", "environmentaleducationbenefit.html"],
					["Forest Tax &amp; Economics", "foresttaxandeconomics.html"],
					["Governmental Relations", "governmentalrelations.html"],
					["Landowner Programs", "landownerprograms.html"],
					["Regulation &amp; Policy", "regulationandpolicy.html"],
					["membershipbenefits.html"]
				],				
							"regulationAndPolicy": [
								["regulationandpolicy.html"]
							],
							"forestTaxAndEconomics": [
								["foresttaxandeconomics.html"]
							],
							"governmentalRelations": [
								["governmentalrelations.html"]
							],
							"communicationsAndPublicInformation": [
								["communications.html"]
							],
							"environmentalEducationBenefit": [
								["environmentaleducationbenefit.html"]
							],
							"landownerPrograms": [
								["landownerprograms.html"]
							],
	
	"contact": [
		["contact.html"]
	]
};

var popupTitles = {
	"workingForests": "Working Forests",
		"aRenewableResource": "A Renewable Resource",
		"reforestation": "Reforestation",
		"habitatProtection": "Habitat Protection",
			"roadsAndCulverts": "Roads and Culverts",
			"steepSlopes": "Steep Slopes",
			"bufferZones": "Buffer Zones",
		"forestHealth": "Forest Health",
			"wildfire": "Wildfire",
			"animalDamageControl": "Animal Damage",
		"timberHarvest": "Timber Harvest",
		"forestProducts": "Forest Products",
		"technology": "Technology",
		"steepSlopeProtection": "Steep Slope Protection",
	"sustainableForestry": "Sustainable Forestry",
		"fishAndWildlife": "Fish &amp; Wildlife",
			"fish": "Fish",
			"mammals": "Wildlife",
			"amphibians": "Amphibians",			
			"birds": "Birds",
			"northernSpottedOwl": "Northern Spotted Owl",
		"coolCleanWater": "Cool, Clean Water",
		"habitat": "Habitat",
		"forestCertification": "Forest Certification",
			"treeFarmProgram": "Tree Farm Program",
	"science": "Science",
		"adaptiveManagement": "Adaptive Management",
		"cooperativeMonitoring": "Cooperative Monitoring, Evaluation, and Research",
	"policy": "Policy",
		"forestsAndFishLaw": "Forests &amp; Fish Law",
		"forestsAndFishLaw2": "Forests &amp; Fish Law Results",
		"forestsAndFishLaw3": "Forests &amp; Fish Law Resources",
		"habitatConservationPlans": "Habitat Conservation Plan",
		"regulatoryEnvironment": "Regulatory Environment",
		//"legislativeHighlights": "Legislative Highlights",
		"climateChange": "Climate Change",
		"biomassPolicy": "Biomass",
	"education": "Education",
		"environmentalEducation": "Environmental Education",
		"aboutWAForests": "About Washington's Forests",
			"privateForestland": "Private Forestland",
			"governmentForestland": "Government Forestland",
			"forestRegions": "Forest Regions",
			"treeSpecies": "Tree Species",
	"newsAndResources": "News &amp; Resources",
		"news": "News",
		"briefingPapers": "Briefing Papers",
		"brochure": "Booklets &amp; Brochures",
		"FYIResearchSummaries": "FYI Research Summary",
		"annualMeetings": "Annual Meetings",
		"WFPAAnnualReports": "Annual Reports",
		"forestsAndFishNewsletters": "Forests &amp; Fish Update",
		"links": "Forestry Links",
		"photoAlbum": "Photo Album",
	"about": "About WFPA",
		"memberCompanies": "Member Companies",
		"valueOfMembership": "Value Of Membership",
		"membershipBenefits": "Membership Benefits",					
			"communicationsAndPublicInformation": "Communications",
			"environmentalEducationBenefit": "Environmental Education",
			"forestTaxAndEconomics": "Forest Tax &amp; Economics",
			"governmentalRelations": "Governmental Relations",
			"landownerPrograms": "Landowner Programs",
			"regulationAndPolicy": "Regulation &amp; Policy",	
	"contact": "Contact"
};

var popupCaptions = {
	"workingForests": "What can you find in a working forest? Find out how WFPA's members responsibly manage their private forestland.",
		"aRenewableResource": "Our members replant Washington's private forests with three trees for every one harvested.",
		"reforestation": "Washington has some of the toughest forest practice laws in the country, requiring a harvested area to be replanted within three years.",
		"habitatProtection": "Private forest landowners have a special obligation to support fish and wildlife in their working forests.",
			"roadsAndCulverts": "Improving the roads and culverts of our private forests means clean water for Washington&rsquo;s native fish.",
			"steepSlopes": "Steep, potentially unstable slopes can cause landslides that devastate salmon habitat.",
			"bufferZones": "Trees and vegetation along streams provide critical shade and habitat for Washington&rsquo;s fish and wildlife.",
		"forestHealth": "Washington&rsquo;s private forest landowners protect their growing forests from fire, insects, and disease, while safeguarding wildlife and water quality.",
			"wildfire": "Reintroducing fire to fire-dependent ecosystems, in a safe and responsible manner, is one way to prevent catastrophic wildfires.",
			"animalDamageControl": "Animal damage has an enormous economic impact on private forest landowners, causing millions of dollars in damage each year in Washington.",
		"timberHarvest": "Harvesting is the process of removing trees for wood, paper, and pulp-based products while supporting the long-term health of the forest.",
		"forestProducts": "Over 5,000 different wood, paper, and pulp-based products are created from the trees harvested in private forests.",
		"technology": "From the tree nursery to the mill, technological innovation has had a profound impact on Washington&rsquo;s forest products industry.",
		"steepSlopeProtection": "Private Forest Landowners are applying Adaptive Management techniques to help reduce the risk of landslides in our state's working forests.",
	"sustainableForestry": "Sustainable forestry provides jobs for rural communities, cleans our air and water, and protects fish and wildlife habitat.",
		"fishAndWildlife": "Private foresters play a significant role in protecting fish and wildlife.",
			"fish": "Pacific salmon species are a cultural icon for Washington and the Pacific Northwest.",
			"amphibians": "Frogs and salamanders dominate Washington&rsquo;s amphibian population.",
			"mammals": "Washington's mammal population is flourishing in private forests.",
			"birds": "The Northern Spotted Owl, Bald Eagle, and Marbled Murrelet are three bird species on the lists for endangered and threatened species.",
			"northernSpottedOwl": "The foundation of the current recovery strategy for the Northern Spotted Owl is a network of owl conservation areas located on Federal lands.",
		"coolCleanWater": "From rivers and streams to wetlands and lakes, private forest landowners are committed to sustaining Washington's water quality.",
		"habitat": "The space that fish and wildlife depend on for food, water, and shelter comes in many different shapes and sizes.",
		"forestCertification": "Forest certification is a voluntary process to demonstrate sustainable forestry.",
			"treeFarmProgram": "The Washington Tree Farm Program (WTFP) is sponsored by the American Tree Farm System&reg;, a program of the American Forest Foundation.",
	"science": "WFPA members rely on science to guide them in discovering the best forest practices.",
		"adaptiveManagement": "Private forest landowners continually improve their practices through scientific learning and new information.",
		"cooperativeMonitoring": "The scientific community works collaboratively to address forest related issues.",
	"policy": "Washington has among the toughest environmental policies in the nation.",
		"forestsAndFishLaw": "The Forests &amp; Fish Law protects cool, clean water for generations to come.",
		"forestsAndFishLaw2": "The Forests &amp; Fish Law is making a difference.",
		"forestsAndFishLaw3": "Key documents on the Forests &amp; Fish Law.",
		"habitatConservationPlans": "Washington State's Forest Practices HCP is a 50-year agreement with the federal government.",
		"regulatoryEnvironment": "Forestry is regulated by state and federal environmental laws and subject to Native American treaty rights.",
		//"legislativeHighlights": "The WFPA Legislative Highlights detail the activities and issues affecting our timber industry.",
		"climateChange": "Resources to help describe the forest products industry&rsquo;s unique role and perspective on climate change policy options.",
		"biomassPolicy": "Generating electricity with biomass provides environmental benefits that make it a preferred alternative to fossil fuels.",
	"education": "Educate yourself about Washington&rsquo;s forests and learn the issues of 21st century forestry.",
		"environmentalEducation": "WFPA provides students the opportunity to investigate environmental issues and encourages them to make informed, responsible decisions.",
		"aboutWAForests": "With its temperate climate, abundant precipitation, and fertile soils, Washington has some of the most productive forests in the world.",
			"privateForestland": "Thirty-seven percent of Washington's forestland, about 7.8 million acres, is owned or managed by private landowners.",
			"governmentForestland": "Sixty-three percent of Washington's forestland, about 13.5 million acres, is owned or managed by the government.",
			"forestRegions": "Each of Washington's four forest regions has its own variety of trees, plants, and animals.",
			"treeSpecies": "Washington's forests are home to about 25 native tree species.",
	"newsAndResources": "Visit our website for the most recent news and research on Washington's private forests.",
		"news": "WFPA keeps its stakeholders informed with important news and events happening within the forest products industry.",
		"brochure": "WFPA publishes informational booklets and brochures to educate the public about important forestry topics.",
    "annualMeetings": "WFPA's annual meeting celebrates the year's achievements and coordinates a direction for our membership for the upcoming year.",
		"FYIResearchSummaries": "The FYI Research Summary highlights scientific research being conducted to benefit Washington's private forestland.",
		"WFPAAnnualReports": "WFPA's annual report to its members highlights yearly achievements and reviews progress made within its various programs.",
		"forestsAndFishNewsletters": "The Forests &amp; Fish Update informs its readers about the important work being done through Washington's Forests &amp; Fish Law.",
		"links": "If you want to learn more about the timber industry, we have provided a good selection of forestry websites to choose from.",
		"photoAlbum": "View our photo album to see what's happening at WFPA.",
	"about": "Washington Forest Protection Association (WFPA) is a trade association representing private forest landowners in Washington State.",
		"memberCompanies": "Our members are large and small companies, individuals and families.",
		"valueOfMembership": "This diversity of membership is the cornerstone of WFPA's strength and effectiveness in representing the forest industry.",
		"membershipBenefits": "WFPA is committed to providing first-class service to our members.",
			"regulationAndPolicy": "WFPA provides Regulation &amp; Policy programs in Forest Management and Environmental Policy.",
			"forestTaxAndEconomics": "The Forest Tax &amp; Economics program manages the tax and economics issues of the forest industry.",
			"governmentalRelations": "The Governmental Relations program develops and implements strategic plans to address public policy issues.",
			"communicationsAndPublicInformation": "The Communications program represents the industry's stewardship and forest practices to the public.",
			"environmentalEducationBenefit": "The Environmental Education program works with schools and communities to teach youth to use critical and creative thinking to make wise decisions about forestry.",
			"landownerPrograms": "The Animal Damage Control Program and Tree Farm Program are two Landowner programs that WFPA manages.",
	"contact": "Please contact us by phone, email, or stop by our offices. We want to hear from you."
};





// --------
// Popup State Tracking
// --------

var popupMenuItem;
var popupVisible = false;
var popupTimeout;



// recordMouseover
//

function recordPopup(menuItem) {
  popupMenuItem = menuItem;
}



// recordMouseover
//

function recordMouseover() {
  popupVisible = true;
  spawnTimeout();
}



// recordMouseout
//

function recordMouseout() {
  popupVisible = false;
  spawnTimeout();
}



// spawnTimeout
//

function spawnTimeout() {
  if (!popupTimeout) popupTimeout = setTimeout(processPopup, 0);
}





// --------
// Mouse events
// --------

// popupMouseover
//

function popupMouseover(e) {
  recordMouseover(this);
}



// popupMouseout
//

function popupMouseout(e) {
  recordMouseout(this);
}



// menuLinkMouseover
//

function menuLinkMouseover(e) {
  recordPopup(this);
  recordMouseover(this);
}



// menuLinkMouseout
//

function menuLinkMouseout(e) {
  recordPopup(this);
  recordMouseout(this);
}





// --------
// Popup Manipulation
// --------

// createPopup
//

function createPopup() {
  var myPopup = document.createElement("div");
	myPopup.id = "menuPopup";

  // Container
  var myPopupContainer = document.createElement("div");
  myPopupContainer.id = "popupContainer";
	myPopupContainer.onmouseover = popupMouseover;
	myPopupContainer.onmouseout = popupMouseout;

  // Container internals
  var myPopupArrow = document.createElement("div");
  myPopupArrow.id = "popupArrow";

  var myPopupTop = document.createElement("div");
  myPopupTop.id = "popupTop";

  var myPopupContent = document.createElement("div");
  myPopupContent.id = "popup";

  var myPopupBottom = document.createElement("div");
  myPopupBottom.id = "popupBottom";


  // Content
  var myPopupTitle = document.createElement("div");
  myPopupTitle.id = "popupTitle";

  var myPopupCaption = document.createElement("div");
  myPopupCaption.id = "popupCaption";

  var myPopupBody = document.createElement("ul");
  myPopupBody.id = "popupBody";


  // Content attachments
  myPopupContent.appendChild(myPopupTitle);
  myPopupContent.appendChild(myPopupCaption);
  myPopupContent.appendChild(myPopupBody);


  // Internals attachments
  myPopupContainer.appendChild(myPopupTop);
  myPopupContainer.appendChild(myPopupContent);
  myPopupContainer.appendChild(myPopupBottom);
  myPopupContainer.appendChild(myPopupArrow);
  myPopup.appendChild(myPopupContainer);

  return myPopup;
}



// processPopup
//

function processPopup() {
  // Reset the timeout
  popupTimeout = 0;

	var myPopup = document.getElementById("menuPopup");

  if (!popupVisible || !popupMenuItem || !popupMenuItem.id || !popupLinks[popupMenuItem.id]) {
    if (myPopup) myPopup.style.display = "none";
    return;
  }

	if (!myPopup) myPopup = createPopup();
  var name = popupMenuItem.id;

  if (myPopup.contentId != name) {
    myPopup.contentId = name;

    // Move the popup to the correct location
  	popupMenuItem.parentNode.insertBefore(myPopup, popupMenuItem);

    // Grab the containers
    var myPopupTitle = document.getElementById("popupTitle");
    var myPopupCaption = document.getElementById("popupCaption");
    var myPopupBody = document.getElementById("popupBody");

    // Pages uri lookup
    var pagesUri = getPagesUri();

    // Title
    myPopupTitle.innerHTML = '<a class="noArrow" href="' + pagesUri + popupLinks[name][popupLinks[name].length - 1][0] + '" target="_self">' + popupTitles[name] + '</a>';

    // Caption
    myPopupCaption.innerHTML = popupCaptions[name] || "";
    if (popupCaptions[name]) {
      myPopupCaption.style.display = "block";
    }
    else {
      myPopupCaption.style.display = "none";
    }

    // Body
  	var linksHtml = "";
  	for (i = 0; i < popupLinks[name].length - 1; i++) {
      var linkUri = popupLinks[name][i][1];
      if ((linkUri.charAt(0)!= "/") && (linkUri.charAt(0)!= ".") && (linkUri.indexOf("http") == -1)) {
        // Assume pages directory unless /, ./, or ../ are at the start of the uri, or if its a full URL containing http
        linkUri = pagesUri + linkUri;
      }
  		linksHtml += "<li><a href='" + linkUri + "'>" + popupLinks[name][i][0] + "</a></li>";
  	}

    if (linksHtml) {
      myPopupBody.innerHTML = "<ul>" + linksHtml + "</ul>";
      myPopupBody.style.display = "block";
    }
    else {
      myPopupBody.innerHTML = ">";
      myPopupBody.style.display = "none";
    }
  }

  myPopup.style.display = "block";
}



// getPagesUri
//

function getPagesUri() {
  var scriptDir = "script/"; // The location of the script directory

  try {
    var head = document.getElementsByTagName("head")[0];
    var scripts = head.getElementsByTagName("script");
    var script, i=0;
    while (script = scripts[i++]) {
      var uri = String(script.src || script.getAttribute("src") || "");
      var z = uri.indexOf(scriptDir);
      if (z != -1) return uri.substring(0, z) + "pages/";
    }
  }
  catch (e) {}

  // If it died for some odd reason or we couldn't find the script tag then
  // default to an absolute url.
  return "/pages/";
}





// --------
// Mouse event assignment
// --------

// setMenuLinkFunctions
//

function setMenuLinkFunctions() {
  // Get the menu container
  var menuObj = document.getElementById("menu");
  if (!menuObj) return;

  // Get the anchors in the menu container
  var anchors = menuObj.getElementsByTagName("a");

  // Assign the mouseovers and mouseouts
  var anchorObj, i=0;
  while (anchorObj = anchors[i++]) {
    var name = anchorObj.id;
    if (!popupLinks[name] && !popupTitles[name] && !popupCaptions[name]) continue;
    if (anchorObj.className.indexOf("Active") != -1) continue;
    anchorObj.onmouseover = menuLinkMouseover;
    anchorObj.onmouseout = menuLinkMouseout;
  }
}




// --------
// Image preloading
// --------

var preloadImageList = [
  "../images/popupTop.gif",
  "../images/popupBottom.gif",
	"../images/popupBg.gif",
	"../images/popupArrow.gif"
];



// preloadImages
//

var preloadObjectList = [];

function preloadImages() {
  for (var i=0; i < preloadImageList.length; i++) {
    var imageObj = new Image();
    imageObj.src = preloadImageList[i];
    preloadObjectList.push(imageObj);
  }
}





// --------
// Setup
// --------

var setupFunctions = [setMenuLinkFunctions];



// setup
//

function setup() {
  var func, i=0;
  while (func = setupFunctions[i++]) func();
}

if (!window.onload) window.onload = setup;

// I'm making this load straight away instead of waiting until the rest of the
// loads. -JS
preloadImages();

