var maximalniVyskaObrazku = 0;
var maximalniSirkaObrazku = 0;
var fotkaCislo = 0;
var slideCasovac = false;
var idFotky = new Array();
var idFotkyDb = new Array();
var aktualniFotka = false;
var aktualniFoto = "";
var seznamIdFotek = new Array();
var rodic = "";
var pp = "";
var idElementu = "";
var element = "";
var elementNacti = "";
var predchozi = 0;
var seznamObrazku = "";
var tiktak = false;
var zobrazeneFotky = new Array();


var cekej = "";
var fotoSkryte = "";
var nacitaniFotek = 0;
var pic = new Array();
var tiktakFoto = 0;

tiktak = window.setInterval("priradOnClick();", 400);

function priradOnClick()
  {
    var p = 0;
    if(document.body != 'null' && document.getElementById('seznam-fotek') != 'null') {     
      seznamObrazku = document.getElementById('seznam-fotek');
      for(w=0;w<seznamObrazku.childNodes.length;w++) {
        if(seznamObrazku.childNodes[w].id != undefined) {
        idFotky[p] = seznamObrazku.childNodes[w].id;
        idFotkyDb[seznamObrazku.childNodes[w].id] = seznamObrazku.childNodes[w].id.substr(11);
        p++;
        seznamObrazku.childNodes[w].onclick=function(){return zobrazFoto(this.id);};
        pic[p] = new Image();
        pic[p].src = seznamObrazku.childNodes[w].href;
        }
      }
      clearInterval(tiktak);
    }
  }
  
function defaultniPruhlednost(id) 
  {
    opacity(id, 100, 60, 1500);  
  }
  
function aktivniPruhlednost(id)
  {
    opacity(id, 60, 100, 1500);  
  }

