function zobraz_nahlad(obrazok,vsetky_obrazky){
  posun_nahlad();
  document.getElementById('nahlad').style.display = 'block';
  document.getElementById('filter').style.display = 'block';
  if(vsetky_obrazky)
    ajaxReload("nahlady.php?img="+obrazok+"&slideshow=1&vsetky_obrazky="+vsetky_obrazky,"nahlad");
  else
    ajaxReload("nahlady.php?img="+obrazok+"&slideshow=0","nahlad");
}

function schovat_nahlad(){
  document.getElementById('nahlad').style.display = 'none';
  document.getElementById('nahlad').innerHTML = '';
  document.getElementById('filter').style.display = 'none';
}

function iny_obrazok(obrazok,vsetky_obrazky){
  document.getElementById("nahlad_img").style.visibility='hidden';
  ajaxReload("nahlady.php?img="+obrazok+"&slideshow=1&vsetky_obrazky="+vsetky_obrazky,"nahlad");  
}

function nahlad_tlacitko(e){
  if(document.getElementById('nahlad').style.display == "block"){
    var tlacitko = e.keyCode;
    var vsetky_obrazky = "";
    if(document.getElementById('vsetky_obrazky') != null)
      vsetky_obrazky = document.getElementById('vsetky_obrazky').value;
    if(tlacitko == '27'){
      schovat_nahlad();
      return true;
    }
    else if(tlacitko == '37'){
      if((document.getElementById('predosla_fotka') != null) && (obrazok = document.getElementById('predosla_fotka').value))
        iny_obrazok(obrazok,vsetky_obrazky);
    }
    else if(tlacitko == '39'){
      if((document.getElementById('dalsia_fotka') != null) && (obrazok = document.getElementById('dalsia_fotka').value))
        iny_obrazok(obrazok,vsetky_obrazky);
    }
    return true;
  }
  return false;
}

function posun_nahlad(){
  //vyska odscrollovanej casti stranky
  if(typeof(window.pageYOffset) == 'number')
      posunutie = window.pageYOffset;
  else{
    if(document.body && (document.body.scrollTop))
      posunutie = document.body.scrollTop;
    else{
      if(document.documentElement && (document.documentElement.scrollTop) )
        posunutie = document.documentElement.scrollTop;
      else
        posunutie = 0;
    }
  }
  
  //vyska viditelnej casti stranky
  if(typeof(window.innerHeight) == 'number')
    vyska = window.innerHeight;
  else{
    if(document.documentElement && (document.documentElement.clientHeight))
      vyska = document.documentElement.clientHeight;
    else{
      if(document.body && (document.body.clientHeight))
        vyska = document.body.clientHeight;
    }
  }
  
  //vyska celej stranky aj so scrollovanim
  if(window.innerHeight && window.scrollMaxY)
    pageHeight = window.innerHeight + window.scrollMaxY;
  else if(document.body.scrollHeight > document.body.offsetHeight)
    pageHeight = document.body.scrollHeight;
  else
    pageHeight = document.body.offsetHeight + document.body.offsetTop;

  akt_poz = document.getElementById('nahlad').style.top.replace(/[^0-9]+/,"");
  vyska_nahlad = document.getElementById('nahlad').clientHeight;
  if(((pageHeight > (posunutie + 20 + vyska_nahlad)) || (akt_poz == '') || (akt_poz > posunutie)) && (vyska_nahlad <= pageHeight))
    document.getElementById('nahlad').style.top = posunutie + 20 + 'px';
  document.getElementById('filter').style.top = posunutie + 'px';
}

window.onscroll = function(){
  if(document.getElementById('nahlad').style.display == "block"){
    posun_nahlad();
  }
}

function ajaxReload(location,element){
  var xmlhttp;
  if (window.XMLHttpRequest){
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
  }
  else if (window.ActiveXObject){
    // code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
  else{
    alert("Váš prehliadač nepodporuje XMLHTTP!");
  }

  xmlhttp.onreadystatechange=function(){
    if(xmlhttp.readyState==4){
      document.getElementById(element).innerHTML = xmlhttp.responseText;
    }
  }

  xmlhttp.open("GET",location,true);
  xmlhttp.send(null); 
}

function ajaxOtvorit(location,element,cas){
  var xmlhttp;
  if (window.XMLHttpRequest)
    xmlhttp=new XMLHttpRequest();
  else if (window.ActiveXObject)
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  else
    alert("Váš prehliadač nepodporuje XMLHTTP!");
  
  xmlhttp.onreadystatechange=function(){
    if(xmlhttp.readyState==4 && xmlhttp.responseText){
      document.getElementById(element).style.visibility = 'visible';
      document.getElementById(element).innerHTML = xmlhttp.responseText;
    }
    else
      document.getElementById(element).style.visibility = 'hidden';
  }
  xmlhttp.open("GET",location,true);
  xmlhttp.send(null);
  
  if(cas)
    setTimeout("document.getElementById('"+element+"').style.visibility = 'hidden'",cas*1000);
}

function ajaxOpen(location){
  var ajax;
  if (window.XMLHttpRequest)
    ajax = new XMLHttpRequest();
  else if (window.ActiveXObject)
    ajax = new ActiveXObject("Microsoft.XMLHTTP");
  else
    alert("Váš prehliadač nepodporuje XMLHTTP!");

  ajax.onreadystatechange=function(){
    if(ajax.readyState==4)
      return ajax.responseText;
  }
  ajax.open("GET",location,true);
  ajax.send(null); 
}
