/**
 * Elhelyezi az openPopup funkciót a popup osztályú linkek onclick eseményén
 */
function managePopup() {
    var popup = getElementsByClass("popup");    
    for(i=0; i<popup.length; i++) {
        if (popup[i].href && popup[i].href != "") {
            addEvent(popup[i], "click", openPopup);
        }
    }
    
    var popup = getElementsByClass("galleryPopup");    
    for(i=0; i<popup.length; i++) {
        if (popup[i].href && popup[i].href != "") {
            addEvent(popup[i], "click", openGalleryPopup);
        }
    }
}

/**
 * Megnyitja a linket popup ablakként
 *
 * @param   Object      event       Esemény objektum
 */
function openPopup(event) {
    // Esemény objektum meghatározása, ha nem kapta meg a funkció
    event || (event = window.event);
    
    // Esemény forrásának felderítése
    var source;
    if (typeof event.target != "undefined") {
        source = event.target;
    } else if (typeof event.srcElement != "undefined") {
        source = event.srcElement;
    } else {
        return(true); 
    }
    
    source = getParent(source, "a");
    window.open(source.href, "", "scrollbars, width=780, height=560, left="
            +(screen.availWidth-780)/2 + ", top=" +(screen.availHeight-560)/2);
    
    // Esemény elpusztítása, a link ne működjön
    if (event.preventDefault) {
        event.preventDefault(); event.stopPropagation();
    } else {
        event.cancelBubble = true; 
        event.returnValue = false;
    }
    return false;
}

/**
 * Megnyitja a linket galéria popup ablakként
 *
 * @param   Object      event       Esemény objektum
 */
function openGalleryPopup(event) {
	width = 780;
	height = 560;
    // Esemény objektum meghatározása, ha nem kapta meg a funkció
    event || (event = window.event);
    
    // Esemény forrásának felderítése
    var source;
    if (typeof event.target != "undefined") {
        source = event.target;
    } else if (typeof event.srcElement != "undefined") {
        source = event.srcElement;
    } else {
        return(true); 
    }
    
    href = getParent(source, "a").href;
    
    query = href.split("/");
    
    imageName = query.pop();
    // Leveszi a kép kiterjesztését
    imageName = imageName.substring(0, imageName.lastIndexOf("."));
    galleryID = query.pop();
    
    window.open(siteUrl+"/galerianezegeto/"+galleryID+"/"+imageName, "picture", 
            "location=0, scrollbars=1, status=1, titlebar=1, toolbar=0, directories=0, menubar=0, screenX=0, screenY=0, width=" + width + ", height=" + height + 
            ", left=" +(screen.availWidth-width)/2 + 
            ", top=" + (screen.availHeight-height)/2);
    
    // Esemény elpusztítása, a link ne működjön
    if (event.preventDefault) {
        event.preventDefault(); event.stopPropagation();
    } else {
        event.cancelBubble = true; 
        event.returnValue = false;
    }
    return false;
}