// ***********************************************
// *              tabSwitcher class              *
// ***********************************************

// constructor ... sets nextTab in zero
function tabSwitcher(_maxTabs){
	this.nextTab = 0;
	this.maxTabs = _maxTabs - 1;
	this.miliSec = 1000;
}

tabSwitcher.prototype.nextTab;   // shows nextTab
tabSwitcher.prototype.maxTabs;   // maximum number of tabs
tabSwitcher.prototype.hInterval; // interval handle
tabSwitcher.prototype.miliSec;   // interval length in [ms]

// set interval length
tabSwitcher.prototype.setIntLength = function (_length)
{
	if (_length > 0) this.miliSec = _length;
}

// set nexTab by tab No
tabSwitcher.prototype.setNextTab = function (No)
{
	// check for No overflow
	if (No > this.maxTabs) No = 0;
	this.nextTab = No;
}

// switch to nextTab
tabSwitcher.prototype.switchTab = function ()
{
	setTab(this.nextTab);              // set nextTab
	this.setNextTab(this.nextTab + 1)  // increment nextTab
}
// ***********************************************

// create new tabSwitcher for 3 tabs
// with 2 ms tab switching speed
var ts = new tabSwitcher(3);
    ts.setIntLength(2000);

// set main tab switch interval
function intervalsat() {
	setTab(0);
	ts.hInterval = setInterval("ts.switchTab();", ts.miliSec);
}

// sets onClick events for all tabs
function onclickpromjenaivan()
{
	var currentTab, i = 0; // currentTab ... current instance, i ... tab counter
	
	// add onclick function for all tabs
	while (currentTab = document.getElementById('left').getElementsByTagName ('div') [i]) 
	{
		if (currentTab.className == 'on' || currentTab.className == 'off') 
			currentTab.onclick = onClick(i);
		
		i++;
	}
}

function onClick(_i)
{
	return	function()
			{
				if(typeof ts.hInterval != 'undefined')
				{
					clearInterval(ts.hInterval); // stop switching
					setTab(_i);					 // set selected tab
					
					ts.setNextTab(_i + 1);		 // set next tab and start switching
					ts.hInterval = setInterval("ts.switchTab();", ts.miliSec)
				}
			}
}

function setTab(num)
{
	// get selected tab by No
	var selectedTab = document.getElementById('left').getElementsByTagName('div')[num];
	
	// if selected tab could be turned on/off
	if (selectedTab.className == 'on' || selectedTab.className == 'off') 
		showTab(selectedTab);
}

// show specified tab instance
function showTab(tab)
{
  //return;
	// get all tabs
	var allTabs = document.getElementsByTagName('div');
		
	// for all tabs
	for (var currentTab = 0; currentTab < allTabs.length; currentTab++) 
	{
		// set hide and off property
		allTabs[currentTab].className = allTabs[currentTab].className.replace('show', 'hide');
		allTabs[currentTab].className = allTabs[currentTab].className.replace('on'  , 'off');
	}

	// for selected tab set show and on property
	document.getElementById(tab.getAttribute('title')).className = 'show';
	tab.className = 'on';
}

