function keskkoht(){
  if (self.innerHeight)
    x = Math.round(self.innerWidth / 2) - 10;
  else if (document.body)
    x = Math.floor(document.body.clientWidth / 2);
  return x;
}
laaditud = false;
function toonita(nr, kood){
  if(!kood)
    document.images[nr + 10].style.visibility = 'visible';
  else if(laaditud)
    document.images[nr + 10].style.visibility = 'hidden';
}
var kehtivusaeg = new Date();
var aktiivne = -1;
function sisukord(nr){
  if(document.getElementById){
    toonita(nr, true);
    objekt = document.getElementById('sisukord');
    uuenda(15000);
    if(aktiivne != nr){
      if(aktiivne != -1)
        toonita(aktiivne, false);
      aktiivne = nr;
      sulanda(nr, true, 0);
      vaatleja(nr);
    }
    objekt.style.visibility='visible';
    objekt.innerHTML = '';
    for(i=0; i<elemendid[nr].length; i++)
      objekt.innerHTML += '<a href="'+nr+','+i+'" onmouseover="uuenda(15000)" onmouseout="uuenda(500)">' + elemendid[nr][i] + '</a>';
    objekt.style.left = keskkoht() - 515 + xid[nr];
  }
}
function uuenda(palju){
  hetkel = new Date();
  kehtivusaeg.setTime(hetkel.getTime() + palju);
}
function vaatleja(nr){
  hetkel = new Date();
  if(kehtivusaeg < hetkel){
    sulanda(nr, false, 72);
    toonita(nr, false);
  }
  else if(aktiivne == nr)
    setTimeout('vaatleja('+nr+')', 200);
}
function sulanda(nr, kood, protsent){
  if(nr == aktiivne){
    protsent = kood ? protsent + 18 : protsent - 9;
    if(kood){
      k6rgus = Math.round(objekt.offsetHeight / 4 * (protsent / 18));
      objekt.style.clip = 'rect(auto, auto, '+k6rgus+'px, auto)';
    }
    if(typeof objekt.filters != 'undefined')
      objekt.filters.alpha.opacity = protsent;
    else if (typeof objekt.style.opacity != 'undefined')
      objekt.style.opacity = protsent/100;
    if(protsent == 0){
      objekt.style.visibility='hidden';
      aktiivne = -1;
    }
    if(protsent != 0 && protsent != 72)
      setTimeout('sulanda('+nr+', '+(kood ? 'true' : 'false')+', '+protsent+')', 50);
  }
}
function logo(){
  if(document.getElementById){
    x = keskkoht() + 132;
    if(x < 525)
      x = 525;
    document.getElementById('logo').style.left = x +'px';
    document.getElementById('logo').style.visibility = 'visible';
  }
}
ujukPinnal = false;
ujukAeg = new Date();
ujukIntervall = null;
function pinnaletous(protsent){
  if(typeof ujukObjekt.filters != 'undefined')
    ujukObjekt.filters.alpha.opacity = (protsent == 0 ? 1 : protsent);
  else if (typeof ujukObjekt.style.opacity != 'undefined')
    ujukObjekt.style.opacity = (protsent/100 == 1 ? 0.99 : protsent/100);
  if(protsent < 100){
    protsent += 5;
    setTimeout('pinnaletous('+protsent+')', (protsent == 5 ? 1000 : 50));
  }
  else
    ujukPinnal=true;
}
pildid = new Array();
for(i = 0; i < 6; i++){
  pildid[i] = new Image();
  pildid[i].src = 'pildid/rida2veerg2' + (String.fromCharCode(97 + i)) + '_.png';
}

window.onresize = function(){
  logo();
  aeg=new Date();
  ujukAeg.setTime(aeg.getTime());
  ujuk(false);
}
window.onscroll = new Function('aeg=new Date(); ujukAeg.setTime(aeg.getTime()); ujuk(false)');
window.onload = function(){
  setTimeout('ujuk(true)', 500);
  for(i = 0; i < 6; i++){
    if(document.getElementById){
      document.getElementById('rida2veerg2' + (String.fromCharCode(97 + i))).style.backgroundImage = 'url(\''+pildid[i].src+'\')';
    }
  }
  laaditud = true;
}
function ujuk(kood){
  if(document.getElementById){
    ujukObjekt = document.getElementById('ujuk');
    aeg = new Date();
    if(!kood && ujukPinnal){
      //ujukObjekt.style.visibility = 'hidden';
      if(typeof ujukObjekt.filters != 'undefined')
        ujukObjekt.filters.alpha.opacity = 1;
      else if (typeof ujukObjekt.style.opacity != 'undefined')
        ujukObjekt.style.opacity = 0;
      ujukPinnal = false;
      ujukIntervall = setInterval('ujuk(true)', 334);
    }
    else if(kood && !ujukPinnal && (aeg.getTime() - ujukAeg.getTime() > 1000 || ujukIntervall == null)){
      aknakorgus = self.innerHeight ? self.innerHeight : document.body.clientHeight;
      positsioon = self.pageYOffset ? self.pageYOffset : document.body.scrollTop;
      lehepikkus = document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight;
      aluminepiir = lehepikkus - 110 - 122 + (keel == 'en' ? 43 : 0);
      y = positsioon + aknakorgus - 127 + (keel == 'en' ? 43 : 0);
      if(y < 409)
        y = 409;
      else if(y > aluminepiir)
        y = aluminepiir;
      if(ujukIntervall != null)
        clearInterval(ujukIntervall);
      pinnaletous(0);
      //ujukObjekt.style.visibility = 'visible';
      ujukObjekt.style.top = y + 'px';
      ujukObjekt.style.left = ordinaat(y) + 'px';
    }
  }
}
function ordinaat(y){
  y -= 409;
  if(y <= 105)
    x = keskkoht() + 188 - (0.07619 * y);
  else
    x = keskkoht() + 180;
  if(x < 575)
    x = 575;
  return x + (keel == 'en' ? 3 : 0);
}

