var imgWin;

function imgView(sender) {
    var img = new Image();
    img.onload = imgOnLoad;
    img.src = sender.href;
    return false;
}

function imgOnLoad() {
    var imgP = this.width / this.height;
    var srcP = (screen.availWidth - 10) / (screen.availHeight - 30);
    var imgHeight = this.height;
    var imgWidth = this.width;
    var imgLeft = (screen.availWidth >> 1) - (imgWidth >> 1);       // x div 2
    var imgTop = (screen.availHeight >> 1) - (imgHeight >> 1);

    // obr. je sirsi nez obrazovka -> pomerem jej zmensime
    if ((imgLeft < 0 || imgTop < 0) && (imgP > srcP)) {
        imgLeft = 0;
        imgWidth = screen.availWidth - 10;
        imgHeight = imgWidth / imgP;
        imgTop = (screen.availHeight >> 1) - (imgHeight >> 1);
    }
    // obr. je vyssi nez obrazovka -> pomerem jej zmensime
    if ((imgLeft < 0 || imgTop < 0) && (imgP < srcP)) {
        imgTop = 0;
        imgHeight = screen.availHeight - 30;
        imgWidth = imgHeight * imgP;
        imgLeft = (screen.availWidth >> 1) - (imgWidth >> 1);
    }

    if (imgWin != null)
        imgWin.close();
    imgWin = window.open('', 'imgview', 
        'height='+ imgHeight +','+
        'left='+ imgLeft +','+
        'top='+ imgTop +','+
        'width='+ imgWidth +','+
        'dependent=0,directories=0,location=0,hotkeys=0,menubar=0,'+
        'personalbar=0,resizable=0,scrollbars=0,status=0,titlebar=0,toolbar=0');
    imgWin.document.open('text/html', 'replace');
    imgWin.document.write(
        '<HTML>' +
        '<HEAD><TITLE>Antikvariat Bretschneider</TITLE>'+
        '</HEAD>');
    imgWin.document.write(
        '<BODY BGCOLOR="#495578" ');
    if (document.getElementById)
        imgWin.document.write(
              'ONLOAD="document.getElementById(\'iImage\').style.display = \'\'; '+
                      'document.getElementById(\'iInfo\').style.display = \'none\';"');
    imgWin.document.write(
              'STYLE="background-color:#ffffff; margin: 0;">' +
        '<DIV ID="iImage"><IMG ALT="close / zavrit" HEIGHT="'+ imgHeight +'" ONCLICK="window.close();" SRC="'+ this.src +'" TITLE="close / zavrit" WIDTH="'+ imgWidth +'"></DIV>');
    if (document.getElementById)
        imgWin.document.write(
        '<DIV ID="iInfo" STYLE="display: none;"><BR><BR><BR><CENTER><B>Please wait ... / Prosim cekejte ...</B></CENTER></DIV>' +
        '<SCRIPT> document.getElementById(\'iImage\').style.display = \'none\'; document.getElementById(\'iInfo\').style.display = \'\'; </SCRIPT>');
    imgWin.document.write(
        '</BODY>' +
        '</HTML>');
    imgWin.document.close();
    imgWin.focus();
    return true;
}


/* End of file. */