var imgViewWindow;

function imgView(sender) {
    var img = new Image();
    img.onload = imgViewOnLoad;
    img.src = sender.href ? sender.href : sender.src;
    return false;
}

function imgViewOnLoad() {
    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 (imgViewWindow != null)
        imgViewWindow.close();
    imgViewWindow = window.open('', 'imgview', 
        'height='+ imgHeight +','+
        'left='+ imgLeft +','+
        'top='+ imgTop +','+
        'width='+ imgWidth +','+
        'dependent=0,directories=0,location=0,hotkeys=0,menubar=0,'+
        'personalbar=0,resizable=1,scrollbars=0,status=0,titlebar=0,toolbar=0');
    imgViewWindow.document.open('text/html', 'replace');
    imgViewWindow.document.write(
        '<HTML>' +
        '<HEAD>'+
            '<META HTTP-EQUIV="Content-Type" content="text/html; charset=utf-8">'+
            '<TITLE>COOL AGENT</TITLE>'+
        '</HEAD>');
    imgViewWindow.document.write(
        '<BODY BGCOLOR="#ffffff" ');
    if (document.getElementById)
        imgViewWindow.document.write(
              'ONLOAD="document.getElementById(\'iInfo\').style.display=\'none\';'+
                      'document.getElementById(\'iInfo\').style.visibility=\'hidden\';'+
                      'document.getElementById(\'iImage\').style.display=\'block\';'+
                      'document.getElementById(\'iImage\').style.visibility=\'visible\';" ');
    imgViewWindow.document.write(
              'STYLE="background-color:#ffffff;margin:0;">');
    if (document.getElementById)
        imgViewWindow.document.write(
        '<DIV ID="iInfo"><BR><BR><BR><CENTER><B>Please wait ... / Prosím čekejte ...</B></CENTER></DIV>'+
        '<DIV ID="iImage" STYLE="display:none;visibility:hidden;"><IMG ALT="close / zavřít" ONCLICK="window.close();" SRC="'+ this.src +'" TITLE="close / zavřít"></DIV>');
        //'<SCRIPT>document.getElementById(\'iImage\').style.display=\'none\';document.getElementById(\'iInfo\').style.display = \'\';</SCRIPT>'
    else
        imgViewWindow.document.write(
        '<IMG ALT="close / zavřít" ONCLICK="window.close();" SRC="'+ this.src +'" TITLE="close / zavřít">');
        //'<IMG ALT="close / zavřít" HEIGHT="'+ imgHeight +'" ONCLICK="window.close();" SRC="'+ this.src +'" TITLE="close / zavřít" WIDTH="'+ imgWidth +'">'
    imgViewWindow.document.write(
        '</BODY>' +
        '</HTML>');
    imgViewWindow.document.close();
    imgViewWindow.focus();
    return true;
}


/* End of file. */

