/****************************************
 * Name: sm@rtLoader 2.0
 * Beschreibung: Lädt eine Grafik in einem neuen Fenster
 *
 * © 2002 by Steffen Heinzelmann
 * mail@steffenheinzelmann.de
 ****************************************/

myImgData = new imgData();

/* imgData Objekt */
function imgData() {
    this.beschr="";       //Bildbeschreibung
    this.winTitle="";     //Fentertitel
    this.name = ""        //Bildname
}

function startLoader(loadImg, winTitle, beschr) {
    myImgData.beschr=beschr;
    myImgData.winTitle=winTitle;
    myImgData.name=imgName(loadImg);

    img = new Image();
    img.src=loadImg;

    controller(loadImg);
}

function startLoaderSize(loadImg, winTitle, beschr, imgWidth, imgHeight) {
    myImgData.beschr=beschr;
    myImgData.winTitle=winTitle;
    myImgData.name=imgName(loadImg);
    showImageSize(loadImg,imgWidth,imgHeight)
}

function controller(loadImg) {
    if((img.width!=0)&&(img.height!=0)){
    showImage(loadImg);
    }
    else{
       aufruf="controller('"+loadImg+"')";
       intervall=setTimeout(aufruf,10);
    }
}

function showImageSize(loadImg,imgWidth,imgHeight) {
       width=imgWidth;
       height=imgHeight;
       winHeight=optWinHeight(myImgData.beschr,width)+height;
       win=window.open(loadImg,imgName(loadImg),'resizable=yes,width='+(width+40)+',height='+winHeight);
       win.document.open();
       win.document.write(imgHtml(loadImg,myImgData.beschr,myImgData.winTitle,width,height));
       win.focus();
       win.document.close();
}

function showImage(loadImg) {
       width=img.width;
       height=img.height;
       winHeight=optWinHeight(myImgData.beschr,width)+height;
       win=window.open(loadImg,imgName(loadImg),'resizable=yes,width='+(width+40)+',height='+winHeight);
       win.document.open();
       win.document.write(imgHtml(loadImg,myImgData.beschr,myImgData.winTitle,width,height));
       win.focus();
       win.document.close();

}
function zoom100() {
    myImgData.beschr=beschr;
    winHeight=optWinHeight(myImgData.beschr,orgWidth)+orgHeight+30;
    window.resizeTo(orgWidth+50,winHeight);
    document.bild.width=orgWidth;
    document.bild.height=orgHeight;
}


function zoom(inout) {

    wert=document.bild.width*0.05*inout                   // Verkleinerung-Vergrößerungsfaktor
    myImgData.beschr=beschr;
    xfakt=Math.max(document.bild.width,document.bild.height)/Math.min(document.bild.width,document.bild.height);

    if (document.bild.width>document.bild.height) {
          width=document.bild.width+wert*xfakt;
          height=document.bild.height+wert;
          document.blind.width+=wert*xfakt;
    }
    else {
          width=document.bild.width+wert;
          height=document.bild.height+wert*xfakt;
          document.blind.width+=wert;
    }

    wert*=(xfakt*inout);
    if (window.width>200) {
       winHeight=optWinHeight(myImgData.beschr,width)
       window.resizeTo(width+50,(height+winHeight+wert));
    }
    if (width>150 || height>150) {
       document.bild.width=width;
       document.bild.height=height;
    }
    else alert("Geringster Verkleinerungsfaktor erreicht!");
}

