// JavaScript Document
var iter;
var fotky;
var curVys;
var curSir;

function nastavIter(fotka) {
    i = 0;
    while(i < fotky.length && fotka != fotky[i][0] && fotka.length > 0) 
        i++;
        
    if(i < fotky.length)
        iter = i;
    else iter = 0;
         
    nastavOdkazy();
    vypniObrazek();
    document.getElementById('velkyObrazek').src = 'galerie/' + fotky[iter][0];
    zmenVelikost();
    odkazy();
}

function vypniObrazek() {
    document.getElementById('velkyObrazek').style.display = 'none';    
    document.getElementById('nacitam').style.top = (Math.round(document.body.clientHeight / 2) - 50) + "px"; 
    document.getElementById('nacitam').style.left = (Math.round(document.body.clientWidth / 2) - 100) + "px";     
    document.getElementById('nacitam').style.display = 'block';
}
function zapniObrazek() {
    document.getElementById('velkyObrazek').style.display = 'block';
    document.getElementById('nacitam').style.display = 'none';
    //alert(document.body.clientWidth  - curSir);
}

function odkazy() {
    if(iter == 0) 
        document.getElementById('odkPredchozi').style.display = 'none';
    else 
        document.getElementById('odkPredchozi').style.display = 'block';
    
    if(iter == (fotky.length - 1)) 
        document.getElementById('odkDalsi').style.display = 'none';
    else 
        document.getElementById('odkDalsi').style.display = 'block';
        
} 
function dalsi() {
    if(iter < (fotky.length - 1)) {
        vypniObrazek();
        document.getElementById('velkyObrazek').src = 'galerie/' + fotky[++iter][0];
        zmenVelikost();
        odkazy();
    }
}
function predchozi() {
    if(iter > 0) {
        vypniObrazek();
        document.getElementById('velkyObrazek').src = 'galerie/' + fotky[--iter][0];             
        zmenVelikost();
        odkazy();        
    }
}

function zmenVelikost() {
    obrazW = winW() - 188;
    obrazH = winH() - 57;
     
    if(fotky[iter][1] > obrazW || fotky[iter][2] > obrazH) {
      koef = fotky[iter][1] / obrazW;
      sirka = obrazW;
      vyska = fotky[iter][2] / koef;
    
      if(vyska > obrazH) {
          koef = vyska / obrazH;
          vyska = obrazH;
          sirka = sirka / koef;
      }
    }
    else {
      vyska = fotky[iter][2];
      sirka = fotky[iter][1];
    }
    curVys = vyska;
    curSir = sirka;
    document.getElementById('velkyObrazek').style.width = sirka + "px";
    document.getElementById('velkyObrazek').style.height = vyska + "px";
}
function nastavOdkazy() {
    document.getElementById('odkDalsi').style.right = (document.body.clientWidth) / 2 - 155 + "px";
    document.getElementById('odkPredchozi').style.left = (document.body.clientWidth) / 2 - 155 + "px";

 /*   document.getElementById('odkDalsi').style.top = Math.round(document.body.clientHeight / 2) - 25 + "px";
    document.getElementById('odkPredchozi').style.top = Math.round(document.body.clientHeight / 2) - 25 + "px";*/
}
function winH() {
   if (window.innerHeight)
      return window.innerHeight;
   else if(document.documentElement && document.documentElement.clientHeight)
      return document.documentElement.clientHeight;
   else if(document.body && document.body.clientHeight)
      return document.body.clientHeight;
   else
      return null;
}
function winW() {
   if (window.innerWidth)
      return window.innerWidth;
   else if(document.documentElement && document.documentElement.clientWidth)
      return document.documentElement.clientWidth;
   else if(document.body && document.body.clientWidth)
      return document.body.clientWidth;
   else
      return null;
}

