//<!--
function vytvorXHR() {
    var xhr2;
    try {
        xhr2 = new XMLHttpRequest();
    } catch (e) {
        var MSXmlVerze = new Array('MSXML2.XMLHttp.6.0', 'MSXML2.XMLHttp.5.0', 'MSXML2.XMLHttp.4.0', 'MSXML2.XMLHttp.3.0', 'MSXML2.XMLHttp.2.0', 'Microsoft.XMLHttp');
        for (var i = 0; i <= MSXmlVerze.length; i++) {
            try {
                xhr2 = new ActiveXObject(MSXmlVerze[i]);
                break;
            } catch (e) {
                //vzniklou chybu ignoruji a pokračuji nastavením další verze
            }
        }
    }
    if (!xhr2)
        alert("Došlo k chybě při vytváření objektu XMLHttpRequest!");
    else
        return xhr2;
}
var xhr = vytvorXHR();
function reloadSearch() {

    try {
        xhr.open("GET", "./include/" + url + query);
        xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        try {
            xhr.overrideMimeType('text/html');
        } catch (e) { }
        xhr.onreadystatechange = insertData;
        xhr.send(null);
    }
    catch (e) {
        alert("ERROR" + e);
    }

}

function insertData(id) {
    if (xhr.readyState == 4) {

        //if (xhr.status == 200) {
        div = document.getElementById("picture-box");
        div.innerHTML = xhr.responseText;
        document.getElementById("picture-box").style.display = "block";
        alertMe();
        loadPlayer(id)

        //} else {
        //alert('nepodařilo se vložit data');
        //}
    }
}
function ShowMap() {
	var s = 720;
	var v = 550;
	var clW;
	var clH;	
	
	//zjisti rozliseni cele obrazovky
	clW = screen.width;
	clH = screen.height;
	
	var winl = (clW - s) / 2;
	var wint = (clH - v) / 2;
	
	w_map = window.open('map.asp', 'aspekta_schema', 'scrollbars=yes,resizable=yes,width='+s+',height='+v+',left='+winl+',top='+wint+',screenX='+winl+',screenY='+wint);
	w_map.window.focus();
}

function closePopUpWindow() {
    document.getElementById('website-back').style.display = "none";
    document.getElementById('website-shadow').style.display = "none";
    xhr.open("GET", "./actions/pf_close.asp");
    //xhr.onreadystatechange = insertData;
    xhr.send(null);
}

function getObjectSizeY(id) {
    if (!document.getElementById(id)) {
        return 0;
    }
    obj = document.getElementById(id);
    if (obj.clientHeight) {
        return obj.clientHeight;
    } else {
        if (document.documentElement.clientHeight) {
            return document.documentElement.clientHeight;
        } else {
            if (window.innerHeight) {
                return window.innerHeight;
            }
        }
    }
}
function getObjectSizeX(id) {
    if (!document.getElementById(id)) {
        return 0;
    }
    obj = document.getElementById(id);
    if (obj.clientWidth) {
        return obj.clientWidth;
    } else {
        if (document.documentElement.clientWidth) {
            return document.documentElement.clientWidth;
        } else {
            if (window.innerWidth) {
                return window.innerWidth;
            }
        }
    }
}
function getWindowSize() {
    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return [myWidth, myHeight];
}
function getScreenSizeY() {
    if (document.body.clientHeight) {
        return document.body.clientHeight;
    }
    if (document.documentElement.clientHeight) {
        return document.documentElement.clientHeight;
    }
    if (window.innerHeight) {
        return window.innerHeight;
    }

}
function showBig(soubor, sirka, vyska, objekt) {
	var obr = document.getElementById('BigImg');
	obr.src = soubor;
	obr.width = sirka;
	obr.height = vyska;
	//alert(GetX(objekt) + ', ' + GetY(objekt));
	obr.style.top = GetY(objekt) + 'px';
	obr.style.left = GetX(objekt) + 'px';
	obr.style.display = 'block';
	return false;
}

function hideBig(objekt) {
	objekt.style.display = 'none';
}

function GetX(obj) {
	var curleft = 0;
	if(obj.offsetParent)
		while(1) {
			curleft += obj.offsetLeft;
			if(!obj.offsetParent)
			break;
			obj = obj.offsetParent;
		}
	else if(obj.x)
		curleft += obj.x;
	return curleft;
}

function GetY(obj) {
	var curtop = 0;
	if(obj.offsetParent)
		while(1) {
			curtop += obj.offsetTop;
			if(!obj.offsetParent)
			break;
			obj = obj.offsetParent;
		}
	else if(obj.y)
		curtop += obj.y;
	return curtop;
}

