var TabControl = function(){
	this.headNodes = [];
	this.bodyNodes = [];
}

TabControl.prototype.addTab = function(headNode, bodyNode){
	var instance = this;
	headNode.key = this.headNodes.length;
	headNode.onclick = function(){
		instance.setCurrent(this.key);
	}
	this.headNodes[this.headNodes.length] = headNode;
	this.bodyNodes[this.bodyNodes.length] = bodyNode;
}

TabControl.prototype.setCurrent = function(k){
	for (var i = 0; i < this.headNodes.length; i ++){
		i == k ? this.addClass(this.headNodes[i], 'current') : this.removeClass(this.headNodes[i], 'current');
		this.bodyNodes[i].style.display = i == k ? 'block' : 'none';
	}
}

TabControl.prototype.addClass = function(node, className){
	var classNames = node.className.split(' ');
	classNames[classNames.length] = className;
	node.className = classNames.join(' ');
}

TabControl.prototype.removeClass = function(node, className){
	var newNames = [];
	var classNames = node.className.split(' ');
	for (var i = 0; i < classNames.length; i ++){
		if (classNames[i] != className){
			newNames[newNames.length] = classNames[i];
		}
	}
	node.className = newNames.join(' ');
}
