function rozrol_menu(){
document.getElementById('menu').style.visibility = 'visible';
document.getElementById('menu_rolovatko').style.visibility = 'hidden';
}

function srol_menu(){
document.getElementById('menu').style.visibility = 'hidden';
document.getElementById('menu_rolovatko').style.visibility = 'visible';
}

function original_size(w){
document.getElementById('fotka').style.width=w+"px";
}

function zmensit(w){
var width=document.getElementById('fotka').style.width;
width=width.replace('px', '');
if(width.length==0){width=default_resize;}
var width2=width*1;
width2-=100;
if(width2 < 0){}else{
document.getElementById("fotka").style.width=width2 + "px";}
}

function zvetsit(w){
var width=document.getElementById('fotka').style.width;
width=width.replace('px', '');
if(width.length==0){width=default_resize;}
var width2=width*1;
width2+=100;
document.getElementById("fotka").style.width=width2 + "px";
}

function fotka_in(jmeno){
document.getElementById(jmeno).style.visibility = 'visible';
}
function fotka_out(jmeno){
document.getElementById(jmeno).style.visibility = 'hidden';
}

function ajax_showFind(str,searchmode,vsechny_sekce){
if (str.length==0)
{ 
document.getElementById("ajax").innerHTML="";
return
}

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
{
alert ("Sorry, prohlížeč nepodporuje HTTP requesty, přestože podporuje Jscript... urgujte u mě o vylepšení přístupnosti.")
return
} 

var url="ajax.php";
url=url+"?q="+str;
 if(searchmode.length!==0){
  url=url+"&searchmode="+searchmode;
  xmlHttp.searchmode=searchmode;
  }
url=url+"&vsechny_sekce="+vsechny_sekce;

xmlHttp.str=str;
xmlHttp.onreadystatechange=ajax_find_stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);

}


function ajax_find_stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById("ajax").innerHTML=xmlHttp.responseText;
 
 if(xmlHttp.searchmode=='lide'){
  if(xmlHttp.responseText.length==0){
  document.getElementById('hledat').style.marginBottom='0em';
  document.getElementById("ajax").innerHTML='<em>Nic nenalezeno.</em>';
  }else{
  document.getElementById('hledat').style.marginBottom='12em';
  }
 }
 else
 {document.getElementById('hledani_id').style.height='auto';
 }

} 
}


function hodnota(str){
  if(document.getElementById("select").value.match('([0-9]+[;,]?)+')){
  document.getElementById("select").value=document.getElementById("select").value+";"+str;
  }
  else{
  document.getElementById("select").value=str;
  }
}



function GetXmlHttpObject()
{ 
var objXMLHttp=null
if (window.XMLHttpRequest)
  {
  objXMLHttp=new XMLHttpRequest()
  }
else if (window.ActiveXObject)
  {
  objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
return objXMLHttp
}

function hodnoceni(fotka,dir,hodnoceni){

{

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
{
alert ("Sorry, prohlížeč nepodporuje HTTP requesty, přestože podporuje Jscript... urgujte u mě o vylepšení přístupnosti.")
return
} 

var url="ajax.php";
url=url+"?hodnoceni="+hodnoceni;
url=url+"&dir="+dir;
url=url+"&fotka="+fotka;
xmlHttp.onreadystatechange=ajax_hodnoceni_stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
}

function ajax_hodnoceni_stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById("hodnoceni").innerHTML=xmlHttp.responseText;
} 
}


function ajax_fotka_preload(fotka,dir,slideshow){

 var url_page='?dir='+dir+'&fotka='+fotka+'&slideshow='+slideshow;
 var url_img=dir+'/med_'+fotka;

 xmlHttp=GetXmlHttpObject();

 xmlHttp.onreadystatechange=ajax_fotka_preload_stateChanged;
 xmlHttp.open("GET",url_page,true);
 xmlHttp.send(null);
                    
 img.src = url_img;
}



function ajax_fotka_preload_stateChanged(){
 if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
 }
}

