/***
 * javascriptova knihovna objektu TSwitcher-browsing
 * VA-Admin
 */

/**
 * pole ID elementu zalozek
 */
TSwitcher.prototype.tabs = new Array();
/**
 * pole ID elementu obsahu zalozek
 */
TSwitcher.prototype.boxes = new Array();

/**
 * definice tridy pro zmenu stylu zalozky
 */
TSwitcher.prototype.classShow;
TSwitcher.prototype.classHide;

/**
 * hodnotu shovani celeho obsahu
 */
TSwitcher.prototype.hide = false;


/**
 * konstruktor objektu TSwitcher
 */
function TSwitcher(initTab, tabsID, boxesID, classShow, classHide){
	this.tabs = tabsID;
	this.boxes = boxesID;
	this.classShow = classShow;
	this.classHide = classHide;

	if (initTab && initTab != ''){
		this.switchTab(initTab);
	}
}


/**
 * metoda objektu pro pridani dalsi zalozky do seznamu
 */
TSwitcher.prototype.addTab = function(tabID, boxID){
	this.tabs[this.tabs.length] = tabID;
	this.boxes[this.boxes.length] = boxID;
}


/**
 * metoda vynuluje skupinu zalozek - aktivuje prvni zalozku v seznamu
 */
TSwitcher.prototype.reset = function(){
	first = false;

	for (i in this.tabs) {
		if (!first && this.displayTab(this.boxes[i], true)){
			document.getElementById(this.tabs[i]).className = this.classShow;
			first = true;

		}else if (this.displayTab(this.boxes[i], false)){
			document.getElementById(this.tabs[i]).className = this.classHide;
		}
	}
}


/**
 * samotna procesni metoda pro prepinani zalozek
 */
TSwitcher.prototype.switchTab = function(tabID){
	for (i in this.tabs) {
		if (this.tabs[i] == tabID) {
			if (this.displayTab(this.boxes[i], true))
				document.getElementById(tabID).className = this.classShow;

		} else {
			if (this.displayTab(this.boxes[i], false))
				document.getElementById(this.tabs[i]).className = this.classHide;
		}
	}
}


/**
 * interni metoda switchTab pro zobrazeni jednotlivych zalozek
 */
TSwitcher.prototype.displayTab = function(divID, show){
	box = document.getElementById(divID);

	if (!box) return false;

	if (show == true || (typeof(show) == 'undefined' && (box.style.display || box.style.display == 'none'))) {
		box.style.visibility = 'visible';
		box.style.display = 'block';

	} else {
		box.style.visibility = 'hidden';
		box.style.display = 'none';
	}

	return true;
}