function vytvorProhlizecFotek()
  {
    // 
    var prohlizec = document.createElement('DIV');
    prohlizec.setAttribute('id','fotka-original-ram');
    
    // ramecek, ve kterem je zobrazen obrazek
    var ram = document.createElement('DIV');
    ram.setAttribute('id','fotka-original');
    
    // vlastni obrazek
    var obrazek = document.createElement('IMG');
    obrazek.setAttribute('id','fotka-show');
    obrazek.onclick = function () {nasledujiciFoto();}
    
    // titulek obrazku
    var obrazekTitulek = document.createElement('DIV');
    obrazekTitulek.setAttribute('id','obrazek-titulek');
    
    // filmovy pas, ve kterem jsou zobrazeny nahledy vsech obrazku v galerii
    var filmovyPas = document.createElement('DIV');
    filmovyPas.setAttribute('id','fotka-filmovy-pas');

    // ovladaci panel, ovladaci prvky pro prohlizec
    var ovladaciPanel = document.createElement('DIV');
    ovladaciPanel.setAttribute('id','fotka-ovladaci-panel');

    var obrazekPopis = document.createElement('DIV');
    obrazekPopis.setAttribute('id','obrazek-popis');

    var obrazekPopisButton = document.createElement('DIV');
    obrazekPopisButton.setAttribute('id','obrazek-popis-tlacitko');
    obrazekPopisButton.onclick = function () {ukazPopis(); return false;}  
    obrazekPopisButton.onmouseover = function () {aktivniPruhlednost(this.id);  if(IE) {this.style.cursor = 'hand';} else {this.style.cursor = 'pointer';}}
    obrazekPopisButton.onmouseout = function () { defaultniPruhlednost(this.id);}    


    var slideShowButtonBefore = document.createElement('DIV');
    slideShowButtonBefore.setAttribute('id','slideShowBut-before');
    //slideShowButtonBefore.className='slidePlay';
    slideShowButtonBefore.onclick = function () {predchoziFoto(); return false;}    
    slideShowButtonBefore.onmouseover = function () {aktivniPruhlednost(this.id);  if(IE) {this.style.cursor = 'hand';} else {this.style.cursor = 'pointer';}}
    slideShowButtonBefore.onmouseout = function () { defaultniPruhlednost(this.id);}

    var slideShowButtonNext = document.createElement('DIV');
    slideShowButtonNext.setAttribute('id','slideShowBut-next');
    //slideShowButtonBefore.className='slidePlay';
    slideShowButtonNext.onclick = function () {nasledujiciFoto(); return false;}    
    slideShowButtonNext.onmouseover = function () { aktivniPruhlednost(this.id); if(IE) {this.style.cursor = 'hand';} else {this.style.cursor = 'pointer';}}
    slideShowButtonNext.onmouseout = function () { defaultniPruhlednost(this.id);}

    var slideShowButtonFirst = document.createElement('DIV');
    slideShowButtonFirst.setAttribute('id','slideShowBut-first');
    //slideShowButtonBefore.className='slidePlay';
    slideShowButtonFirst.onclick = function () {prvniFoto(); return false;}    
    slideShowButtonFirst.onmouseover = function () {aktivniPruhlednost(this.id); if(IE) {this.style.cursor = 'hand';} else {this.style.cursor = 'pointer';}}
    slideShowButtonFirst.onmouseout = function () { defaultniPruhlednost(this.id);}

    var slideShowButtonEnd = document.createElement('DIV');
    slideShowButtonEnd.setAttribute('id','slideShowBut-end');
    //slideShowButtonBefore.className='slidePlay';
    slideShowButtonEnd.onclick = function () {posledniFoto(); return false;}    
    slideShowButtonEnd.onmouseover = function () {aktivniPruhlednost(this.id); if(IE) {this.style.cursor = 'hand';} else {this.style.cursor = 'pointer';}}
    slideShowButtonEnd.onmouseout = function () { defaultniPruhlednost(this.id);}
    
    var slideShowButton = document.createElement('DIV');
    slideShowButton.setAttribute('id','slideShowBut');
    slideShowButton.className='slidePlay';
    slideShowButton.onclick = function () {spustSlide(); return false;}    
    slideShowButton.onmouseover = function () { aktivniPruhlednost(this.id); if(IE) {this.style.cursor = 'hand';} else {this.style.cursor = 'pointer';}}
    slideShowButton.onmouseout = function () { defaultniPruhlednost(this.id);}

    var tlacitkoZavriOkno = document.createElement('DIV');
    tlacitkoZavriOkno.setAttribute('id','close-win');
    tlacitkoZavriOkno.onclick = function () {zavriFoto(); return false;}    
    tlacitkoZavriOkno.onmouseover = function () { if(IE) {this.style.cursor = 'hand';} else {this.style.cursor = 'pointer';}}

    var slideTlacitka = document.createElement('DIV');
    slideTlacitka.setAttribute('id','slide-tlacitka');
    
    slideTlacitka.appendChild(slideShowButtonFirst);
    slideTlacitka.appendChild(slideShowButtonBefore);
    slideTlacitka.appendChild(slideShowButton);
    slideTlacitka.appendChild(slideShowButtonNext);
    slideTlacitka.appendChild(slideShowButtonEnd);
    ovladaciPanel.appendChild(tlacitkoZavriOkno);
    ovladaciPanel.appendChild(slideTlacitka);
    ovladaciPanel.appendChild(obrazekPopisButton);

    ram.appendChild(obrazekTitulek);      
    ram.appendChild(obrazek);
    ram.appendChild(obrazekPopis);
    
    var pracovniOkno = document.createElement('IFRAME');
    pracovniOkno.src = '';
    pracovniOkno.setAttribute('id','okno-pracovni');
      
    document.body.appendChild(pracovniOkno);
    
    prohlizec.appendChild(ovladaciPanel);   
    prohlizec.appendChild(ram);
    prohlizec.appendChild(filmovyPas);
    document.body.appendChild(prohlizec);     
    
    nactiSeznamFoto();
  }

function ukazPopis()
  {
    var stavZobrazeniPopisu = document.getElementById('obrazek-popis').style.display;

    if(stavZobrazeniPopisu != 'block') {
      document.getElementById('obrazek-popis').style.display = 'block';
      opacity('obrazek-popis', 0, 70, 1500);  
    } else {
      opacity('obrazek-popis', 70, 0, 1500);  
      setTimeout("document.getElementById('obrazek-popis').style.display = 'none'",1500);
    }
  }

