
// Globale Definitionen
var popup_bgColor = '#fff';
var rahmen        = '1px solid black';
var abstand_w      = 1;
var abstand_h      = 1;
var center_popup  = true;
var popup_close   = 'click'; // Mögliche Werte: 'blur', 'click', ''

// showBild(a, name) - die Hauptfunktion.
var default_site = window.opera ? '' : '';
function showBild(a)
{
    if(!a.target) a.target = "BildFenster";
    var default_width   = 400;
    var default_height  = 200;

    if(popup_close == 'blur' || !showFenster || showFenster.closed)
    showFenster = popUp(default_site, a.target, default_width, default_height);

    showFenster.document.open();
    showFenster.document.write( getHTML(a.href, a.title || a.alt) );
    showFenster.document.close();
    showFenster.focus();

    var img = new Image;
    img.ready = false;
    img.onload = function() { fitWin(this, showFenster); };
    img.src = a.href;
    if(img.complete) fitWin(img, showFenster);

    return false;
}
///////////////////////////////////////////////////////////
// fitWin(Image, window) - wird aus dem Popup aufgerufen.
function fitWin(i, win)
{
    if(i.ready) return;
    i.ready = true;
    var w = i.width;
    var h = i.height;
    var w_s = getWinSize(win);
    var r = 2 * parseInt(rahmen);

    win.resizeBy((w - w_s.width + ( 2 * abstand_w) + r), (h - w_s.height + ( 2 * abstand_h) + r) );

    if(center_popup)
    {
         win.moveTo( 10, 10 );
    }
    win.focus();
}

// getHTML(bild, titel, farbe)
function getHTML(src, title, bgcolor)
{
    if(!title) title = 'kein Titel';
    if(!bgcolor) bgcolor = popup_bgColor;
    var NL = "\n";

    var text = '<!DOCTYPE HTML PUBLIC "-\/\/W3C\/\/DTD HTML 4.01\/\/EN" "http:\/\/www.w3.org\/TR\/html4\/strict.dtd">\n'
    + '<HTML>\n<HEAD>' + NL
    + '<TITLE>' + title + '<\/TITLE>' + NL
    + '<STYLE type="text/css">' + NL
    + 'body{margin:0;padding:0;overflow:hidden;' + NL
    + 'background-color:' + popup_bgColor + NL
    + ';}' + NL
    + 'img{padding:0;'
    + (rahmen ? 'border:' + rahmen + ';'  : '')
    + 'margin-top:' + abstand_h +'px;' + NL
    + 'margin-bottom:' + abstand_h +'px;' + NL
    + 'margin-left:' + abstand_w +'px;' + NL
    + 'margin-right:' + abstand_w +'px;' + NL
    + '}\n' + NL
    + '<\/STYLE>' + NL
    + '<\/HEAD>' + NL
    + '<body'
    + (popup_close.toLowerCase() == 'blur' ? ' onblur="self.close();"' : '')
    + '>'
    + '<img src="' + src + '" title="Fenster schließen durch Mausklick." alt="Fenster schließen durch Mausklick."'
    + (popup_close.toLowerCase() == 'click' ? ' onclick="window.close();"' : '')
    + '>' + NL
    + '<\/body><\/html>'
    ;
    return text;
}
// Ein popup öffnen
function popUp(url, fname, w, h)
{
    var tmp = new Array();
    tmp[tmp.length] = 'resizable=yes';
    tmp[tmp.length] = 'scrollbars=no';
    if(w) tmp[tmp.length] = 'width=' + w;
    if(h) tmp[tmp.length] = 'height=' + h;

    return window.open(url, fname, tmp.join(','));
}
// getWinSize(window)
function getWinSize(win)
{
    if(!win) win = window;
    var s = new Object();
    if(typeof win.innerWidth != 'undefined')
    {
        s.width = win.innerWidth;
        s.height = win.innerHeight;
    }
    else
    {
         var obj = getBody(win);
         s.width = parseInt(obj.clientWidth);
         s.height = parseInt(obj.clientHeight);
    }
    return s;
}
// Der IE hat 2 verschiedene Objekte für den strict und quirks Mode.
function getBody(w)
{
    return (w.document.compatMode && w.document.compatMode == "CSS1Compat") ? w.document.documentElement : w.document.body || null;
}
var showFenster = null;

// ... und am schluss alle Fenster schliessen.
window.onunload = function ()
{
    if(showFenster && !showFenster.closed) showFenster.close();
}

