TabbedItems = function() {
	this.sections = new Array;
	var sections = getElementsByClassName("tabbed-section", document);
	if (sections.length == 0) return;
	for (var i = 0; i < sections.length; i++) {
		this.sections[this.sections.length] = new TabbedSection(sections[i],"ts" + i);
	}
	tickle();
}
TabbedItems.prototype.destroy = function() {
	for (var i = 0; i < this.sections.length; i++) {
		for (var j = 0; j < this.sections[i].tabs.childNodes; j++) {
			var u = this.sections[i].tabs.childNodes[j];
			u.number = u.onclick = null;
		}
	}
}
TabbedSection = function(obj, id) {
	// gather children and construct the menu
	this.items = getElementsByClassName("tabbed-item", obj);
	this.headers = getElementsByClassName("tabbed-header", obj);
	// create tabbed menu
	this.tabs = document.createElement("ul");
	this.tabs.className = "tabs";
	for (var i = 0; i < this.headers.length; i++) {
		var tab = document.createElement("li");
		var self = this;
		tab.number = i;
		if(this.headers[i].title) var label = this.headers[i].title
		else var label = this.headers[i].innerHTML;
		tab.innerHTML = "<a href=\"#\">" + label + "</a>";
		tab.onclick = function() { 
			self.resetAll(this.number);
			return false;
		}
		this.tabs.appendChild(tab);
	}
	this.tabs.childNodes[0].className = "first";
	obj.insertBefore(this.tabs,this.items[0]);
	// set defaults
	this.resetAll(0);
}
TabbedSection.prototype.resetAll = function(exception) {
	for (var i = 0; i < this.items.length; i++) {
		if (i != exception) {
			removeClass(this.items[i], "current");
			removeClass(this.tabs.childNodes[i], "current");
		} else {
			addClass(this.items[i], "current");
			addClass(this.tabs.childNodes[i], "current");
		}
	}
	tickle();
}