function nactiSeznamFoto()
  {
    // nacteni obrazku galerie a pripava pro jejich zobrazeni    
    filmovyPas = document.getElementById('fotka-filmovy-pas');
    prohlizec = document.getElementById('fotka-original-ram');
    
    var fotoSkryteElement = document.createElement('IMG');
    fotoSkryteElement.src = '';
    fotoSkryteElement.setAttribute('id','fotka-foto-skryte');
    fotoSkryteElement.style.display = 'none';
    
    prohlizec.appendChild(fotoSkryteElement);
    
    fotoSkryte = document.getElementById('fotka-foto-skryte');

    for(r=0;r<idFotky.length;r++) {
      elementNacti = document.getElementById(idFotky[r]);
      potomek = elementNacti.childNodes[0];
      
      // obrazek
      var obrazekf = document.createElement('IMG');
      obrazekf.src=potomek.src;
      obrazekf.alt=potomek.alt;
      obrazekf.style.border=0;
      
      // odkaz k obrazku
      var obrazekA = document.createElement('A');
      obrazekA.href=elementNacti.href;
      obrazekA.title=elementNacti.title;
      obrazekA.setAttribute('id',r);
      obrazekA.onmouseover = function () { aktivniPruhlednost(this.id);}
      obrazekA.onmouseout = function () { defaultniPruhlednost(this.id);}
      obrazekA.onclick=function(){return zobrazFoto(idFotky[this.id]);};
      
      obrazekA.appendChild(obrazekf);
 
      // pridani obrazku do filmoveho pasu
      filmovyPas.appendChild(obrazekA);
      defaultniPruhlednost(r);  

    fotoSkryte.src = elementNacti.href;
 //   fotoSkryte.onload = pokracuj;
      
    }  
  
    prohlizec.appendChild(filmovyPas);    
  }


function nedelejNic()
  {

  }
  
function pokracuj()
  {
    clearTimeout(cekej);
  }

function posledniFoto()
  {
    var posledni = idFotky.length - 1;
    zobrazFoto(idFotky[posledni]);
  }

function prvniFoto()
  {
    zobrazFoto(0);
  }

function predchoziFoto()
  {
    predchozi = aktualniFotka - 1;
    if(predchozi < 0) {predchozi = 0;}
    zobrazFoto(idFotky[predchozi]);
  }

function nasledujiciFoto()
  {
    var nasledujici = aktualniFotka + 1;
    if(nasledujici >= idFotky.length) {nasledujici = idFotky.length - 1 ;}
    zobrazFoto(idFotky[nasledujici]);
  }

function spustSlide()
  {
    // nastavime text/obrazek pro zastaveni slideShow
    document.getElementById('slideShowBut').className = 'slideStop';
    document.getElementById('slideShowBut').onclick = function () {zastavSlide(); return false;}
    
    if(fotkaCislo == idFotky.length) {fotkaCislo = 0;}
    //blendimage('fotka-original', 'fotka-show', fotkaCestaO[fotkaCislo] , 1000); 
    if(slideCasovac == false) {    
      slideCasovac=window.setInterval("spustSlide();", 5000);
    }
    zobrazFoto(idFotky[fotkaCislo]);

    fotkaCislo++;    
    
  }
  
function zastavSlide()
  {
    clearInterval(slideCasovac);
    document.getElementById('slideShowBut').className = 'slidePlay';
    document.getElementById('slideShowBut').onclick = function () {spustSlide(); return false;}    
  }

function winHFun() {
   if (window.innerHeight)
      /* NN4 a kompatibilní prohlížeče */
      return window.innerHeight;
   else if
   (document.documentElement &&
   document.documentElement.clientHeight)
      /* MSIE6 v std. režimu - Opera a Mozilla
      již uspěly s window.innerHeight */
      return document.documentElement.clientHeight;
   else if
   (document.body && document.body.clientHeight)
      /* starší MSIE + MSIE6 v quirk režimu */
      return document.body.clientHeight;
   else
      return null;
}