function fotka_change(prochazena_dir,act){
actual_item=parseInt(act);
var dir=dir_index[actual_item][0];
var fotka=dir_index[actual_item][1];
var fotka_nahled=dir_index[actual_item][2]+dir+"/nahledy/"+fotka;
 /* img = new Image(); */
 img.src = dir_index[actual_item][2]+"/fotky/"+dir_index[actual_item][0]+"/nahledy/med_"+dir_index[actual_item][1];
 
if(actual_item+1<dir_index.length){
 img_next = new Image();
 img_next.src = dir_index[actual_item+1][2]+dir_index[actual_item+1][0]+"/nahledy/med_"+dir_index[actual_item+1][1];
 }
 
document.getElementById("fotkaimg").style.opacity='1';
document.getElementById("fotkaimg").src=fotka_nahled;
document.getElementById("fotkaimg").style.height='480px';
//fade(-1,document.getElementById("fotkaimg"));
document.getElementById("fotka_nadpis").innerHTML=dir_index[actual_item][0]+"/"+dir_index[actual_item][1];

if (document.getElementById("fotka_nalepky")){
document.getElementById("fotka_nalepky").innerHTML="... načítám nálepky...";
}else{
var nalepky = document.createElement('div');
nalepky.id="fotka_nalepky";
nalepky.innerHTML="...načítám nálepky...";
document.getElementById("all").appendChild(nalepky);  
}

if (document.getElementById("fotka_nal_dir")){document.getElementById("fotka_nal_dir").value=dir;}
if (document.getElementById("fotka_nal_fotka")){document.getElementById("fotka_nal_fotka").value=fotka;}
if (document.getElementById("fotka_newnal_dir")){document.getElementById("fotka_newnal_dir").value=dir;}
if (document.getElementById("fotka_nal_fotka")){document.getElementById("fotka_newnal_fotka").value=fotka;}

var nex=parseInt(actual_item) + 1;
document.getElementById("fotka_akt_cislo").innerHTML=nex;
 if(document.getElementById("fotka_link_next") && nex<dir_index.length){
 document.getElementById("fotka_next").src=dir_index[actual_item+1][2]+dir_index[actual_item+1][0]+"/nahledy/"+dir_index[actual_item+1][1];
 }

 if(document.getElementById("fotka_pre") && actual_item>0){
 document.getElementById("fotka_pre").src=dir_index[actual_item-1][2]+dir_index[actual_item-1][0]+"/nahledy/"+dir_index[actual_item-1][1];
 }
 for(var i=0;i<3;i++){
 if (document.getElementById("fotka_hodnoceni_"+i)){document.getElementById("fotka_hodnoceni_"+i).href="javascript:hodnoceni('"+dir+"','"+fotka+"','"+i+"')";}
 }
 title=document.title; 
 title=title.split(">");
 title.pop();
 title.pop();
 title[title.length]=' '+dir+' ';
 title[title.length]=' '+fotka;
 var newtitle;
  for(i=0;i<title.length;i++){
   if(i==0){
    newtitle=title[i]
   }
   else{
    newtitle=newtitle+">"+title[i];
   }
  }
 document.title=newtitle;



 var url='ajax.php?co=fotka_change&dir='+dir+'&fotka='+fotka+'&prochazena_dir='+prochazena_dir;
 xmlHttp=GetXmlHttpObject();
 
 xmlHttp.onreadystatechange=fotka_change_stateChanged;
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}



function fade(inout,element){
if(inout==1){var numero=0.1;}else{var numero=-0.1;}
for (i=1;i<11;i++){
 window.setTimeout(function() {
  addFade(numero,element);
  }, i * 50);
 }
}

function addFade(value,element) {
 element.style.opacity = parseFloat(element.style.opacity) + parseFloat(value);
}


function fotka_change_stateChanged(){

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("fotkaimg").style.visibility = "hidden"; 
fotka_odkaz(dir,dir_index,actual_item);

 data=xmlHttp.responseText;
 data_arr=data.split('\n');
 document.getElementById('fotka_exif_data').innerHTML=data_arr[0];
 document.getElementById('fotka_nalepky').innerHTML=data_arr[1];
 reschanged=data_arr[2].split(';');
  if (reschanged[0]=='nahled'){
  document.getElementById("velikost").innerHTML="<h3>Fotka byla zmenšena</h3><a href=\""+dir_index[actual_item][0]+"/"+dir_index[actual_item][1]+"\">Zobrazte si ji v plné velikosti ("+reschanged[1]+"x"+reschanged[2]+")</a><br /><a href=\"?dir="+dir_index[actual_item][0]+"&amp;fotka="+dir_index[actual_item][1]+"\">Přímý odkaz na tuto fotku</a>";
  adresa=dir_index[actual_item][2]+dir_index[actual_item][0]+"/nahledy/med_"+dir_index[actual_item][1];
  }else{document.getElementById("velikost").innerHTML="";adresa=dir_index[actual_item][2]+dir_index[actual_item][0]+'/'+dir_index[actual_item][1];}
                                       
 
 document.getElementById("fotkaimg").src = adresa;
 document.getElementById("fotkaimg").alt = dir_index[actual_item][1];
 document.getElementById("fotkaimg").style.visibility = "visible";
 //fade(1,document.getElementById("fotkaimg"));

 if (document.getElementById("fotka_slideshow_dir")){document.getElementById("fotka_slideshow_dir").value = dir;}
 if (document.getElementById("fotka_slideshow_fotka")){document.getElementById("fotka_slideshow_fotka").value = dir_index[actual_item][0]+"/"+dir_index[actual_item][1];}

 if (document.getElementById("fotka_komentare_dir")){document.getElementById("fotka_komentare_dir").value = dir_index[actual_item][0];}
 if (document.getElementById("fotka_komentare_fotka")){document.getElementById("fotka_komentare_fotka").value = dir_index[actual_item][1];}

 if(data_arr[3]=="0"){
 document.getElementById("fotka_komentare_obsah").innerHTML="";
 }else{
 document.getElementById("fotka_komentare_obsah").innerHTML=data_arr[4];
 }
 if(data_arr[5]){
  document.getElementById('zmena_slozky').innerHTML=data_arr[5];
  }

}
   }

