/*
*	Tomáš Králík Copyright © 2010 
*/

function tabset(defPageId, placeHolderId, tabsNotClickable) {
	
	var thisObj = this;
	
	this.tabs = new Object();
	var defaultPage = defPageId;
	
	this.placeHolder = document.getElementById(placeHolderId);
	var placeHolderRemoved = false;
	
	this.onChange = function (id) {};
	this.activeTab = defPageId;
	
	
	this.register = function (id, pageId, buttonId, activeClass, inactiveClass) {
		
		
		this.tabs[id] = new Object();
		this.tabs[id].button = document.getElementById(buttonId);
		this.tabs[id].page = document.getElementById(pageId);
		this.tabs[id].activeClass = activeClass;
		this.tabs[id].inactiveClass = inactiveClass;
		
		if (id == defaultPage) {
			this.activate(id, true);
		}
		
		
		if (!tabsNotClickable) {
			addEvent('click', function () { thisObj.activate(id); } ,this.tabs[id].button);
		}
		
		
		
	}
	
	this.activate = function (id, init) {
		
		if (!init) {
			
			var x;
			for (x in this.tabs) {
				this.tabs[x].page.style.display = 'none';
				this.tabs[x].button.className = this.tabs[x].inactiveClass;
			}
			
		}
		
		if (!placeHolderRemoved) {
			if (this.placeHolder) {
				this.placeHolder.style.display = 'none';
			}
			placeHolderRemoved = true;
		}
		
		this.tabs[id].page.style.display = 'block';
		this.tabs[id].button.className = this.tabs[id].activeClass;
		
		this.onChange(id);
		
		this.activeTab = id;
		
	}
	
	
}

