/**********************************************************************
 * Tab Switch Javascript
 * Created by Chris Rock
 * This script was created to be an easy way to add tabs to a web page
 * 
 * Sample HTML Markup:
 *********************************************************************
 * <div id="tabmenu"></div>    **** Be sure to add this empty div!****
 * 	<div class="tab_1">
 * 		<h2 class="tab_label">First Tab</h2>
 * 		<p>First Tab content goes here</p>
 * 	</div>
 * 	<div class="tab_2">
 * 		<h2 class="tab_label">First Tab</h2>
 * 	<p>Second Tab content goes here</p>
 * </div>
 ********************************************************************
 * With this markup, the script will create an unordered list
 * and put it into the "tabmenu" div, with the labels specified by
 * the "tab_label" class.  It hides the labels so that they're only
 * seen in the list. You can then style the list to look like tabs.
 *
 * If Javascript is disabled, the user will see all the content
 * separated by the "tag_label" headings.
 ********************************************************************/
window.onload = tabInit;
 
function tabInit() {
	var tabs = getElementsByClassName('tab_label');
	var tabmenuHTML = "<div class=\"clear\"></div><ul>\n";
	for (var i=0; i<tabs.length; i++) {
		tabmenuHTML += "<li><a href=\"javascript: void(null);\" onclick=\"tabSwitch(" +
			(i + 1) + ");\">" + tabs[i].firstChild.nodeValue + 
			"</a></li>\n";
		tabs[i].style.display = "none";
	}
	tabmenuHTML += "</ul>\n";
	tabmenuHTML += "<div class=\"clear\"></div>";
	document.getElementById('tabmenu').innerHTML = tabmenuHTML;
	tabSwitch(1);
}

function tabSwitch(tabNum) {
	hideAll();
	var tabClass = 'tab_' + tabNum;
	var showTab = getElementsByClassName(tabClass);		
	showTab[0].style.display = "block";
	var tabs = document.getElementById('tabmenu').getElementsByTagName('a');
	for (var i=0; i<tabs.length; i++) {
		tabs[i].className = "";
	}
	tabs[tabNum-1].className = "selected";
	return false;
}	

function hideAll() {
	var i=1;
	var hideTab;
	while(getElementsByClassName('tab_'+i) != "") {
			hideTab = getElementsByClassName('tab_'+i);
			hideTab[0].style.display = "none";
			i++;
	}
}

function getElementsByClassName(name) {
	var elements = document.body.getElementsByTagName('*');
	var foundElements = new Array();
	for (var i=0; i< elements.length; i++) {
		if(elements[i].className == name) {
			foundElements.push(elements[i]);
		}
	}
	return foundElements;
}
