// JavaScript Document
var idTabSelected = new String();

function setMouseOverColor() {
	this.style.backgroundColor = "#33FFFF";
}
function setMouseOutColor() { // simulate CSS hover state
	if (this.id == idTabSelected) {
		this.style.backgroundColor = "#339999";
	} else {
		this.style.backgroundColor = "#66CCCC";
	}
}
function setMouseDownColor() { // simulate CSS active state
	if (this.id != idTabSelected) {
		this.style.backgroundColor = "#339999";
	}
}

function InitIslandBlocks() {
	// set default div.display attribute
	var allDivs = document.getElementsByTagName("div");
	var blockFound = false;
	for (var i=0; i<allDivs.length; i++) {
		if (allDivs[i].id.match("TabContent")) {
			if (allDivs[i].id == "OahuTabContent") {
				allDivs[i].style.display = "block";
			} else {
				allDivs[i].style.display = "none";
			}
			blockFound = true;
		}
	}
	if (!blockFound) {
		document.getElementById("IslandMenuBarBorder").style.display = "none";
		return false;
	}
	// assign mouse actions to tabs
	var allTabs = document.getElementsByTagName("a");  
	for (var i=0; i<allTabs.length; i++) {
		if (allTabs[i].id.match("Tab")) {
			allTabs[i].onclick = DisplayIslandBlock;
			allTabs[i].onmouseover = setMouseOverColor;
			allTabs[i].onmouseout = setMouseOutColor;
			allTabs[i].onmousedown = setMouseDownColor;
		}
	}

	document.getElementById("OahuTab").style.backgroundColor = "#339999";
	idTabSelected = "OahuTab";
}

function DisplayIslandBlock() {
	// display selected block and hide all other blocks
	var allDivs = document.getElementsByTagName("div");
	var blockFound = false;
	for (var i=0; i<allDivs.length; i++) {
		if (allDivs[i].id.match("TabContent")) {
			if (allDivs[i].id.match(this.id)) { // match island name of tab label to block label
				allDivs[i].style.display = "block";
			} else {
				allDivs[i].style.display = "none";
			}
			blockFound = true;
		}
	}
	if (!blockFound) {
		history.back();
		return false;
	}
	// set color of selected tab and reset all other tabs
	var allTabs = document.getElementsByTagName("a");  
	for (var i=0; i<allTabs.length; i++) {
		if (allTabs[i].id.match("Tab")) {
			if (allTabs[i].id == this.id) {
				allTabs[i].style.backgroundColor = "#339999";
				// alert(document.getElementById("OahuTab").className);
			} else {
				allTabs[i].style.backgroundColor = "#66CCCC";
			}
		}
	}
	
	idTabSelected = this.id;
	return false;
}

addOnload(InitIslandBlocks);
