function layBgLoad(layId, url, lurl)
{
    if (e=getElement(layId))
        e.style.visibility = 'hidden';
    if (lurl)
    {
        loading = document.createElement('IMG');
        loading.id = 'layBgLoadingImage';
        loading.src = lurl;
        loading.style.width = '100px';
        loading.style.height = '100px';
        loading.style.position = 'absolute';
        loading.style.zIndex = 10;
        loading.style.left = '48%';
        loading.style.top = '48%';
        document.getElementsByTagName('body')[0].appendChild(loading);
    }
    laybgimg = new Image(25, 25);
    laybgimg.onload = new Function('layBgLoaded(\''+layId+'\');');
    laybgimg.src = url;
}

function layBgLoaded(layId)
{
    if (e=getElement(layId))
        e.style.visibility = 'visible';
    if (e=getElement('layBgLoadingImage'))
        e.style.display = 'none';
}


var axTimer = null;

    var galerieFoto = new sack();
        galerieFoto.requestFile = URL+'includes/js.php';
        galerieFoto.method = 'POST';
        galerieFoto.element = false;
        galerieFoto.fotoId = false;
        galerieFoto.reqType = false;
        galerieFoto.imgAttr = new Array();
        galerieFoto.img = new Image(25,25);
        galerieFoto.img.onload = function() {
            if (e=getElement('fotoMainImageArt'))
            {
                e.imgResizeXTo = false;
                if ((typeof(galerieFoto.imgAttr['imgx'])!='undefined' && galerieFoto.imgAttr['imgx']) && (typeof(galerieFoto.imgAttr['imgy'])!='imgy' && galerieFoto.imgAttr['imgy']))
                {
                    e.imgResizeXTo = galerieFoto.imgAttr['imgx'];//e.style.width = galerieFoto.imgAttr['imgx']+'px';
                    e.imgResizeYTo = galerieFoto.imgAttr['imgy'];//e.style.height = galerieFoto.imgAttr['imgy']+'px';
                    e.mTop = Math.floor((500-parseInt(galerieFoto.imgAttr['imgy']))/2);
                }
                e.src = galerieFoto.img.src;
                if (e=getElement('fotoMainImageArtLink'))
                {
                    wx = (typeof(galerieFoto.imgAttr['x'])!='undefined' && galerieFoto.imgAttr['x']) ? galerieFoto.imgAttr['x'] : 1044;
                    if (parseInt(wx)>1044)
                        wx = 1044;
                    else
                        wx = parseInt(wx)+20;
                    wy = (typeof(galerieFoto.imgAttr['y'])!='undefined' && galerieFoto.imgAttr['y']) ? galerieFoto.imgAttr['y'] : 788;
                    if (parseInt(wy)>788)
                        wy = 788;
                    else
                        wy = parseInt(wy)+20;
                    url = (typeof(galerieFoto.imgAttr['htmlurl'])!='undefined' && galerieFoto.imgAttr['htmlurl']) ? galerieFoto.imgAttr['htmlurl'] : '';
                    e.onclick = new Function('popUp(\'galerie\', \''+url+'\', '+wx.toString()+', '+wy.toString()+'); return false');
                    e.href = url;
                }
                if (e=getElement('fotoMainIndex'))
                {
                    e.innerHTML = galerieFoto.imgAttr['index']+' / '+galerieFoto.imgAttr['fotografii'];
                }
            }
            if (e=getElement('fotoMainPopis'))
                e.innerHTML = (typeof(galerieFoto.imgAttr['popis'])!='undefined' && galerieFoto.imgAttr['popis']) ? galerieFoto.imgAttr['popis'] : '';
            if (e=getElement('fotoMainSoubor'))
                e.innerHTML = (typeof(galerieFoto.imgAttr['soubor'])!='undefined' && galerieFoto.imgAttr['soubor']) ? galerieFoto.imgAttr['soubor']+"\n" : '';
        };
        galerieFoto.img.onerror = function() {
            if (e=getElement('fotoMainLoading'))
                e.innerHTML += '<br><span class="red">error loading image</span>';
        }
        galerieFoto.onLoading = function() {
            if (e=getElement('fotoMainLoading'))
            {
                e.style.display = 'block';
                e.innerHTML = '';
            }
        };
        galerieFoto.onLoaded = function() {
        };
        galerieFoto.onCompletion = function() {
            if (typeof(this.responseXML)!='undefined' && this.responseXML!=null)
            {
                try {
                    reqType = this.responseXML.getElementsByTagName('request')[0];
                    reqType = (reqType.firstChild) ? reqType.firstChild.nodeValue : '';
                } catch(e) {}
                switch(reqType)
                {
                    case 'imageId':
                        fotoId = getXMLSingleValue(this.responseXML, 'id');
                        fotoURL = getXMLSingleValue(this.responseXML, 'url');
                        this.imgAttr['soubor'] = getXMLSingleValue(this.responseXML, 'soubor');
                        this.imgAttr['popis'] = getXMLSingleValue(this.responseXML, 'popis');
                        this.imgAttr['x'] = getXMLSingleValue(this.responseXML, 'x');
                        this.imgAttr['y'] = getXMLSingleValue(this.responseXML, 'y');
                        this.imgAttr['velikost'] = getXMLSingleValue(this.responseXML, 'velikost');
                        this.imgAttr['typ'] = getXMLSingleValue(this.responseXML, 'typ');
                        this.imgAttr['zobrazeno'] = getXMLSingleValue(this.responseXML, 'zobrazeno');
                        this.imgAttr['htmlurl'] = getXMLSingleValue(this.responseXML, 'htmlurl');
                        this.imgAttr['imgx'] = getXMLSingleValue(this.responseXML, 'imgx');
                        this.imgAttr['imgy'] = getXMLSingleValue(this.responseXML, 'imgy');
                        this.imgAttr['index'] = getXMLSingleValue(this.responseXML, 'index');
                        this.imgAttr['fotografii'] = getXMLSingleValue(this.responseXML, 'fotografii');
                        if (fotoId)
                        {
                            //getElement('fotoMainLoading').innerHTML = fotoURL.unescapeHtml();
                            onArtLoading();
                            this.img.src = fotoURL.unescapeHtml();
                            this.fotoId = fotoId;
                        }
                        else
                        {
                            if (e=getElement('fotoMainLoading'))
                                e.style.display = 'none';
                        }
                        break;
                    default:
                        if (e=getElement('fotoMainLoading'))
                            e.style.display = 'none';
                }
            }
            else
            {
                if (e=getElement('fotoMainLoading'))
                    e.innerHTML = '<span class="red">'+this.response+'</span>';
            }
        };
        galerieFoto.onError = function() {
            if (e=getElement('fotoMainLoading'))
                e.innerHTML = 'ERROR '+this.responseStatus[0]+': '+this.responseStatus[1];
        }
    galerieFoto.update = function ()
    {
        this.setVar('s', 'galerieFoto');
        this.runAJAX();
    }
    galerieFoto.goImage = function (dir)
    {
        if (e=getElement('fotoMain'))
        {
            this.reqType = 'imageId';
            this.setVar('s', 'galerieFotoRequestFotoId');
            this.setVar('reqDirection', dir);
            this.setVar('fotoId', this.fotoId);
            this.abort();
            this.runAJAX();
            return false;
        }
    }
    
