	/* This function will automatically rotate the "main features" of the home page. */
	var currentItem; //Default values
	var nextItem; //Default values
	var fadingOut = false;
	var fadingIn = false;
	var currentFadeOutValue = 100;
	var currentFadeInValue = 0;
	var swapTimer;
	var fadeTimer;
	var keynote_link = "working-with-dr-bob/keynote-speaking/";
	var teamwork_link = "working-with-dr-bob/teamwork-retreats/";
	var strategic_link = "working-with-dr-bob/strategic-planning/";

	function rotateFeatures()
	{
		swapTimer = setTimeout("swapFeature(true);", 18000); //Swap every 18 seconds.
	}

	function swapFeature(keepSwitching)
	{
		fadeOut(currentItem);
		fadeIn(nextItem);
		if (keepSwitching)
		{
			/*
				The 'nextItem' variable has to be set to 2 features ahead because
				by the time animation actually takes place - the currentItem will
				be 1 behind.

				For example: if the currentItem at time of this function running
				is 'keynote' than the nextItem to be shown will be the 'strategic'
				item. By the time the script runs (due to timeout latency) the
				currentItem will in fact be 'teamwork'.
			*/
			if (currentItem == "keynote")
			{
				nextItem = "strategic";
			}
			else if (currentItem == "teamwork")
			{
				nextItem = "keynote";
			}
			else if (currentItem == "strategic")
			{
				nextItem = "teamwork";
			}
			rotateFeatures();
		}
	}

	function userInitiatedSwap(switchTo)
	{
		//The user wants to specifically swap to another "pane".

		//Only allow this functionality if we're not already in the middle of a transition
		if (!(fadingIn || fadingOut))
		{
			clearTimeout(swapTimer); //This stops the automatic rotation.

			nextItem = switchTo;

			swapFeature(false);
		}
	}

	function fadeOut(item)
	{
		if (fadingIn)
		{
			//Wait 1/4 second to fade out.
			setTimeout("fadeOut('"+item+"');", 250);
		}
		else
		{
			if (currentFadeOutValue > 0)
			{
				fadingOut = true;
				currentFadeOutValue -= 8; //Subtract 8 from the opacity value
				if (item == "keynote")
				{
					document.getElementById("fs_keynote_link").className = "";
					document.getElementById("keynote_container").style.opacity = currentFadeOutValue / 100;
					document.getElementById("keynote_container").style.filter = "alpha(opacity="+currentFadeOutValue+")";
				}
				else if (item == "teamwork")
				{
					document.getElementById("fs_teamwork_link").className = "";
					document.getElementById("teamwork_container").style.opacity = currentFadeOutValue / 100;
					document.getElementById("teamwork_container").style.filter = "alpha(opacity="+currentFadeOutValue+")";
				}
				else if (item == "strategic")
				{
					document.getElementById("fs_strategic_link").className = "";
					document.getElementById("strategic_container").style.opacity = currentFadeOutValue / 100;
					document.getElementById("strategic_container").style.filter = "alpha(opacity="+currentFadeOutValue+")";
				}
				fadeTimer = setTimeout("fadeOut('"+item+"');", 1);
			}
			else
			{
				//Finally, actually hide the layers.
				if (item == "keynote")
				{
					document.getElementById("keynote_container").style.display = "none";
				}
				else if (item == "teamwork")
				{
					document.getElementById("teamwork_container").style.display = "none";
				}
				else if (item == "strategic")
				{
					document.getElementById("strategic_container").style.display = "none";
				}

				//Reset the fade out value back to 100 for the next item.
				currentFadeOutValue = 100;
				fadingOut = false;
			}
		}
	}

	function fadeIn(item)
	{
		if (fadingOut)
		{
			//Wait 1/4 second to fade in.
			setTimeout("fadeIn('"+item+"');", 250);
		}
		else
		{
			if (currentFadeInValue == 0)
			{
				fadingIn = true;
				//Make the items available...
				if (item == "keynote")
				{
					document.getElementById("keynote_container").style.display = "block";
					document.getElementById("feature_learn_more").innerHTML = '<a href="'+keynote_link+'" title="Learn More">Learn More</a>';
				}
				else if (item == "teamwork")
				{
					document.getElementById("teamwork_container").style.display = "block";
					document.getElementById("feature_learn_more").innerHTML = '<a href="'+teamwork_link+'" title="Learn More">Learn More</a>';
				}
				else if (item == "strategic")
				{
					document.getElementById("strategic_container").style.display = "block";
					document.getElementById("feature_learn_more").innerHTML = '<a href="'+strategic_link+'" title="Learn More">Learn More</a>';
				}
				currentItem = item;
				currentFadeInValue = 8;
				fadeIn(item);
			}
			else if (currentFadeInValue < 100)
			{
				currentFadeInValue += 8; //Add 8 to the opacity value.
				if (item == "keynote")
				{
					document.getElementById("keynote_container").style.opacity = currentFadeInValue / 100;
					document.getElementById("keynote_container").style.filter = "alpha(opacity="+currentFadeInValue+")";
				}
				else if (item == "teamwork")
				{
					document.getElementById("teamwork_container").style.opacity = currentFadeInValue / 100;
					document.getElementById("teamwork_container").style.filter = "alpha(opacity="+currentFadeInValue+")";
				}
				else if (item == "strategic")
				{
					document.getElementById("strategic_container").style.opacity = currentFadeInValue / 100;
					document.getElementById("strategic_container").style.filter = "alpha(opacity="+currentFadeInValue+")";
				}
				fadeTimer = setTimeout("fadeIn('"+item+"');", 1);
			}
			else
			{
				//We're good. Reset the currentFadeInValue to 0 for the next item.
				currentFadeInValue = 0;
				if (item == "keynote")
				{
					document.getElementById("fs_keynote_link").className = "selected";
				}
				else if (item == "teamwork")
				{
					document.getElementById("fs_teamwork_link").className = "selected";
				}
				else if (item == "strategic")
				{
					document.getElementById("fs_strategic_link").className = "selected";
				}
				fadingIn = false;
			}
		}
	}

	window.onload = function() {
		// CALL ANY ONLOAD SCRIPTS HERE, NOT IN THE BODY! This helps completely separate the JavaScript portion from the front end code.

		//First, initialize the current/next item variables:
		if (document.getElementById('fs_keynote_link').className == "selected")
		{
			currentItem = "keynote";
			nextItem = "teamwork";
		}
		else if (document.getElementById('fs_teamwork_link').className == "selected")
		{
			currentItem = "teamwork";
			nextItem = "strategic";
		}
		else if (document.getElementById('fs_strategic_link').className == "selected")
		{
			currentItem = "strategic";
			nextItem = "keynote";
		}

		rotateFeatures();
	}