var aktualita_delay = 40;
var aktualita_pocet_kroku = 10
var akt_strana = 1;
var vyska_prvku = 80;
var pocet_prvku = 3;
var galerie = "galerie-obrazky";
var inProgress = false;
var top_obrazky;
var top_thumbnail;
var pocet_obrazku;
var duration = 500;       //doba změny obrázku
var steps = 10;           //počet kroků
var auto_delay = 2500;    // doba zobrazení obrázku v 0% průhlednosti
var isProgress = false;
auto_delay += duration * 2;
function galerieNahoru() {
    if (!inProgress) {
        if (akt_strana > 0) {
            nastavStranu(akt_strana - 1)
        }
    }
}

function galerieDolu() {
    if (!inProgress) {
        if (akt_strana < pocet_obrazku) {
            nastavStranu(akt_strana + 1)
        }
    }
}
var odva
var kam
odva = false;
kam = 0;
function galerieNahoruODva() {
    if (!inProgress) {
        if (akt_strana > 0) {
            odva = true;
            nastavStranu(akt_strana - 1)
            kam = 1;
        }
    }
}

function galerieDoluODva() {
    if (!inProgress) {
        if (akt_strana < pocet_obrazku) {
            odva = true;
            nastavStranu(akt_strana + 1)
            kam = 2;
        }
    }
}

function nastavPocatek(strana) {
    akt_strana = strana
    if (strana == 0) {
        document.getElementById('top-right').style.backgroundPosition = "0px -" + (vyska_prvku - 10) + "px";
        document.getElementById(galerie).style.top = "0px";
        document.getElementById('atm-pic').src = './images/' + top_obrazky[strana];
    }
    if (strana == pocet_obrazku) {

        document.getElementById('top-right').style.backgroundPosition = "0px " + (vyska_prvku + 10) + "px";
        posun = strana * vyska_prvku * -1 + 2 * vyska_prvku;
        document.getElementById(galerie).style.top = posun + "px";
        document.getElementById('atm-pic').src = './images/' + top_obrazky[strana];
    }
    if (strana > 0 && strana < pocet_obrazku) {
        document.getElementById('top-right').style.backgroundPosition = "0px 10px";
        posun = strana * vyska_prvku * -1 + vyska_prvku ;
        document.getElementById(galerie).style.top = posun + "px";
        document.getElementById('atm-pic').src = './images/' + top_obrazky[strana];

    }

    nastavPozicovani();
    nastavSipky();
}

function nastavStranu(newStrana) {
    var posun;
    posun = vyska_prvku;
    inProgress = true;

    for (i = 1; prvek = document.getElementById("galerie_" + i); i++) {
        prvek.style.cursor = "auto";
        prvek.onclick = null;
    }
    if (akt_strana < newStrana) {
        posun = posun * (newStrana - akt_strana)
        posunKrokDopredu(posun, 1);
    }
    if (akt_strana > newStrana) {
        posun = posun * (akt_strana - newStrana)
        posunKrokDozadu(posun, 1);
    }
    
    
        
    fadeOut();
    akt_strana = newStrana
    nastavPozicovani();


}
function none() {

}
function nastavPozicovani() {
    if (document.getElementById("galerie_" + (akt_strana + 1 - 1))) {
        document.getElementById("galerie_" + (akt_strana + 1 - 1)).style.cursor = "pointer";
        document.getElementById("galerie_" + (akt_strana + 1 - 1)).onclick = galerieNahoru;
        if (akt_strana == pocet_obrazku) {
            if (document.getElementById("galerie_" + (akt_strana + 1 - 2))) {
                document.getElementById("galerie_" + (akt_strana + 1 - 2)).style.cursor = "pointer";
                document.getElementById("galerie_" + (akt_strana + 1 - 2)).onclick = galerieNahoruODva;
            }
        }
    }
    if (document.getElementById("galerie_" + (akt_strana + 1 + 1))) {
        document.getElementById("galerie_" + (akt_strana + 1 + 1)).style.cursor = "pointer";
        document.getElementById("galerie_" + (akt_strana + 1 + 1)).onclick = galerieDolu;
        if (akt_strana == 0) {
            if (document.getElementById("galerie_" + (akt_strana + 1 + 2))) {
                document.getElementById("galerie_" + (akt_strana + 1 + 2)).style.cursor = "pointer";
                document.getElementById("galerie_" + (akt_strana + 1 + 2)).onclick = galerieDoluODva;
            }
        }
    }
}

