//	Configure tabs

function tabToPanel(tabID) {
	return tabID.replace(/tab/,'pan');
}

function initPanels() {
	//	Get panels and hide all but the first one
	var panels = $("panels").immediateDescendants();
//	alert(panels);
	panels.each(function(s) { $(s).hide(); });
	$(panels[0]).show();
}

function initTabs() {
	//	Get tabs and add triggers
	var tabs = $("tabs").getElementsBySelector("a");
//	tabs.each(function(s) { $(s).onclick = function(s) {tabToggle(s); return false;}});
	tabs.each(function(s) { Event.observe(s,'click',function(s){clickTab(s);}) });
	tabs[0].addClassName("current");
	
	tab = window.location.hash.substr(1);
	//alert (tab);
	if (tab) {
		toggleTab(tab);
		$$('html')[0].scrollTo();
	}
}

function initPanels4() {
	//	Get panels and hide all but the first one
	var panels = $("panels").immediateDescendants();
//	alert(panels);
	panels.each(function(s) { $(s).hide(); });
	$(panels[4]).show();
}

function initTabs4() {
	//	Get tabs and add triggers
	var tabs = $("tabs").getElementsBySelector("a");
//	tabs.each(function(s) { $(s).onclick = function(s) {tabToggle(s); return false;}});
	tabs.each(function(s) { Event.observe(s,'click',function(s){clickTab(s);}) });
	tabs[4].addClassName("current");
	
	tab = window.location.hash.substr(1);
	//alert (tab);
	if (tab) {
		toggleTab(tab);
		$$('html')[0].scrollTo();
	}
}

function clickTab(e) {
	//alert(e);
	var t = $(Event.element(e)).up().id;
	toggleTab(t);
	Event.stop(e);
}

function clickTabOld(e) {
	//alert(e);
	var t = $($(Event.element(e)).up().id);
	//alert(t.id);
	var p = $(tabToPanel(Event.element(e).up().id));
	//alert(p.id);
	var panels = $("panels").immediateDescendants();
	$(t).up().siblings().each(function(n) {$(n).down().removeClassName("current")});
	panels.each(function(n) { $(n).hide(); });
	if (!$(t).hasClassName("current")) { $(t).addClassName("current"); }
	p.show();
	Event.stop(e);
}

function toggleTab(tab) {
	t = $(tab);
	p = $(tabToPanel(tab));
	var panels = $("panels").immediateDescendants();
	$(t).up().siblings().each(function(n) {$(n).down().removeClassName("current")});
	panels.each(function(n) { $(n).hide(); });
	if (!$(t).hasClassName("current")) { $(t).addClassName("current"); }
	p.show();
}