/*
Funkce na otevření externího okna do středu obrazovky do kterého  se  načte
obrázek a okno se následně zvětší na velikost  obrázku. Pokud je obrázek
větší jak  rozlišení  obrazovky,  okno se roztáhne pouze na tuto velikost .

Použití:
Nejdříve načteme funkci do stránky.  Mezi  tagy <head></head> vložíme:
<script src="js/extpict.js" type="text/javascript"></script>

Následně můžeme volat funkci s parametrem, kterým je obrázek, např.:
<a href="javascript:extpict('obrazek.gif');">Odkaz</a> nebo
<a href="obrazek.gif" target="_blank" onclick="return extpict('obrazek.gif');">Odkaz</a>

historie:

0.3 - možnost vložit velký obrázek jako druhý parametr pro volbu "kvalitní tiskový obrázek"

Verze 0.3; Vytvořil Pavel Černý pro NAUSUS (c) 2002
(extpict@beltaine.cz; nausus@nausus.cz)
*/

function extpict(picture, bigpict)
{	var text      = '#ffffff', 
	titlename = 'BARENTZ',
	defwidth  = 350, 
	defheight = 350, 
	bgcolor   = '#f3fcf8', 	
	alttext   = 'Close window',
	winname   = ''; // jmeno oteviraneho okna

	// fyzické rozlišení obrazovky
	scw = window.screen.availWidth-30;
	sch = window.screen.availHeight;

	// pozice na středu otevřeného oknas
	wleft = scw/2-defwidth/2;
	wtop = sch/2-defheight/2;
	
	Preview = window.open('', winname, 'resizable=1, status=0, menubar=0, location=0, directories=0, scrollbars=1, width='+defwidth+', height='+defheight+', top='+wtop+', left='+wleft);
	Preview.document.write('<html><head><title>'+titlename+'</title><link rel="STYLESHEET" type="text/css" href="leicagallery.css"></head>');
	if (bigpict) Preview.document.write('<script src="js/extpict.js" type="text/javascript"></script>');
	Preview.document.write('\n<script language="JavaScript">\n');
	Preview.document.write('function sizeImg(){\n');
	Preview.document.write('winwidth=document.getElementById("foto").width+30;\n');
	Preview.document.write('winheigh=document.getElementById("foto").height+31;\n');
	Preview.document.write('if (winwidth>'+scw+') winwidth='+scw+';\n'); // podmínky redukující případnou velikost okna podle rozlišení
	Preview.document.write('if (winheigh>'+sch+') winheigh='+sch+';\n');
	Preview.document.write('wtop='+(sch/2)+'-winheigh/2;\n'); // vypočítám novou pozici okna
	Preview.document.write('wleft='+(scw/2)+'-winwidth/2;\n');
	Preview.document.write('if (wtop<0) wtop=0;\n');
	Preview.document.write('if (wleft<0) wleft=0;\n');
	Preview.document.write('window.moveTo(wleft, wtop);\n'); // změna velikosti okna
	Preview.document.write('window.resizeTo(winwidth,winheigh+'+((bigpict) ? 20 : 0)+');\n'); // změna velikosti okna
	Preview.document.write('}\n');
	Preview.document.write('</script>\n');
	Preview.document.write('<body onLoad="sizeImg()" style="margin:0px;" link="'+text+'" vlink="'+text+'" bgcolor="'+bgcolor+'" text="'+text+'" topmargin="0" leftmargin="0" marginheight="0" marginwidth="0" rightmargin="0" bottommargin="0">');
	Preview.document.write('<a href="javascript:window.close();">');
	Preview.document.write('<img src="' + picture + '" border="0" id="foto" alt="' + alttext + '" hspace="0" vspace="0">');
	Preview.document.write('</a>');
	if (bigpict) Preview.document.write('<br /><div align="right"><a href="'+bigpict+'" target="_blank">Printable Picture Size</a>&nbsp;&nbsp;</div>');
	Preview.document.write('</body></html>');
	Preview.document.close();

	return false;
}
