
var tabPages = 
	[
		{ "name" : "For Employers",     "linkUrl" : "employers.shtml",       "linkTitle" : "Go to For Employers",     "prefix" : "tabEmployers", "className" : "tabEmployersSelected" },
		{ "name" : "For Policy Makers", "linkUrl" : "policy_makers.shtml",        "linkTitle" : "Go to For Policy Makers", "prefix" : "tabPolicy",    "className" : "tabPolicySelected"    },
		{ "name" : "For the Community", "linkUrl" : "community.shtml", "linkTitle" : "Go to For the Community", "prefix" : "tabCommunity", "className" : "tabCommunitySelected" }
	];

var currentTab = 0;
var currentPage = 0;

function nextPage()
{
	if ( currentPage == getPageCount(currentTab)-1 )
		return;
	currentPage++;
	refreshPage();
}

function previousPage()
{
	if ( currentPage == 0 )
		return;
	currentPage--;
	refreshPage();
}

function refreshPage()
{
	// hide all pages
	for ( var tabIndex = 0; tabIndex < tabPages.length; tabIndex++ )
	{
		var pageCount = getPageCount(tabIndex);
		for ( var pageIndex = 0; pageIndex < pageCount; pageIndex++ )
		{
			var pageId = tabPages[tabIndex].prefix + "_Page_" + (pageIndex+1);
			var page = document.getElementById(pageId);
			page.style.display = "none";
		}
	}
		
	// show only the page that is currently selected
	var selectedPageId = tabPages[currentTab].prefix + "_Page_" + (currentPage+1);
	var selectedPage = document.getElementById(selectedPageId);
	selectedPage.style.display = "block";

	// show or hide the previous page link as appropriate
	var tabPreviousPageLink = document.getElementById("tabPreviousPageLink");	
	if ( currentPage == 0 )
		tabPreviousPageLink.style.display = "none";
	else
		tabPreviousPageLink.style.display = "";

	// show or hide the next page link as appropriate
	var tabNextPageLink = document.getElementById("tabNextPageLink");	
	if ( currentPage == getPageCount(currentTab)-1 )
		tabNextPageLink.style.display = "none";
	else
		tabNextPageLink.style.display = "";
		
	// update the middle navigation link to reflect the current tab's link
	var tabMiddleNavigationLink = document.getElementById("tabMiddleNavigationLink");
	tabMiddleNavigationLink.href = tabPages[currentTab].linkUrl;
	tabMiddleNavigationLink.innerHTML = tabPages[currentTab].linkTitle;
}

function selectTab(tabIndex)
{
	currentTab = tabIndex;
	currentPage = 0;
	refreshPage();
	
	var tabContainer = document.getElementById("tabContainer");
	tabContainer.className = "tabs " + tabPages[currentTab].className;
}

// dynamically determine the number of pages for a given tab based on how many (correctly named and sequential) page elements exist
function getPageCount(tabIndex)
{
	var pageCount = 0;
	var nextId = 1;
	while ( 1 )
	{
		var testPageId = tabPages[tabIndex].prefix + "_Page_" + nextId;
		var page = document.getElementById(testPageId);
		if ( page == null )
			return pageCount;
		pageCount++;
		nextId++;
	}
}
