// Navigation Tabs Javascript Code
// Copyright 2003-2009 Warburton Technology

// Display the navigation tabs
function createTabs(theTabGroupID, theTabDataArray, theTabOrientation, theDisplayWidth)
{
	var tabIndex;

	// Declare an array for the path match results
	var pathMatchArray = new Array(theTabDataArray.length);

	for (tabIndex = 0; tabIndex < theTabDataArray.length; tabIndex ++)
	{
		// Split the link path into separate folders
		var linkPathArray = theTabDataArray[tabIndex][0].split("/");

		// Compare the link path with the document path
		pathMatchArray[tabIndex] = checkMatchingPaths(linkPathArray, documentPathArray);
	}

	// Choose the selected tab
	var selectedTabIndex = -1;

	var tempPathMatch = 100;

	for (tabIndex = 0; tabIndex < theTabDataArray.length; tabIndex ++)
	{
		if (pathMatchArray[tabIndex] != -1)
		{
			if (pathMatchArray[tabIndex] < tempPathMatch)
			{
				selectedTabIndex = tabIndex;
			}

			tempPathMatch = pathMatchArray[selectedTabIndex];
		}
	}

	var displayWidthRemaining;

	// Save the display width
	displayWidthRemaining = theDisplayWidth;

	// Draw the navigation tabs
	for (tabIndex = 0; tabIndex < theTabDataArray.length; tabIndex ++)
	{
		var tabLink = rootPath + theTabDataArray[tabIndex][0];
		var tabText = theTabDataArray[tabIndex][1];

		var tabSubstyle = "auto";

		if (theTabDataArray[tabIndex][2] != undefined)
		{
			// Set the tab substyle
			tabSubstyle = theTabDataArray[tabIndex][2];
		}

		var tabHidden = true;

		if (tabSubstyle == "title")
		{
			tabHidden = false;
		}

		if (tabSubstyle == "auto")
		{
			// Determine which size of tab to display according to the length of tab text
			if 	(tabText.length < 4)		tabSubstyle = "verysmall";
			else if (tabText.length < 7)	tabSubstyle = "small";
			else if (tabText.length < 10)	tabSubstyle = "medium";
			else if (tabText.length < 13)	tabSubstyle = "large";
			else if (tabText.length < 17)	tabSubstyle = "verylarge";
			else							tabSubstyle = "supersize";
		}

		var tabWidth;

		switch (tabSubstyle)
		{
			case "verysmall":	tabWidth = 36;		break;
			case "small":		tabWidth = 46;		break;
			case "medium":		tabWidth = 66;		break;
			case "large":		tabWidth = 86;		break;
			case "verylarge":	tabWidth = 106;		break;
			case "supersize":	tabWidth = 126;		break;
			case "title":		tabWidth = 112;		break;
			case "default":		tabWidth = 112;		break;
			default:			tabWidth = 112;
		}

		if ((displayWidthRemaining - tabWidth) <= 0)
		{
			document.write("<br>");

			// Reset the remaining display width
			displayWidthRemaining = theDisplayWidth;
		}

		if (tabIndex == selectedTabIndex)
		{
			// Display the tab selected
			document.write("<a class=\"tab_" + theTabOrientation + "_" + tabSubstyle + "_selected\">" + tabText + "</a>");
		}
		else
		{
			// Display the tab unselected
			document.write("<a class=\"tab_" + theTabOrientation + "_" + tabSubstyle + "_default\" href=\"" + tabLink + "\">" + tabText + "</a>");
		}
		
		// Calculate the remaining display width
		displayWidthRemaining = displayWidthRemaining - tabWidth;
	}
}

function rightBackString(fullString, subString)
{
	var returnString = "";

	if (fullString.lastIndexOf(subString) != -1)
	{
		returnString = fullString.substring(fullString.lastIndexOf(subString) + 1, fullString.length);
	}

	return returnString;
}

function leftBackString(fullString, subString)
{
	var returnString = "";

	if (fullString.lastIndexOf(subString) != -1)
	{
		returnString = fullString.substring(0, fullString.lastIndexOf(subString));
	}

	return returnString;
}