function posunKrokDopredu(posun, pocet) {
    var rposun = posun / aktualita_pocet_kroku;
    for (i = 0; i <= aktualita_pocet_kroku; i++) {
        vychozi = getDelka(document.getElementById(galerie).style.top) * -1;
        if (akt_strana == 0) {
            setTimeout("nastavPozadi(" + (((i * rposun)) - posun + 10) + ")", i * aktualita_delay);
        } else {
            if (akt_strana != pocet_obrazku - 1) {
                setTimeout("nastavBox(" + ((-1 * i * rposun) - vychozi) + ")", i * aktualita_delay);
            } else {
                setTimeout("nastavPozadi(" + (((i * rposun)) + 10) + ")", i * aktualita_delay);
            }
        }
    }
    setTimeout("nastavSipky()", i * aktualita_delay);
}

function posunKrokDozadu(posun, pocet) {
    var rposun = posun / aktualita_pocet_kroku;
    for (i = aktualita_pocet_kroku; i >= 0; i--) {
        vychozi = getDelka(document.getElementById(galerie).style.top) * -1;
        if (akt_strana == 1) {
            setTimeout("nastavPozadi(" + (((-1 * i * rposun) - vychozi) + 10) + ")", i * aktualita_delay);
        } else {
            if (akt_strana < pocet_obrazku) {
                setTimeout("nastavBox(" + (-1 * ((-1 * i * rposun) + vychozi)) + ")", i * aktualita_delay);
            } else {
            setTimeout("nastavPozadi(" + (posun - ((i * rposun)) + 10) + ")", i * aktualita_delay);
            }
        }
    }
    setTimeout("nastavSipky()", aktualita_pocet_kroku * aktualita_delay);
}

function nastavPozadi(novaPozice) {
    document.getElementById('top-right').style.backgroundPosition = "0px " + novaPozice + "px";
}
function nastavBox(novaPozice) {
    document.getElementById(galerie).style.top = novaPozice + "px";
}

function nastavSipky() {
    if (akt_strana < pocet_obrazku) {
        document.getElementById("sipka-bottom").style.display = 'block';
    } else {
        document.getElementById("sipka-bottom").style.display = 'none';
    }

    if (akt_strana > 0) {
        document.getElementById("sipka-top").style.display = 'block';
    } else {
        document.getElementById("sipka-top").style.display = 'none';
    }
    inProgress = false;
    if (odva) {
        odva = false
        if(kam == 2){
            kam = 0;
            galerieDolu();
        }
        if (kam == 1) {
            kam = 0;
            galerieNahoru();
        }
    }
    
}

function getDelka(str) {
    var delka = str.substr(0, str.length - 2);
    if (delka + "" == "") { delka = 0 }
    delka = delka * 1;
    return delka
}

function getObjectSizeY(id) {
    if (!document.getElementById(id)) {
        return 0;
    }
    obj = document.getElementById(id);
    if (obj.clientHeight) {
        return obj.clientHeight;
    } else {
        if (document.documentElement.clientHeight) {
            return document.documentElement.clientHeight;
        } else {
            if (window.innerHeight) {
                return window.innerHeight;
            }
        }
    }
}

function setOpacity(level) {
    document.getElementById("atm-pic").style.opacity = level;
    document.getElementById("atm-pic").style.MozOpacity = level;
    document.getElementById("atm-pic").style.KhtmlOpacity = level;
    document.getElementById("atm-pic").style.filter = "alpha(opacity=" + (level * 100) + ");";
}

function fadeIn() {
    for (i = 0; i <= 1; i += (1 / steps)) {
        setTimeout("setOpacity(" + i + ")", i * (duration / 2));
    }
}

function fadeOut() {
    isProgress = true;
    for (i = 0; i <= 1; i += (1 / steps)) {
        setTimeout("setOpacity(" + (1 - i) + ")", i * (duration / 2));
    }
    timer2 = setTimeout("nastavObrSrc()", (duration / 2));
}


function nastavObrSrc() {
    var box = document.getElementById("atm-pic").parentNode;
    var imageBox = document.getElementById("atm-pic")
    
    var newImageBox = document.createElement('img');
    newImageBox.setAttribute("id", "atm-pic");


    newImageBox.src = "./images/" + top_obrazky[akt_strana];

    newImageBox.style.opacity = 0;
    newImageBox.style.MozOpacity = 0;
    newImageBox.style.KhtmlOpacity = 0;
    newImageBox.style.filter = "alpha(opacity=" + (0 * 100) + ");";

    box.removeChild(imageBox)
    box.appendChild(newImageBox);
    addEvent(newImageBox, "load", fadeIn)
}

function addEvent(el, type, myFunction) {
    if (el.addEventListener) {
        el.addEventListener(type, myFunction, false);
    } else if (el.attachEvent) {
        try {
            el.attachEvent("onload", fadeIn());
        } catch (e) { }
    } else {
        el.type = myFunction;
    }
}
// -->
