/*
 © Struppi
 Mail: struebig@gmx.net
 URL: http://javascript.jstruebig.de/source/popup.html

 letzte Änderung: 26.07.2005

 Beschreibung:
 -------------
 Ein Skript um ein Fenster in der Größe eines Bildes öffnen.

 Einbinden:
 ----------
 <script src="popup.js"></script>
 <A HREF="grosses_bild.jpg" target="bild"
 onclick="return showBild(this, 'name_des_Bildes');"
 ><IMG SRC="kleines_bild.jpg"></A>
*/
///////////////////////////////////////////////////////////
// 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, title)
{
    if(!a.target) a.target = "BildFenster";
    var default_width   = 400;
    var default_height  = 200;

    if(popup_close == 'blur' || !showFenster || showFenster.closed ||
    typeof showFenster.closed == 'undefined' // Opera 8 Bugfix
    )
    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); 
    
	//alert(title); //TEST
	
    return false;
}

///////////////////////////////////////////////////////////
// fitWin(Image, window) - wird aus dem Popup aufgerufen.
function fitWin(i, win)
{
    if(i.ready) return;
    i.ready = i.width > 0;
    var w_s = getWinSize(win);
    var r = 2 * parseInt(rahmen);
    var w = i.width > screen.width ? screen.width : i.width;
    var h = i.height > screen.height  ? screen.height  : i.height;
    if(i.width > screen.height || i.height > screen.width ) 
    {
    win.document.getElementsByTagName('body')[0].style.overflow = 'scroll';
    }

    win.resizeBy((w - w_s.width + ( 2 * abstand_w) + r), (h - w_s.height + ( 2 * abstand_h) + r) );

    if(center_popup && !window.opera)
    {
         w_s = getWinSize(win);
         win.moveTo(( screen.width - w_s.width) / 2, (screen.height - w_s.height) / 2 );
    }
    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
    + '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 galleryimg="no" src="' + src + '" alt="" title="' + title + '"'
    + '>' + NL
    + (popup_close.toLowerCase() == 'click' ? '<script> document.images[0].onclick=function(){window.close()};</script>' : '')
    + '<\/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();
}


function openWindow(URL,b,h,was)
{

  if (navigator.appVersion.indexOf('Mac')!=-1 && navigator.appName.indexOf('Explorer')!=-1) {
    b =b- 15;
    h =h- 15;
  }
    var xPos = (screen.availWidth - b) / 2
    var yPos = (screen.availHeight - h ) / 2
	  //var yPos = 155
	  ma = window.open(URL,'popwin','width='+b+',height='+h+',scrollbars=no,toolbar=no,status=no,menubar=no,screenX='+xPos+',screenY='+yPos+',left='+xPos+',top='+yPos,scrollbar=0)
}