function getObj(name) //by P.P.Koch
{
  if (document.getElementById)
  {
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all)
  {
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers)
  {
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
}
function zrob_losowy_link(p_tekst,p_odstep) {
if (p_odstep==0)
  document.write('<a href="javascript:skocz_losowo_ramka()">'+p_tekst+'</a>');
if (p_odstep==1)
  document.write('|&nbsp;<a href="javascript:skocz_losowo_ramka()">'+p_tekst+'</a>');
if (p_odstep==2)  
  document.write('&nbsp;|&nbsp;&nbsp;<a href="javascript:skocz_losowo_ramka()">'+p_tekst+'</a>');
}

var MAXT = 37;
var curr_t=0;

function skocz_losowo_ramka(spec) {
var rand=Math.round(Math.random()*MAXT)+1;
przeskocz(rand);
}

function przeskocz(nowy) {
        if (nowy<0 || nowy>MAXT) return false;
        var str_stary = 't' + curr_t;
        var str_nowy = 't' + nowy;
        var div_stary = new getObj(str_stary);
        var div_nowy = new getObj(str_nowy);
        if (!div_stary || !div_nowy) return false;
        div_stary.style.display = 'none';
        div_nowy.style.display = 'block';
        var a_poprz = new getObj('poprz');
        var a_nast = new getObj('nast');
        a_poprz.style.color = nowy==0 ? '#888' : '#fff';
        a_nast.style.color = nowy==MAXT ? '#888' : '#fff';
        curr_t = nowy;
        return true;
}        

function rob_klik(ident) {
        if (!ident) return true;
	if (ident=='nast') return przeskocz(curr_t*1+1);
	if (ident=='poprz') return przeskocz(curr_t*1-1);
	if (ident=='pocz') return przeskocz(0);
	if (ident=='spistr') return przeskocz(37);
	if (ident=='domek') return true;
	return przeskocz(ident.substr(1));
}

function kliknij(e) {
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	if (targ.nodeType == 3) // defeat Safari bug
		targ = targ.parentNode;
	var dokad = targ.href.split('#')[1];
	if (dokad) return rob_klik(dokad)
	else return rob_klik(targ.id);
}

function klawisz(e) {
  var evtobj=window.event? event : e
  var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode;
  if (unicode!=37 && unicode!=39) return;
  if (unicode==37) return przeskocz(curr_t*1-1);
  if (unicode==39) return przeskocz(curr_t*1+1);

}        

function centruj_ramke() {
var winh;
if (window.innerHeight) { winh = window.innerHeight }
else if (document.documentElement&&document.documentElement.clientHeight) {
  winh = document.documentElement.clientHeight
  }
else return;
//alert(winh);
var conth = 462;
margh = Math.round((winh-conth)/2)-15;
//alert(margh);
var rmk = new getObj('ramka');
rmk.style.marginTop = margh>50? margh+'px' : '50px';
//alert(rmk.style.marginTop);
}

window.onload = function() {
var divs = document.getElementsByTagName('div');
var ii, div, link;
for (ii=0; (div=divs[ii]); ii++)
  if (div.className == 'toggle') div.style.display = 'none';
for (ii=0; (link=document.links[ii]); ii++) link.onclick = kliknij;
document.onkeydown = klawisz;
//window.onresize = centruj_ramke;
//centruj_ramke();
przeskocz(0);
}
