function TabSet(aname) {
	this.Name = aname;
	this.Tabs = new Array();
	this.TabButtons = new Array();
	this.TabIndex = -1;
	this.ontabchange = null;
	this.ontabchanging = null;

	this.SetVisibility = function(object, visible) {
		if (!object) { return; }
		object.style.visibility = (visible) ? 'visible' : 'hidden';
		object.style.display = (visible) ? 'block' : 'none';
	}


	this.SetTabIndex = function(index) {
		if (index < 0 || index >= this.Tabs.length) {
			return;
		}
		if (index == this.TabIndex) {
			return;
		}
		if (typeof(this.ontabchanging) == "function") {
			if (!this.ontabchanging()) {
				return;
			}
		}
		var tab = this.Tabs[index];
		var tabbutton = this.TabButtons[index];
		if (this.TabIndex > -1) {
			var oldtab = this.Tabs[this.TabIndex];
			var oldtabbutton = this.TabButtons[this.TabIndex];
			oldtabbutton.selected = false;
			oldtabbutton.className = oldtabbutton.classNameNormal;
			this.SetVisibility(oldtab, false);
		}
		tabbutton.selected = true;
		tabbutton.className = tabbutton.classNameSelected;
		this.SetVisibility(tab, true);
		var oldtabindex = this.TabIndex;
		this.TabIndex = index;
		if (oldtabindex != -1) {
			if (typeof(this.ontabchange) == "function") {
				this.ontabchange();
			}
		}
	}

	this.InitButton = function(button, id) {
		button.TabSet = this;
		button.classNameNormal = 'tabbuttonnormal';
		button.classNameOver = 'tabbuttonover';
		button.classNameSelected = 'tabbuttonselected';
		button.style.cursor = 'pointer';
		button.onclick2 = button.onclick;
		button.onclick = function() {
			this.TabSet.SetTabIndex(id);
			if (typeof(this.onclick2) == "function") {
				this.onclick2();
			}
		}
		button.onmouseover2 = button.onmouseover;
		button.onmouseover = function() {
			if (!this.selected) {
				this.className = this.classNameOver;
			}
			if (typeof(this.onmouseover2) == "function") {
				this.onmouseover2();
			}
		}
		button.onmouseout2 = button.onmouseout;
		button.onmouseout = function() {
			this.className = (this.selected) ? this.classNameSelected : this.classNameNormal;
			if (typeof(this.onmouseout2) == "function") {
				this.onmouseout2();
			}
		}
	}


	this.AddTab = function(buttonname,tabname) {
		var button = document.getElementById(buttonname);
		var tab = document.getElementById(tabname);
		if (!button || !tab) {
			alert('Error adding tab');
		} else {
			this.SetVisibility(tab, false);
			var id = this.TabButtons.push(button);
			this.Tabs.push(tab);
			this.InitButton(button, id - 1);
			tab.TabSet = this;
			this.SetTabIndex(0);
		}
	}

	this.SetButtonClass = function(normal, over, selected) {
		for (c = 0; c < this.TabButtons.length; c++ ) {
			var tb = this.TabButtons[c];
			tb.className = (tb.selected) ? selected : normal;
			tb.classNameNormal = normal;
			tb.classNameOver = over;
			tb.classNameSelected = selected;
		}
	}


}