function fotka_odkaz(dir,dir_index,actual_item){
actual_item=parseInt(actual_item);

   var next=actual_item+1;
 if(next>=dir_index.length && document.getElementById("fotka_link_next")){
 document.getElementById("fotka_href").href='#';
 document.getElementById("fotka_link_next").style.visibility='hidden';
 }else{
  if(document.getElementById("fotka_link_next")){
  var js_next_code="javascript:fotka_change('"+dir+"','"+next+"');";
   document.getElementById("fotka_href").href=js_next_code;
  document.getElementById("fotka_link_next").style.visibility='visible';
  document.getElementById("fotka_link_next").href=js_next_code;
  }
 }
   var prev=actual_item-1;
 if(prev<0 && document.getElementById("fotka_link_pre")){
 document.getElementById("fotka_link_pre").style.visibility='hidden';
 }else{
  if(document.getElementById("fotka_link_pre")){
  var js_prev_code="javascript:fotka_change('"+dir+"','"+prev+"');";
  document.getElementById("fotka_link_pre").style.visibility='visible';
  document.getElementById("fotka_link_pre").href=js_prev_code;
  }
 }
}

function slideshow_init(dir,actual_item){
/* Musi si stahnout dir_index */

document.getElementById("fotka_slideshow").innerHTML="Slideshow se inicializuje - stahuji obsah složky.";

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)
{
alert ("Sorry, prohlížeč nepodporuje HTTP requesty, přestože podporuje Jscript... urgujte u mě o vylepšení přístupnosti.")
return
} 

var url="ajax.php";
url=url+"?dir_index="+dir;
url=url+"&actual_item="+actual_item;
xmlHttp.onreadystatechange=slideshow_init_stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}


function slideshow_init_stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
 var pole=xmlHttp.responseText.split("§");
 var actual_item=pole[0];
 var dir=pole[1];
 var dir_index=pole[2].split(";");
 slideshow();
 } 
}


function slideshow(){
//dir, dir_index a actual_item jsou globalni promenne

document.getElementById("fotka_slideshow").innerHTML="Slideshow běží s prodlevou <span id=\"s_cas\">"+prodleva+"</span>s. <a href=\"javascript:prodleva=prodleva-(prodleva*0.5);document.getElementById('s_cas').innerHTML=prodleva;nic();\">Zrychli</a>, <a href=\"javascript:prodleva=Math.round(parseInt(prodleva)+(parseInt(prodleva)*0.5));document.getElementById('s_cas').innerHTML=prodleva;nic();\">zpomal</a>, <a href=\"javascript:vypnout_slideshow(slideshow_h);\">zastav</a>.";

actual_item=parseInt(actual_item);
if (prodleva<5){prodleva=5;}
fotka=dir_index[actual_item][1];
 if(actual_item+1>=dir_index.length){
 /* Slideshow skončila */
  document.getElementById("fotka_slideshow").innerHTML="Slideshow vypnutá,  <a href=\"javascript:prodleva='10';slideshow()\">zapnout</a>.";
 }else{
 if(actual_item+2<dir_index.length){var itempp=dir_index[actual_item+2][1];}else{var itempp='';}
  clearTimeout(slideshow_h);
  slideshow_h=window.setTimeout(function() {
  slideshow();
  actual_item++;
  fotka_change(dir,parseInt(actual_item));
  }, prodleva * 1000);
 }
}

function vypnout_slideshow(slideshow_h){
clearTimeout(slideshow_h);
document.getElementById("fotka_slideshow").innerHTML="Slideshow vypnutá,  <a href=\"javascript:var slideshow_h=slideshow();\">zapnout</a>.";
}

