//tutaj ustalasz czas w milisekundach
//var time = 2500;
//tutaj ustalasz identyfikatory pokazywanych zakładek:
//PAMIETAJ ŻE:
// - identyfikatory są dwa: 'tabx-header' oraz 'tabx-header' gdzie x jest identyfikatorem
// - liczby w tej tablicy to identyfikatory zakładek
// - WAŻNA JEST KOLEJNOŚĆ! MUSI BYĆ ZGODNA Z KOLEJNOŚCIĄ ZAKŁADEK W PLIKU HTML!
//var tabs = ['0','1','2'];
//tabs.reverse(tabs);
/*
* Variable 'S' defines the speed of the accordian
* Variable 'T' defines the refresh rate of the accordian
*/
//tutaj ustalasz prędkość rozwijania
ds=7;
//a tutajjest częstotliwość odświeżania - czyli krok
t=10;
//tutaj ustalasz maksymalną wysokość zakładki - jeśli dasz 0 to skrypt będzie automatycznie rozciągał do zawartości zakładki
//var maxHeight=450;

/*
* The Variable names have been compressed to achive a higher level of compression.
*/

function ch(d){
	if(maxHeight == 0)
		return sh(d);
	else
		return maxHeight;
}

// set or get the current display style of the div
function dsp(d,v){
	if(v==undefined){
		return d.style.display;
	}else{
		d.style.display=v;
	}
}

// set or get the height of a div.
function sh(d,v){
	// if you are getting the height then display must be block to return the absolute height
	if(v==undefined){
		if(dsp(d)!='none'&& dsp(d)!=''){
			return d.offsetHeight;
		}
		viz = d.style.visibility;
		d.style.visibility = 'hidden';
		o = dsp(d);
		dsp(d,'block');
		r = parseInt(d.offsetHeight);
		dsp(d,o);
		d.style.visibility = viz;
		return r;
	}else{
		d.style.height=v;
	}
}

//Collapse Timer is triggered as a setInterval to reduce the height of the div exponentially.
function ct(d){
	d = document.getElementById(d);
	if(sh(d)>0){
		v = Math.round(sh(d)/ds);
		//alert(v);
		v = (v<1) ? 1 :v ;
		v = (sh(d)-v);
		sh(d,v+'px');
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
	}else{
		sh(d,0);
		dsp(d,'none');
		clearInterval(d.t);
	}
}

//Expand Timer is triggered as a setInterval to increase the height of the div exponentially.
function et(d){
	d = document.getElementById(d);
	if(sh(d)<d.maxh){
		v = Math.round((d.maxh-sh(d))/ds);
		v = (v<1) ? 1 :v ;
		v = (sh(d)+v);
		sh(d,v+'px');
		d.style.opacity = (v/d.maxh);
		d.style.filter= 'alpha(opacity='+(v*100/d.maxh)+');';
	}else{
		sh(d,d.maxh);
		clearInterval(d.t);
	}
}

// Collapse Initializer
function cl(d){
	if(dsp(d)=='block'){
		clearInterval(d.t);
		d.t=setInterval('ct("'+d.id+'")',t);
	}
}

//Expand Initializer
function ex(d){
	if(dsp(d)=='none'){
		dsp(d,'block');
		d.style.height='0px';
		clearInterval(d.t);
		d.t=setInterval('et("'+d.id+'")',t);
	}
}

// Removes Classname from the given div.
function cc2(n,v){
	s=n.className.split(/\s+/);
	for(p=0;p<s.length;p++){
		if(s[p]==v+n.tc){
			s.splice(p,1);
			n.className=s.join(' ');
			break;
		}
	}
}

function getElements(){
	lo=[];	
	for(i=0,j=0; i<tabs.length; i++){j++;
		x = document.getElementById('tab'+tabs[i]+'-header');
		lo.push(x.id);				
		x.style.display='block';		
		y = document.getElementById('tab'+tabs[i]+'-content');
		lo.push(y.id);
		y.style.display='block';	
	}
	return lo;
}
c = [];
//Accordian Initializer
function Accordian(d,s,tc){
tabs.reverse(tabs);
	// get all the elements that have id as content	
	l=getElements();

	c=[];
	for(i=0;i<l.length;i++){
		h=l[i];
		if(h.substr(h.indexOf('-')+1,h.length)=='content'){c.push(h);}
	}
	sel=null;
	
	//then search through headers
	for(i=0;i<l.length;i++){
		h=l[i];
		if(h.substr(h.indexOf('-')+1,h.length)=='header'){
			d=document.getElementById(h.substr(0,h.indexOf('-'))+'-content');
			d.style.display='none';
			d.style.overflow='hidden';
			d.maxh = ch(d);
			d.s=(s==undefined)? 7 : s;
			h=document.getElementById(h);
			h.tc=tc;
			h.c=c;
			// set the onclick function for each header.
			h.onclick = function(){
				expColl(this);
				clearInterval(d.f);
			}
			if(h.className.match(/selected+/)!=undefined){ sel=h;}
		}
	}
	changeTabs();
	d.f = setInterval('changeTabs()',time);
	if(sel!=undefined){sel.onclick();}
	

}

var startTab = 0;

function changeTabs(){
	startTab = startTab <= 0 ? tabs.length - 1 : startTab - 1;
	//startTab = startTab % tabs.length;
	//alert(startTab);
	h = document.getElementById('tab'+tabs[startTab]+'-header');
	h.c = c;
	expColl(h);
	//startTab++;
}

function expColl(h){
	for(i=0;i<h.c.length;i++){
		cn=h.c[i];
		n=cn.substr(0,cn.indexOf('-'));
		if((n+'-header')==h.id){
			ex(document.getElementById(n+'-content'));
			n=document.getElementById(n+'-header');
			cc2(n,'__');
			n.className=n.className+' '+n.tc;
		}else{
			cl(document.getElementById(n+'-content'));
			cc2(document.getElementById(n+'-header'),'');
		}
	}
}

