// Main tab constructor
function sTab_tab(id,bId,par,a) {
	a = (a === undefined)?false:true;
	this.id = id;
	this.bId = bId;
	this.obj = document.getElementById(id);
	this.button = document.getElementById(bId);
	if (!this.obj && a) { alert('Object with ID \''+id+'\' does not exist.'); return false; }
	if (!this.button && a) { 
		alert('Object with ID \''+bId+'\' does not exist.'); return false;
	} else if (this.button) {
		this.button.onmousedown = function() { par.show_tab(par.tabs[this.id].id); return false; }
		this.button.onclick = function() { return false; }
	}
}

sTab_tab.prototype.toggle = function(s) {
	if (!this.obj) { return null; }
	if (typeof(s)!='undefined') {
		var reg = /[^a-zA-Z0-9_]*on[^a-zA-Z0-9_]*/;
		if (s && !this.button.className.match(reg)) { this.button.className += ' on'; } else if (!s) { this.button.className = this.button.className.replace(reg,''); }
		this.obj.style.display=(s)?'block':'none';
	} else { this.obj.style.display=(this.obj.style.display=='none')?'block':'none'; }
}

function sTab(ids) {
	var id_arr = ids.split(',');
	this.tabs = new Object;
	this.buttons = new Object;
	for (var id in id_arr) {
		var s=id_arr[id].split(':');
		if (!this.first) { this.first = s[1]; }
		this.tabs[s[0]] = new sTab_tab(s[1],s[0],this);
	}
	this.show_tab = function(id) {
		for (var tab in this.tabs) { this.tabs[tab].toggle(this.tabs[tab].id==id); }
	}
}


var sTabs = new sTab('b_overview:overview,b_catalogs:catalogs,b_manuals:manuals,b_specs:specs,b_green:green,b_otherinfo:otherinfo,b_submittals:submittals,b_videos:videos,b_cut_sheets:cut_sheets');
sTabs.show_tab(sTabs.first);
