var which_text = new Array();
var which_link = new Array();
// which tab is currently active
var text_on;
var firstrun = true;
var qtLoaded = false;
var qtOffLeft = false;


// FOR THE MAIN PROJECT PAGE
function rolloverProjects(value) {
	if (text_on !== undefined) {
		which_text[text_on].style.display = 'none';
	}
	which_text[value].style.display = 'block';
	text_on = value;
}

// FOR THE INDIVIDUAL PROJECTS PAGES
function changeTabProject(value) {
	if (firstrun) {
		//lets the images page load offscreen then hides it
		which_text[1].style.display = 'none';
		which_text[1].className = " backOn";
	}
	firstrun = false;
	if (text_on !== undefined) {
		if (text_on == 0 && qtLoaded) {
			which_text[text_on].className = " offLeft";
			qtOffLeft = true;
		}else{
			which_text[text_on].style.display = 'none';
		}
		which_link[text_on].className = "off";
	}
	if (value == 0 && qtOffLeft) { // if we are coming back to "excerpt" and the QT has already loaded
		which_text[value].className = " backOn";
		qtOffLeft = false;
	}else{ // normal block on and off
		which_text[value].style.display = 'block';
	}
	
	// set qtLoaded to true once "excerpt" is clicked on
	if (value == 0) {qtLoaded = true;}
	
	// turns clicked tab on
	which_link[value].className = " on";
	
	// sets state of what the current tab is
	text_on = value;
}

// FOR THE ABOUT PAGE
function changeTabAbout(value) {
	if (text_on !== undefined) {
		which_text[text_on].style.display = 'none';
		which_link[text_on].className = "off";
	}
	which_text[value].style.display = 'block';
	which_link[value].className = " on";
	text_on = value;
}

// Attach event listeners to the buttons
function findButtons() {
	all_divs = document.getElementsByTagName("div");
	all_links = document.getElementsByTagName("a");
	var cur;
	var t;
	h = 0;
	for (i=0; i<all_divs.length; i++) {
		cur = all_divs[i];
		t = all_divs[i].id;
		if (t.match("text") == "text") {
			which_text[h] = cur;
			h++;
		}
	}
	h = 0;
	for (i=0; i<all_links.length; i++) {
		cur = all_links[i];
		t = all_links[i].id;
		if (t.match("link") == "link") {
			which_link[h] = cur;
			h++;
		}
	}
	which_link[0].onmouseover = function () {rolloverProjects(0);};
	which_link[1].onmouseover = function () {rolloverProjects(1);};
	which_link[2].onmouseover = function () {rolloverProjects(2);};
	which_link[3].onmouseover = function () {rolloverProjects(3);};
	which_link[4].onmouseover = function () {rolloverProjects(4);};
	which_link[5].onmouseover = function () {rolloverProjects(5);}; 
}

function findTabs() {
	all_divs = document.getElementsByTagName("div");
	all_links = document.getElementsByTagName("a");
	var cur;
	var t;
	h = 0; 
	for (i=0; i<all_divs.length; i++) {
		cur = all_divs[i];
		t = all_divs[i].id;
		if (t.match("tab_")) {
			which_text[h] = cur;
			h++;
		}
	}
	h = 0;
	for (i=0; i<all_links.length; i++) {
		cur = all_links[i];
		t = all_links[i].id;
		if (t.match("link_")) {
			which_link[h] = cur;
			h++;
		}
	}
	
	which_link[0].onclick = function () {changeTabProject(0);return false;};
	which_link[1].onclick = function () {changeTabProject(1);return false;};
	which_link[2].onclick = function () {changeTabProject(2);return false;};
}

// Initialize the rollovers/tab effects
window.onload = function() {
	if (document.body.id.match("projects-page")) {
		findButtons();
		rolloverProjects(0);
	}
	if (document.body.id.match("about-page")) {
		findTabs();
		changeTabAbout(0);
	}
	if (document.body.id.match("_page")){
		findTabs();
		changeTabProject(2);
	}
}