/***************************
 *  imgHtml
 */
 function imgHtml(img,beschr,winTitle,imgWidth,imgHeight) {
                html="<hmtl><head><title>bergfelden.de</title></title>";
                html+="<link rel='stylesheet' href='/css/formular.css' type='text/css'>";
                html+="<script language='JavaScript' src='/share/scripts/smartloader.js' type='text/javascript'></script>";
                html+="<script language='JavaScript'>\n";
                html+="<!--\n";
                html+="var beschr = '"+beschr+"';\n";
                html+="var orgWidth = "+imgWidth+";\n";
                html+="var orgHeight = "+imgHeight+";\n";
                html+="//-->\n";
                html+="</script>\n";
                html+="</head>";
                html+="<body leftmargin=0 topmargin=0 marginheight=0 marginwidth=0 bgcolor='#F9F9F9'>";
                html+="<table width='100%' height='100%'border=0 cellpadding=0 cellspacing=0>";
                html+="<tr>";
                html+="<td><img src='/share/images/blind.gif' width=20 height=10></td>";
                html+="<td><img src='/share/images/blind.gif' name='blind' width=20 height=1></td>";
                html+="<td><img src='/share/images/blind.gif' width=20 height=1></td>";
                html+="</tr>";
                html+="<tr valign='top'>";
                html+="<td></td>";
                html+="<td>";
                      html+="<div style='font-family:arial;font-size:12px;color:#555555'><b>"+winTitle+"</b></div>";
                      html+="<table width='100%' border=0 cellpadding=0 cellspacing=0>";
                      html+="<tr valign='top'>";
                      html+="<td style='background-image:url(/share/scripts/loading.gif);background-repeat:no-repeat;'>";
                      html+="<img src='"+img+"' name='bild' width='"+imgWidth+"' height='"+imgHeight+"' hspace='0' vspace='0'>";
                      html+="</td></tr>";
                      html+="<tr valign='top'><td style='padding-top:4px;'>";
                      if(beschr!=''){
                        html+="<div style='font-family:Arial,Verdana;font-size:11px;color:#555555;line-height:12px;'>";
                        html+=beschr;
                        html+="</div><img src='/share/images/blind.gif' width=20 height=5>";
                      }
                      html+="</td></tr>";
                      html+="</table>";
                html+="</td></tr>";
                html+="<tr valign='bottom'>";
                html+="<td></td>";
                html+="<td>";
                      html+="<table width='100%' border=0 cellpadding=0 cellspacing=0>";
                      html+="<tr valign='top'>";
                      html+="<td align='right'>";
                      if (navigator.appName=='Microsoft Internet Explorer')
                         html+="<input type='button' class='b_dgr' value='&nbsp;-&nbsp;' onclick='zoom(-1)' onFocus='if(this.blur)this.blur()' title='Bild verkleinern'>&nbsp;<input type='button' class='b_dgr' value='&nbsp;1:1&nbsp;' onclick='zoom100()' onFocus='if(this.blur)this.blur()' title='Originalbildgröße'>&nbsp;<input type='button' class='b_dgr' value='&nbsp;+&nbsp;' onclick='zoom(1)' onFocus='if(this.blur)this.blur()' title='Bild vergrößern'>&nbsp;&nbsp;";
                         html+="<input type='button' class='b_o' value='&nbsp;Schließen' onclick='window.close()' onFocus='if(this.blur)this.blur()' title='Fenster schließen'>";
                      html+="</td>";
                      html+="</tr>";
                      html+="<tr><td><img src='/share/images/blind.gif' width=20 height=5></td></tr>";
                      html+="</table>";
                html+="</td>";
                html+="<td></td></tr>";
                html+="</table>";
                html+="</body></html>";
        return html;
 }


//Hilfsmethoden *****************************************************


/* Ermittelt aus dem Pfad den Dateinamen ohne Dateiendung */
function imgName(imgSrc) {
        x=imgSrc.lastIndexOf("/");
        if(x>0) x++;
        return imgSrc.substring(x,(imgSrc.length-4));
}

/* Optimale Fensterhöhe */
function optWinHeight(imgBeschr,imgWidth) {
        x = imgBeschr.length;
        imgWidth=imgWidth;
        i=0;
        b=0;
        temp=imgBeschr.substring(i,x);
        while(i != -1) {
           temp=temp.substring(i,x);
           i = temp.search(/<br>/);
           if(i > 0){
                b+=1; i+=4;
           }
        }
        if (b<1) b=1;
        z=x/(imgWidth/5.3);
        if (z<1) z=1;
        z+=b;
        return Math.round((z*20)+45);
}