function getXMLSingleValue(xml, tagName)
{
    values = xml.getElementsByTagName(tagName);
    if (values.length>0)
        try {
            value = (typeof(values[0].firstChild.nodeValue)!='undefined') ? values[0].firstChild.nodeValue : false;
            if (!value)
                value = (typeof(values[0].childNodes[0].text)!='undefined') ? values[0].childNodes[0].text : false;
        } catch(ex) {
            value = false;
        }
    else
        return false;
    return (value!='') ? value.unescapeHtml() : false
}

String.prototype.unescapeHtml = function () {
    var temp = document.createElement("div");
    temp.innerHTML = this;
    var result = temp.childNodes[0].nodeValue;
    temp.removeChild(temp.firstChild)
    return result;
}

function currentOpac(id, opacEnd, millisec, setc) {
    //standard opacity is 100
    var currentOpac = 100;
    if (setc)
        currentOpac = 30;
    
    //if the element has an opacity set, get it
    if(document.getElementById(id).style.opacity < 100) {
        currentOpac = document.getElementById(id).style.opacity * 100;
    }

    //call for the function that changes the opacity
    opacity(id, currentOpac, opacEnd, millisec)
} 

function shiftOpacity(id, millisec) {
    //if an element is invisible, make it visible, else make it ivisible
    if(document.getElementById(id).style.opacity == 0) {
        opacity(id, 0, 100, millisec);
    } else {
        opacity(id, 100, 0, millisec);
    }
}

function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / (opacEnd-opacStart));
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd) {
        for(i = opacStart; i >= opacEnd; i--)
        {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    } else if(opacStart < opacEnd) {
        for(i = opacStart; i <= opacEnd; i++)
        {
            setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
            timer++;
        }
    }
}

//change the opacity for different browsers
function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function delay(cmd) {
    if (typeof(axTimer)!='undefined')
        clearTimeout(axTimer);
    axTimer = setTimeout(cmd, 200);
}

function resetSelectOptions(e)
{
    for (i=(e.length - 1); i>=0; i--)
    {
        e.remove(i);
    }
}

function changeSelectOptions(e, xml)
{
    resetSelectOptions(e);
    opts = xml.getElementsByTagName('option');
    for (var i=0; i<opts.length; i++)
    {
        text = (opts[i].firstChild) ? opts[i].firstChild.nodeValue : '';
        try {
            text = opts[i].firstChild.nodeValue;
        }   catch(ex) {
            text = opts[i].childNodes[0].text;
        }
        try {
            value = opts[i].attributes.getNamedItem("value").nodeValue;
        } catch(ex) {
            value = opts[i].attributes[0].nodeValue;
        }
        var opt = document.createElement('option');
        opt.text = text;
        opt.value = value;
        try {
            e.add(opt, null);
        } catch(ex) {
            e.add(opt);
        }
    }
}


    
function gup( name )
{
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
        return "";
    else
        return results[1];
}

