/**
 * tab-box.js
 */

var tabs = ['features', 'datasheet', 'specs'];

function hideTab(id){
	var tab = document.getElementById(id);
	tab.className = '';
}

function showTab(id, scroll){
	// scroll will default to true
	if(typeof scroll == 'undefined')
		scroll = true;

	// hide other tabs
	for(var i = 0; i < tabs.length; i++){
		if(id != tabs[i]) hideTab(tabs[i]);
	}

	// show selected tab
	var tab = document.getElementById(id);
	tab.className = 'target';

	if(scroll)
		tab.scrollIntoView();
}

function initTabs(){
	// set up onclick events
	for(var i = 0; i < tabs.length; i++){
		var tabId = tabs[i];
	//	eval("document.getElementById(tabs[i] + '-link').onclick = function(){showTab('" + tabs[i] + "', true); return false;}");
		document.getElementById(tabs[i] + '-link').onclick = function(){showTab(this.parentNode.id, true); return false;};
	}

	var id = tabs[0];
	if(location.hash != ''){
		id = location.hash.substr(1);  // remove the # from the beginning of the string
	}

	// should make sure the id is a tab that exists on the page first
	showTab(id, false);
}

addLoadEvent(initTabs);
/*
addLoadEvent(function(){
	var id = 'features';
	if(location.hash != ''){
		id = location.hash.substr(1);  // remove the # from the beginning of the string
	}
	showTab(id, false);
});*/
/*
function showTab(id){
	// removes the classname that gets added onload
	var tab = document.getElementById('features');
	tab.className = '';
}

addLoadEvent(function(){
	var tab = document.getElementById('features');
	if(location.hash == ''){
		tab.className = 'target';
	}else{
		tab.className = '';
	}
});
*/