Tabber.prototype.build = Tabber_build;
Tabber.prototype.buildTabs = Tabber_buildTabs;
Tabber.prototype.getTabTitle = Tabber_getTabTitle;
Tabber.prototype.hideAllButOne = Tabber_hideAllButOne;
Tabber.prototype.selectTab = Tabber_selectTab;
Tabber.prototype.appendNextButtons = Tabber_appendNextButtons;
Tabber.prototype.nextTab = Tabber_nextTab;
Tabber.prototype.styleIt = Tabber_giveItSomeStyle;
Tabber.prototype.destroy = Tabber_destroy;
var TabberScope;
function Tabber() {
	this.borderStyle = "1px white solid"; //   <-------------- This controls the style of the border around each tab.
	this.anchorPattern = /#\w+$/;
	TabberScope = this;
	this.rootNode;
	this.rootNodeID;
	this.childType;
	this.viewToggle;
	this.childNodes;
	this.firstChild;
	this.tabs;
	this.tabsArray = new Array();
	this.selectedTab = 1;
	this.labels = new Array();
	this.legendBackups = new Array();
}
function Tabber_build(rootNodeID, childType, viewToggle) { // viewToggle = <A> tag; with src = "#";
	this.rootNode = typeof (rootNodeID) == "string" ? $(rootNodeID) : rootNodeID;
	this.childType = childType;
	this.viewToggle = viewToggle;
	this.rootNodeID = rootNodeID;
	this.childNodes = $_t(this.rootNode, childType);
	if(this.childNodes.length > 1){
		this.firstChild = this.childNodes[0];
		this.buildTabs();
		var urlMatch = window.location.href.match(this.anchorPattern);
		this.hideAllButOne(urlMatch ? getIndex(this.labels, urlMatch[0].split("#").join("")) : 0);
		/*this.appendNextButtons();
		viewToggle.innerHTML = (showAllLabel=="")?"Show All":showAllLabel;
		viewToggle.onclick = function() {
			TabberScope.destroy();
		}*/
		//this.collapseChildern(this.childNodes);
	} else {
		//viewToggle.style.visibility = "hidden";
	}
}
function Tabber_buildTabs() {
	this.tabs = $c("UL");
	this.tabs.setAttribute("id", "tabber_header");
	this.tabs.style.width = this.firstChild.offsetWidth+"px";
	for(var z = 0; z<this.childNodes.length; ++z) {
		this.childNodes[z].style.clear = "left";
		var tab = $c("LI");
		tab.setAttribute("id", "TABBER_tab"+z);
		tab.innerHTML = this.getTabTitle(this.childNodes[z]);
		tab.style.width = (98/this.childNodes.length)+"%";
		if(z == 0) {
			tab.style.borderLeft = this.borderStyle;
			tab.style.borderTop = this.borderStyle;
			tab.style.borderRight = this.borderStyle;
		} else {
			tab.style.borderTop = this.borderStyle;
			tab.style.borderRight = this.borderStyle;
		}
		tab["scope"] = this;
		tab.onclick = this.selectTab;
		this.tabs.appendChild(tab);
		this.tabsArray.push(tab);
	}
	this.rootNode.insertBefore(this.tabs, this.firstChild);
}
function Tabber_appendNextButtons() {
	for(var z = 0; z<this.childNodes.length-1; ++z) {
		var cur = this.childNodes[z];
		var button = $c("INPUT");
		button.setAttribute("type", "button");
		button.setAttribute("id", "nextbutton"+z);
		button.setAttribute("value", (nextLabel==undefined || nextLabel=="")?"Next >>":nextLabel);
		button.style.cssFloat = "right";
		button.style.styleFloat = "right";
		button.style.marginRight = "10px";
		button["scope"] = this;
		button.onclick = this.nextTab;
		cur.appendChild(button);
	}
}
function Tabber_nextTab(e) {
	if(!e) { e = window.event, e.target = e.srcElement; }
	e.target.scope.hideAllButOne(Number(e.target.id.split("nextbutton").join(""))+1);
}
function Tabber_hideAllButOne(which) {
	for(var z = 0; z<this.childNodes.length; ++z) {
		if(z == which) {
			this.tabsArray[z].className = "here";
			this.childNodes[z].style.display = "block";
			//this.childNodes[z].style.visibility = "visible";
			this.childNodes[z].style.height="auto";
			this.childNodes[z].overflow="visible";
		} else {
			this.tabsArray[z].className = "";
			this.childNodes[z].style.display = "none";
			//this.childNodes[z].style.visibility = "hidden";
			this.childNodes[z].style.height="0px";
			this.childNodes[z].style.padding="0px";
			this.childNodes[z].style.overflow="hidden";
		}
	}
}
function Tabber_selectTab(e) {
	if(!e) { e = window.event, e.target = e.srcElement; }
	var n = Number(e.target.id.split("TABBER_tab").join(""))
	//window.location = window.location.toString().replace(this.scope.anchorPattern, "");
	//window.location += "#selectedTab"+n;
	this.scope.hideAllButOne(n);
}
function Tabber_getTabTitle(from) {
	var els = $_t(from, "*");
	var target;
	for(var z = 0; z<els.length; ++z) {
		if(els[z].className.indexOf("TABBERTITLE") != -1) {
			this.legendBackups.push(els[z]);
			var toR = els[z].innerHTML;
			this.labels.push(toR);
			from.removeChild(els[z]);
			return toR;
		}
	}
	return
}
function Tabber_giveItSomeStyle(cssClass) {
	this.tabs.setAttribute("class", cssClass);
}
//
function Tabber_destroy() {
	this.rootNode.removeChild(this.tabs);
	//this.selectedTab = 1;
	for(var z = 0; z<this.childNodes.length; ++z) {
		var cur = this.childNodes[z];
		if(z != this.childNodes.length-1) {
			cur.removeChild($("nextbutton"+z));
		}
		cur.insertBefore(this.legendBackups[z], cur.firstChild);
		cur.style.visibility = "visible";
		cur.style.display = "block";
	}
	this.viewToggle.innerHTML = (viewAsTabsLabel=="")?"View as tabs":viewAsTabsLabel;
	this.viewToggle.onclick = function() {
		TabberScope.tabsArray = new Array();
		TabberScope.build(TabberScope.rootNodeID, TabberScope.childType, this);
	}
}