/*function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        do {
            curleft += obj.offsetLeft;
            curtop += obj.offsetTop;
        } while (obj = obj.offsetParent);
    }
    return [curleft,curtop];
}*/

function setBg(obj, value) {
    if (
        navigator.appVersion.indexOf("MSIE 7")!=-1
        || navigator.appVersion.indexOf("MSIE")==-1
    ){
        // IE7 und "normale" Browser
        obj.style.background = 'url(' + value + ')';
    }
    else {
        // IE6 und abwaerts
        obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + value + "');";
    }
}

function show_popup(pic1, pic2, pic3, pic4, pic5, pic6) {
    //hide_popup();

    // Anzahl der Bilder bestimmen
    var piccount = 0;
    if (pic1) piccount++;
    if (pic2) piccount++;
    if (pic3) piccount++;
    if (pic4) piccount++;
    if (pic5) piccount++;
    if (pic6) piccount++;
    
    // Groesse berechnen
    var innerwidth = piccount * 75 + (piccount - 1) * 5;
    var popupwidth = innerwidth + 10;
    var offsets = getPageSize();
    var xoff = offsets[0] / 2 - popupwidth / 2;
    var yoff = offsets[1] / 2 - 48;
    
    // UI positionieren
    var part = document.getElementById('popupcenter');
    part.style.left = xoff + "px";
    part.style.top = yoff + "px";
    part.style.width = popupwidth + "px";
    
    part = document.getElementById('clicktext');
    part.style.left = (xoff + 5) + "px";
    part.style.top = (yoff + 75) + "px";
    part.style.width = (innerwidth - 20) + "px";
    
    part = document.getElementById('closex');
    part.style.left = (xoff + innerwidth - 10) + "px";
    part.style.top = (yoff + 75) + "px";
    
    // Bilder positionieren
    xoff = xoff + 5;
    yoff = yoff + 5;
    
    var link;
    var bild;
    
    if (pic1) {
        link = document.getElementById('popuplink1');
        link.setAttribute('href', 'pictures/' + pic1 + '.jpg');
        link.setAttribute('rel', 'lightbox[Gallerie]');
        link.style.display = 'block';
        link.style.left = xoff + "px";
        link.style.top = yoff + "px";
        setBg(link, 'pictures/' + pic1 + '.png');
        xoff = xoff + 80;
    }
    
    if (pic2) {
        link = document.getElementById('popuplink2');
        link.setAttribute('href', 'pictures/' + pic2 + '.jpg');
        link.setAttribute('rel', 'lightbox[Gallerie]');
        link.style.display = 'block';
        link.style.left = xoff + "px";
        link.style.top = yoff + "px";
        setBg(link, 'pictures/' + pic2 + '.png');
        xoff = xoff + 80;
    }
    
    if (pic3) {
        link = document.getElementById('popuplink3');
        link.setAttribute('href', 'pictures/' + pic3 + '.jpg');
        link.setAttribute('rel', 'lightbox[Gallerie]');
        link.style.display = 'block';
        link.style.left = xoff + "px";
        link.style.top = yoff + "px";
        setBg(link, 'pictures/' + pic3 + '.png');
        xoff = xoff + 80;
    }
    
    if (pic4) {
        link = document.getElementById('popuplink4');
        link.setAttribute('href', 'pictures/' + pic4 + '.jpg');
        link.setAttribute('rel', 'lightbox[Gallerie]');
        link.style.display = 'block';
        link.style.left = xoff + "px";
        link.style.top = yoff + "px";
        setBg(link, 'pictures/' + pic4 + '.png');
        xoff = xoff + 80;
    }
    
    if (pic5) {
        link = document.getElementById('popuplink5');
        link.setAttribute('href', 'pictures/' + pic5 + '.jpg');
        link.setAttribute('rel', 'lightbox[Gallerie]');
        link.style.display = 'block';
        link.style.left = xoff + "px";
        link.style.top = yoff + "px";
        setBg(link, 'pictures/' + pic5 + '.png');
        xoff = xoff + 80;
    }
    
    if (pic6) {
        link = document.getElementById('popuplink6');
        link.setAttribute('href', 'pictures/' + pic6 + '.jpg');
        link.setAttribute('rel', 'lightbox[Gallerie]');
        link.style.display = 'block';
        link.style.left = xoff + "px";
        link.style.top = yoff + "px";
        setBg(link, 'pictures/' + pic6 + '.png');
        xoff = xoff + 80;
    }
    
    // Overlay positionieren
    var overlay = document.getElementById('my_overlay');
    overlay.style.width = offsets[0] + "px";
    overlay.style.height = offsets[1] + "px";
    
    // Alles anzeigen
    overlay.style.display = 'block';
    
    /*
    Element.setOpacity('popupcenter', '0.0');
    Element.setOpacity('popuplink1', '0.0');
    Element.setOpacity('popuplink2', '0.0');
    Element.setOpacity('popuplink3', '0.0');
    Element.setOpacity('popuplink4', '0.0');
    Element.setOpacity('popuplink5', '0.0');
    Element.setOpacity('popuplink6', '0.0');
    */
    document.getElementById('popup').style.display = 'block';
    /*
    new Effect.Appear('popupcenter', { duration: 0.2, from: 0.0, to: 1.0 });
    new Effect.Appear('popuplink1', { duration: 0.2, from: 0.0, to: 1.0 });
    new Effect.Appear('popuplink2', { duration: 0.2, from: 0.0, to: 1.0 });
    new Effect.Appear('popuplink3', { duration: 0.2, from: 0.0, to: 1.0 });
    new Effect.Appear('popuplink4', { duration: 0.2, from: 0.0, to: 1.0 });
    new Effect.Appear('popuplink5', { duration: 0.2, from: 0.0, to: 1.0 });
    new Effect.Appear('popuplink6', { duration: 0.2, from: 0.0, to: 1.0 });
    */
}

function hide_popup() {
    document.getElementById('popup').style.display = 'none';
    document.getElementById('my_overlay').style.display = 'none';
    
    var obj = document.getElementById('popuplink1');
    obj.setAttribute('rel', 'inactive');
    obj.style.display = 'none';
    
    obj = document.getElementById('popuplink2');
    obj.setAttribute('rel', 'inactive');
    obj.style.display = 'none';
    
    obj = document.getElementById('popuplink3');
    obj.setAttribute('rel', 'inactive');
    obj.style.display = 'none';
    
    obj = document.getElementById('popuplink4');
    obj.setAttribute('rel', 'inactive');
    obj.style.display = 'none';
    
    obj = document.getElementById('popuplink5');
    obj.setAttribute('rel', 'inactive');
    obj.style.display = 'none';
    
    obj = document.getElementById('popuplink6');
    obj.setAttribute('rel', 'inactive');
    obj.style.display = 'none';
}

function init_popup() {
    setBg(document.getElementById('closex'), 'images/closex.png');
}

Event.observe(window, 'load', init_popup, false);
