function openTab(inTabTd) {

	
	div0 = inTabTd.getElementsByTagName("div")[0];
	div1 = div0.getElementsByTagName("div")[0];
	div2 = div1.getElementsByTagName("div")[0];
	div3 = div2.getElementsByTagName("div")[0];
	tabName = div3.innerHTML;


	// so it doesn't change tabs if it isn't needed
	if(div0.className == "tab0sel") { return; }


	// RESETTING ALL TABS BACK TO NOTHING
	allTds = inTabTd.parentNode.getElementsByTagName("td");
	if(allTds) {
		//alert("allTds: " + allTds);
		for(x = 0; x < allTds.length; x++) {
			thisTd = allTds[x];
			if(thisTd.id != "nochange") {
				//thisTd.className = "galTabDeselected";
				thisDiv0 = thisTd.getElementsByTagName("div")[0];
				thisDiv1 = thisDiv0.getElementsByTagName("div")[0];
				thisDiv2 = thisDiv1.getElementsByTagName("div")[0];
				thisDiv3 = thisDiv2.getElementsByTagName("div")[0];

				thisDiv0.className = "tab0desel";
				thisDiv1.className = "tab1desel";
				thisDiv2.className = "tab2desel";
				thisDiv3.className = "tab3desel";

				thisTdName = thisDiv3.innerHTML;
				thisThumbSet = document.getElementById("thumbs" + thisTdName);
				if(thisThumbSet) {
					thisThumbSet.style.display = "none";
				}
			}
		}
	}


	
	// SETTING NEW TAB STYLE AND MAKING THUMB SET VISIBLE
	//alert("tabName: " + tabName);
	div0.className = "tab0sel";
	div1.className = "tab1sel";
	div2.className = "tab2sel";
	div3.className = "tab3sel";
	thisThumbSet = document.getElementById("thumbs" + tabName);
	if(thisThumbSet) {
		thisThumbSet.style.display = "block";

		// DESELECTING ANYTHING THAT MIGHT ME SELECTED
		allTds = thisThumbSet.getElementsByTagName("td");
		for(x = 0; x < allTds.length; x++) {
			thisTd = allTds[x];
			thisTd.style.backgroundColor = "transparent";
			thisTd.style.cursor = "pointer";
		}
	}

}

function thumbHover(theTd, turnOn) {
	if(!theTd) {return;}
	if(theTd.style.backgroundColor != "#00a515" && theTd.style.backgroundColor != "rgb(0, 165, 21)") {
		//alert("theTd-backcolor:" + theTd.style.backgroundColor + ":");
		if(turnOn) {
			theTd.style.backgroundColor="#53DA00";
		} else {
			theTd.style.backgroundColor="transparent";
		}
	}
}

function thumbSelect(theTd) {
	if(theTd.style.cursor=="default") {return;}

	imgHolder = document.getElementById("folioImage");
	imgPermalink = document.getElementById("folioPermalink");
	descHolder = document.getElementById("folioDescription");
	imgUrl = theTd.getElementsByTagName("div")[0].innerHTML;
	imgDesc = theTd.getElementsByTagName("span")[0].innerHTML;
	imgThumb = theTd.getElementsByTagName("img")[0];

	descHolder.innerHTML = imgDesc;
	imgHolder.style.display="block";
	imgHolder.innerHTML = "<img src='" + imgUrl + "' alt='' />";
	permL = "http://www.ratage.com/folio.php?imageId=" + imgUrl.substr(7, imgUrl.length - 16);
	imgPermalink.innerHTML = "Permalink: <a href='" + permL + "'><b>" + permL + "</b>"; 
	imgPermalink.style.display="block";

	allTds = theTd.parentNode.getElementsByTagName("td");
	for(x = 0; x < allTds.length; x++) {
		thisTd = allTds[x];
		thisTd.style.backgroundColor = "transparent";
		thisTd.style.cursor="pointer";
	}
	theTd.style.backgroundColor="#00A515";
	theTd.style.cursor="default";

	if(document.title) {
		document.title = imgThumb.alt + " in Folio | Ratage.com";
	}
}