
function setup()
{
	tabs = new Array();
	var page = window.location + ""; // empty string added to force if statement to accept indexOf method to run, Firefox 2.0.0.11, Mac OS 10.4
	
	// get set values depending on calling page
	if (page.indexOf("portfolio.html") != -1)
	{
		tabs[0] = "web";
		tabs[1] = "programming";
		tabs[2] = "university";
	}
	else if (page.indexOf("cv.html") != -1)
	{
		tabs[0] = "information";
		tabs[1] = "skills";
		tabs[2] = "education";
		tabs[3] = "work";
		tabs[4] = "achievements";
		tabs[5] = "additional";
	}
	else
	{
		return;
	}
	
	// create ul element for tabs
	var ul_tabs = document.createElement("ul");
	ul_tabs.id = "subNavigation";
	
	loop = tabs.length;
	
	// build and add html elements for each tab
	for (i = 0; i < loop; i ++)
	{
		var link = document.createElement("a");
		var link_text = document.createTextNode(tabs[i]);
		var list_item = document.createElement("li");
		
		link.setAttribute("href", "display_tab" + i + ""); // pass index of tab as the a element href attribute
		list_item.id = tabs[i] + "Tab";
		
		link.appendChild(link_text);
		list_item.appendChild(link);
		
		ul_tabs.appendChild(list_item);
		
		// add function to a element onclick event
		
		link.onclick = displayTab;
	}
	
	
	
	// add the tabs to the document
	var container = document.getElementById("content");
	//var body = document.getElementById("body");
	
	var h1 = document.getElementsByTagName("h1")[0];	
	container.insertBefore(ul_tabs, h1.nextSibling);
	
	// hide all but first tab
	for (i = 1; i < loop; i ++)
	{
		document.getElementById(tabs[i]).style.display = "none";
	}
	
	// set first table as CCS current tab
	document.getElementById(tabs[0] + "Tab").className = "currentTab";
}

function displayTab()
	{
		// get tab index
		display_tab = this.href + "";
		start = display_tab.indexOf("display_tab") + 11;
		sz_length = display_tab.length;
		
		display_tab = display_tab.substring(start, sz_length);
		loop = tabs.length;
		
		for (i = 0; i < loop; i ++)
		{
			if (i != display_tab)
			{
				document.getElementById(tabs[i]).style.display = "none";
				document.getElementById(tabs[i] + "Tab").className = "tab";
			}
			else
			{
				document.getElementById(tabs[i]).style.display = "block";
				document.getElementById(tabs[i] + "Tab").className = "currentTab";
			}
		}
		
		return false;
	}

window.onload = setup;