/*
  использование
  <a href="disco.jpg" target="_blank" onClick="return
imgOpen(this.href,400,300,'Я на дискотеке');"><img src="disco_small.gif"
width="80" height="60" alt="Я на дискотеке - 200 Кбайт" border="0"></a>
*/

function imgOpen(imgURL,imgWidth,imgHeight,Title) {
    var imgWndw=window.open('','_blank','width='+imgWidth+',height='+
      imgHeight+',toolbar=no,menubar=no,location=no,status=no,'+
      'resizable=yes,scrollbars=no');
    var imgTitle=(Title)?Title:imgURL+": "+imgWidth+'x'+imgHeight;
    with (imgWndw.document){
      open();
      write('<ht'+'ml><he'+'ad><ti'+'tle>'+imgTitle+'</ti'+'tle>'+
      '</he'+'ad><bo'+'dy leftmargin="0" topmargin="0" '+
      'rightmargin="0" bottommargin="0" marginwidth="0" '+
      'marginheight="0"><a href="#" onclick="window.close();"><img src="'+imgURL+'" width="'+imgWidth+
      '" height="'+imgHeight+'" border="0" alt="'+imgTitle+
      '"></a></bo'+'dy></ht'+'ml>');
      close();
    }
    return false
}

var aIndex=0;
var preload_thumb = new Array();
var isError = 0;

function imgOpen2(imgURL) {
	var imgWidth=700;
	//var imgHeight=1000;
	var windWidth = imgWidth + 20;
	/* aIndex++;
  preload_thumb[aIndex]=new Image() ;
 // preload_thumb[aIndex].onerror=noImage;
  preload_thumb[aIndex].src=imgURL;
  preload(imgURL);
  //if(isError==0){chkLoading()};
	var imgWidth = preload_thumb[aIndex].width;
	
	var imgHeight = preload_thumb[aIndex].height; */
  var imgWndw=window.open('','_blank','width='+windWidth+',height=600,toolbar=no,menubar=no,location=no,status=no,'+
      'resizable=yes,scrollbars=yes');
    var imgTitle='Просмотр картинки';
    with (imgWndw.document){
      open();
      write('<ht'+'ml><he'+'ad><ti'+'tle>'+imgTitle+'</ti'+'tle>'+
      '</he'+'ad><bo'+'dy style="margin:0;padding:0;text-align:center"><a href="#" onclick="window.close();"><img src="'+imgURL+'" width="'
	  +imgWidth+
	  '" border="0" alt="'+imgTitle+
      '"></a></bo'+'dy></ht'+'ml>');
      close();
    }
    return false
}
function chkLoading(){if(preload_thumb[aIndex].complete==true){nextImage();} else{setTimeout("chkLoading()",100);}}

function nextImage(){ }

function noImage(){ isError=1; alert('No image');setTimeout("isError=0;preloadImage()",100); }

function preload(image) {
    if (typeof document.body == "undefined") return;
    try {
        var div = document.createElement("div");
        var s = div.style;
        s.position = "absolute";
        s.top = s.left = 0;
        s.visibility = "hidden";
        document.body.appendChild(div);
        div.innerHTML += "<img src=\"" + image + "\" />";
    } catch(e) {
        // Error. Do nothing.
    }
}

