/*
 ----------------------------------------------------
 * © 2003 Struppi                                   *
 * Mail: struebig@gmx.net                           *
 ----------------------------------------------------
*/

//===================================================================
// Globale Definitionen
//===================================================================
function globals()
{
    this.showWarteFenster = true;
    this.wWinH = 100; // Die Breite des warten Fenster
    this.wWinB = 250;
    this.wText = "<center><b>Bild wird geladen...<br>Bitte warten !</b></center>";

    this.rahmenX = 0;
    this.rahmenY = 0;
    this.bgColor = 'white';

    this.wWin = null;
    this.sWin = null;
}

//===================================================================
// showImage(url, name) - die Hauptfunktion.
//===================================================================
function showImage(link)
{
    // Erst das alte Fenster schließen
    if(GLOBAL.sWin != null && typeof GLOBAL.sWin.close != 'undefined')
    {
         GLOBAL.sWin.close();
         GLOBAL.sWin = null;
         //setTimeout('showImage(' + link + ')', 100);
         //return false;
    }
    // Das Bild laden
    var img = new Image();
    img.onload = openPopUp;
    img.onerror = FEHLER;

    img.alt = link.title ? link.title : "Grosses Foto";
    img.target = link.target ? link.target : "foto";
    img.src = link.href;

    //********************************
    // Das "warten.." Fenster öffnen
    //********************************
    if(!img.complete && GLOBAL.showWarteFenster)
    {
         GLOBAL.wWin = popUp("about:blank", "warte", GLOBAL.wWinB, GLOBAL.wWinH);
         var doc = GLOBAL.wWin.document;
         doc.open();
         doc.write(GLOBAL.wText);
         doc.close();
    }
    return false;
}

//-----------------------------------------------
// Nach dem onload ein Fenster öffnen
//-----------------------------------------------
function openPopUp()
{
    // Das warte... Fenster schliessen
    if(GLOBAL.wWin != null && typeof GLOBAL.wWin.close != 'undefined')
    {
         GLOBAL.wWin.close()
         GLOBAL.wWin = null;
    }
    var text = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">\n'
    + '<HTML>\n<HEAD>\n' + '<TITLE>' + this.alt + '</TITLE>\n'
    + '<STYLE type="text/css">\n'
    + 'body{\nmargin:0;padding:0;text-align:center;'
    + 'background-color:' + GLOBAL.bgColor + ';\n}\n'
    + '</STYLE>\n' + '</HEAD>\n' + '<body>\n'
    + '<img src="' + this.src + '" alt="' + this.alt +'" border=0>'
    + '\n</body></html>';

    GLOBAL.sWin = popUp("about:blank", this.target , this.width + GLOBAL.rahmenX, this.height + GLOBAL.rahmenY);
    var doc = GLOBAL.sWin.document;
    doc.open();
    doc.write(text);
    doc.close();
}
//-----------------------------------------------
// Ein popup öffnen
//-----------------------------------------------
function popUp(url, name, 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, name, tmp.join(','));
}
//-----------------------------------------------
// FEHLER
//-----------------------------------------------
function FEHLER()
{
    var text =  "\nFehler !!!\n\nDas Bild mit der URL:\n"
    + this.src + ".\nkonnte nicht geladen werden.";

    closeAll();
    alert(text);
}
//-----------------------------------------------
// und am schluss alle Fenster schliessen.
//-----------------------------------------------
window.onunload = closeAll;

function closeAll()
{
    if(GLOBAL.wWin != null && typeof GLOBAL.wWin.close != 'undefined') GLOBAL.wWin.close();
    if(GLOBAL.sWin != null && typeof GLOBAL.sWin.close != 'undefined') GLOBAL.sWin.close();
    GLOBAL.wWin = GLOBAL.sWin = null;
}
//===================================================================
// globale, nicht veränderbare Werte
//===================================================================
var GLOBAL = new globals();
