function ShowNextImage() {
    imageIndex = nextIndex;
    GetActualImage().src = basePath + "/" + Images[imageIndex];
    nextIndex++;
    if (nextIndex == Images.length) nextIndex = 0;
    prevIndex++;
    if (prevIndex == Images.length) prevIndex = 0;
}

function ShowPrevImage() {
    imageIndex = prevIndex;
    GetActualImage().src = basePath + "/" + Images[imageIndex];
    nextIndex--;
    if (nextIndex == -1) nextIndex = Images.length - 1;
    prevIndex--;
    if (prevIndex == -1) prevIndex = Images.length - 1;
}

function ShowImageByIndex(index) {
    imageIndex = index;
    GetActualImage().src = basePath + "/" + Images[imageIndex];
    nextIndex = index + 1 >= Images.length ? 0 : index + 1;
    prevIndex = index < 0 ? Images.length - 1 : index - 1;
}

function PopupActualImage() {
    window.open(GetActualImage().src, '', 'status=nno,scrollbars=no');
}

function PopupGallery(title, id) {
    window.open(siteUrl + "/galeria/" + title + "/" + id, 'galleryPopup', 'width=1024,height=600,scrollbar=no,toolbar=no');
}

function GetActualImage() {
    return document.getElementById("actualImage");
}


function getElementsByClass(name) {
    var found = 0;
    var elems = new Array();
    var alltags = document.getElementsByTagName("*");
    if (alltags) {
        for (i=0; i < alltags.length; i++) {
            if (alltags[i].className==name) {
                elems[found++]=alltags[i];
            }
        }
     }
     return(elems);
}


function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, true);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on"+evType, fn);
        return r;
    } else {
        return false;
    }
 }


function classPopupHandler() {
    var elems=getElementsByClass('gallerypopup');
    for(i=0;i<elems.length;i++) {
        if (elems[i].href && elems[i].href!='') {
            addEvent(elems[i],'click', doPopup);
        }
    }
}


function doPopup(ev) {
    // vagy megkapjuk az esemény objektumot, vagy meg kell szereznünk
    ev || (ev = window.event);

    // mely objektum váltotta ki az eseményt?
    var source;
    if (typeof ev.target != 'undefined') {
        source = ev.target;
    } else if (typeof ev.srcElement != 'undefined') {
        source = ev.srcElement;
    } else {
        return(true);
    }

    window.open(source.href,'popup');

    // eseménnyel mi foglalkoztunk, nem kell továbbvinni
    if (ev.preventDefault) {
        ev.preventDefault(); ev.stopPropagation();
    } else {
        ev.cancelBubble = true; ev.returnValue = false;
    }
    return false;
 }

 addEvent(window, 'load', classPopupHandler);
