Event.observe(window,'load',function(){initTabWidgets()});
function initTabWidgets(){
	$$('dl.STW:not([class~=processed])').each(function(e){initTabWidget(e);});
}
var ontab = '';
var imgsrc = '';
function imgSwap (activeTab) {
	if (activeTab.select('img')[0] != undefined) {
	
	// reset the previous 'over' state
	if (ontab != '' && imgsrc != '') { ontab.select('img')[0].src = imgsrc; }
	
	// swap the image inside the selected dt to the 'over' state
	imgsrc = activeTab.select('img')[0].src;
	imgsrcON = imgsrc.replace(/.gif$/ig,"_over.gif"); // add over state
	activeTab.select('img')[0].src = imgsrcON;
	ontab = activeTab;
	}
}
function initTabWidget(widget){
	widget = $(widget).addClassName('processed');
	var tabs = new Element('div',{'class':'STW_tabsArea'});
	var tabcontents = new Element('div',{'class':'STW_tabContentArea'});
	var clr = new Element('div',{'class':'clear'});
	var arrowBar = new Element('div',{'class':'arrowBar'});
	widget.addClassName('STW_Active');
	widget.insert(tabs).insert(tabcontents);
	
	// Find the tab that is the default 'selected' tab
	widget.select('dt.selected').each(function(e){ 
		imgSwap(e);
	});
	
	//var c = initSpecialBox(tabcontents);
	tabcontents.setStyle({width:'auto'});
	var zcount = 1000; // initialize z-index value
	widget.select('dt').each(function(term){
		var thistab = new Element('div',{'class':'STW_tab'});
		thistab.setStyle({zIndex:zcount});
		zcount = zcount - 10; // drop z-index by ten
		var thiscontent = term.next('dd');
		
		thistab.observe('click',function(){
			widget.select('.selected').each(function(e){e.removeClassName('selected')});
			thistab.addClassName('selected');
			thiscontent.addClassName('selected');
			tabcontents.setStyle({zoom:1,_height:0});
			imgSwap(thistab);
			//moveArrow(tabs);
		});
		if(term.hasClassName('selected')) thistab.addClassName('selected')&&thiscontent.addClassName('selected')&&term.removeClassName('selected');
		tabs.insert(thistab.insert(term));
		tabcontents.insert(thiscontent.addClassName('STW_tabContent'));
	});
	tabs.insert(clr).insert(arrowBar);
}