function zobrazFoto(idElementu)
  {
  
   aktualniFoto = idElementu;
   element = document.getElementById(idElementu);
   if(document.getElementById('fotka-original-ram') == null) {
    vytvorProhlizecFotek();
   }

   if (window.innerWidth)
      /* NN4 a kompatibilní prohlížeče */
      winW = window.innerWidth;
   else if
   (document.documentElement &&
   document.documentElement.clientWidth)
      /* MSIE6 v std. režimu - Opera a Mozilla
      již uspěly s window.innerHeight */
      winW = document.documentElement.clientWidth;
   else if
   (document.body && document.body.clientWidth)
      /* starší MSIE + MSIE6 v quirk režimu */
      winW = document.body.clientWidth;   
  
    var winH = winHFun();

   // aktualniFotka = idFotky.indexOf(element.id);
    for(u=0;u<idFotky.length;u++) {
      if(idFotky[u] == element.id) {
        aktualniFotka = u;
        break;
      }
    }

    maximalniVyskaObrazku = winH-100;
    maximalniSirkaObrazku = winW-540;
    document.getElementById('fotka-show').style.visibility = 'hidden';
    var cesta = element.href;
    var f = new Image();
    f.src = cesta;
    
    var fotka = document.getElementById('fotka-show');
    fotka.src = f.src;
    fotka.style.marginTop = 20;
    nactiRozmery(f,fotka);
    
    var fotoPopis = '';
    var elementImg = element.childNodes[0];
    if(elementImg.tagName.toLocaleUpperCase() == 'IMG') {
      fotoPopis = elementImg.alt;
    }
    
    document.getElementById('obrazek-titulek').innerHTML = element.title;
    document.getElementById('obrazek-popis').innerHTML = fotoPopis;

    document.getElementById('fotka-original-ram').style.textAlign = 'center';
    document.getElementById('fotka-original-ram').style.width = '100%';
    document.getElementById('fotka-original-ram').style.height = winH+'px';

    document.getElementById('fotka-original-ram').style.position = 'absolute';  
    document.body.style.overflow='hidden';

    document.getElementById('fotka-original-ram').style.left = 0;
    document.getElementById('fotka-original-ram').style.top = 0;
    window.scrollTo(0, 0);          

    return false;
  }

function nactiRozmery(fotoCache,f)
  {
    var pomer = 0;
    var obrazekSirka = fotoCache.width;
    var obrazekVyska = fotoCache.height;
    
    // uprava velikosti obrazku dle rozliseni monitoru
    if(obrazekVyska > maximalniVyskaObrazku || obrazekSirka > maximalniSirkaObrazku) {
      if(maximalniVyskaObrazku > maximalniSirkaObrazku) {
        f.width = maximalniSirkaObrazku;
        pomer = obrazekSirka / obrazekVyska;
        f.height = maximalniSirkaObrazku / pomer;
      } else if(maximalniVyskaObrazku < maximalniSirkaObrazku) {
        if(obrazekVyska < maximalniVyskaObrazku) {
          f.width = maximalniSirkaObrazku;
          pomer = obrazekSirka / obrazekVyska;
          f.height = maximalniSirkaObrazku / pomer;
        } else {
          f.height = maximalniVyskaObrazku;
          pomer = obrazekVyska / obrazekSirka;
          f.width = maximalniVyskaObrazku / pomer;
        }
      }
    } else {
      f.height = obrazekVyska;
      f.width = obrazekSirka;
    }

    var vyska = (f.height /2)+60;
    document.getElementById('okno-pracovni').src = '?zapisZobrazeniFoto='+idFotkyDb[aktualniFoto];
    document.getElementById('fotka-original').style.backgroundPosition = 'center '+parseInt(vyska);
    document.getElementById('fotka-original-ram').style.visibility = "visible";
    document.getElementById('fotka-show').style.visibility = "visible";
    //opacity('fotka-show', 100, 10, 1);
    //opacity('fotka-show', 10, 100, 1000);
    defaultniPruhlednost('slideShowBut-before');
    defaultniPruhlednost('slideShowBut-next');
    defaultniPruhlednost('slideShowBut-first');
    defaultniPruhlednost('slideShowBut-end');
    defaultniPruhlednost('slideShowBut');
    
  }
  
function ukazFoto()
  {
 
  }
  
function zavriFoto()
  {
    fotkaCislo = 0;
    zastavSlide();
    document.body.style.overflow='auto';
    document.getElementById('fotka-original-ram').style.visibility='hidden';
    document.getElementById('fotka-show').style.visibility = 'hidden';
  }
  
  