function dynamicChangePxHeight(id,zacatek,konec){
celkovy_time=1000;
steps=20;

 for(step_actual=1;step_actual<=steps;step_actual++){
   a=parseFloat(Math.PI/steps);
   b=parseFloat(step_actual*a);
  cos_actual=Math.cos(b)+1; //od dvou do nuly
  draha=zacatek-konec;
  pxadd=(draha/2)*cos_actual;
   konec=parseFloat(konec);
   pxadd=Math.round(parseFloat(pxadd));
  px=konec+pxadd;
  time=parseFloat((celkovy_time/steps)*step_actual);
 window.setTimeout("document.getElementById('"+id+"').style.maxHeight='"+px+"px'", time);
 }
}


function skryj_div(div_id,reverse){
document.getElementById(div_id).style.overflow='hidden';
  if(reverse==0){
  dynamicChangePxHeight(div_id,300,0);
  }else{
  dynamicChangePxHeight(div_id,0,1000);
  window.setTimeout("document.getElementById('"+div_id+"').style.maxHeight='100%'",1000);
  }
 if(document.getElementById(div_id+"_href")){
  if(reverse==0){
  document.getElementById(div_id+"_href").innerHTML="(rozbalit)";
  document.getElementById(div_id+"_href").href="javascript:skryj_div('"+div_id+"',1);";
  }else{
  document.getElementById(div_id+"_href").innerHTML="(skrýt)";
  document.getElementById(div_id+"_href").href="javascript:skryj_div('"+div_id+"',0);";
  }
 }
}

function zmena_slozky(newdir){
document.getElementById("zmena_slozky").innerHTML="Načítám...";

xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
{
alert ("Sorry, prohlížeč nepodporuje HTTP requesty, přestože podporuje Jscript... urgujte u mě o vylepšení přístupnosti.")
return
} 

var url="ajax.php";
url=url+"?dir_index="+newdir;
url=url+"&fotka_name="+dir_index[actual_item][0]+"/"+dir_index[actual_item][1];
xmlHttp.onreadystatechange=zmena_slozky_stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function zmena_slozky_stateChanged() 
{ 
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
 var pole=xmlHttp.responseText.split("§");
 var actual_item=pole[0];
 dir=pole[1];
 dir_indexx=pole[2].split(";");
dir_index=new Array();
  for (var i in dir_indexx){
   dir_index[i]=dir_indexx[i].split("/");
   dir_index[i][2]="";
   }
  document.getElementById("zmena_slozky").innerHTML="Načteno.";
var a=parseInt(actual_item) + 1;
  document.getElementById("fotka_akt_cislo").innerHTML=a;
  document.getElementById("pocet_ve_slozce").innerHTML=dir_index.length;
  fotka_change(dir,actual_item);
  fotka_odkaz(dir,dir_index,actual_item);
 } 
}

function nic(){}

var img= new Image();

var zI=5;

function rozrol(koho,kdo){

srolVse();
document.getElementById(koho).style.visibility='visible';
document.getElementById(koho).style.zIndex=zI++;
//document.getElementById(kdo).onmouseover=new function(){srol(koho,kdo);};
//document.getElementById(kdo).style.backgroundColor='#a52a2a'; 
}

function srol(koho,kdo){
 document.getElementById(koho).style.visibility='hidden'; 
}

function klavesa(e){
var keycode;
if (window.event){keycode = window.event.keyCode;}
else if (e){keycode = e.which;} 
if (keycode==39 && galerieFotkaDopredu){
  window.location.href=galerieFotkaDopreduAdresa;
}    
if (keycode==37 && galerieFotkaDozadu){
  window.location.href=galerieFotkaDozaduAdresa;
}

//if (keycode==78 && !document.getElementById('hledat_text').hasFocus() && !document.getElementById('select').hasFocus() && !document.getElementById('newnalepka').hasFocus()){
if (keycode==78 && document.getElementById('fotka_nalepky').style.visibility=='hidden'){
  nalepky();
}
}

function nalepky(){
if(!nalepkyNatrvalo){
  rozrol('fotka_nalepky','menu_nal');
  nalepkyNatrvalo=true;
  document.getElementById('select').focus();
  setTimeout("document.getElementById('select').value=document.getElementById('select').value.replace(/n+$/,'');", 70); 
  
  }
}



/* Menu related */
var nalepkyNatrvalo=false;

function srolVse(){
document.getElementById("fotka_slozka").style.visibility="hidden";    
document.getElementById("fotka_info").style.visibility="hidden";    
document.getElementById("fotka_submenu_misc").style.visibility="hidden"; 
  if(!nalepkyNatrvalo){
    document.getElementById("fotka_nalepky").style.visibility="hidden";  
  }    
  if(document.getElementById("hodnoceni")){
  document.getElementById("hodnoceni").style.visibility="hidden";
  }
}