/*
tested and functional under:
- IE5
- NN4
- NN6
- Mozilla1

Opera doesn't open window, if it is already opened.

*/

var win4Pic = null;

function picWin(location,picWidth,picHeight,comment) {

    var closeMsg = "Kliknutím na obrázek se okno zavře.";
	
	comment = (comment) ? comment : "Obrázek";

	if (win4Pic && !win4Pic.closed) {
		win4Pic.close();
	}
	
	// Some browsers can't open window with width or height less than 100px.
	if (picWidth < 100) {picWidth = 100}
	if (picHeight < 100) {picHeight = 100}

	/*
	If we want to center the window, we need to know the screen resolution.
	Then, if our picture is smaller than screen, we can place it to the center.
	If it is bigger, then we will place it to the top left corner.
	*/

    availHeight = screen.height;
    availWidth = screen.width;

    if (availHeight < picHeight) {posTop = 0;}
    else {posTop = (availHeight - picHeight)/2;}

    if (availWidth < picWidth) {posLeft = 0;}
    else {posLeft = (availWidth - picWidth)/2;}

	/*
	Construction of window attributes and then opening the window with these
	attributes.
	*/
    atts = "width=" + picWidth + ",height=" + picHeight + ",directories=0,location=0,menubar=0,resizable=0,scrollbars=0,status=0,toolbar=0,top=" + posTop + ",left=" + posLeft;        
    win4Pic = window.open('','win4Pic',atts);

	/*
	Inserting the content to the window. Removing any borders (using BODY
	attributes and borderless table). If picture is too small to fit window
	(width or height less than 100px), placing it to the center. Closing the
	window onClick and onBlur.
	*/
    win4Pic.document.open();
    win4Pic.document.write("<html><head><title>" + comment + "</title></head><body style='margin: 0px; padding: 0px;' marginwidth='0' marginheight='0' leftmargin='0' topmargin='0' onLoad='void(0);    '><table cellpadding='0' cellspacing='0' border='0' width='100%' height='100%'><tr><td align='center' valign='middle'><a href='#' onClick='self.close()'><img src='" + location + "' border='0' width='" + picWidth + "' height='" + picHeight + "' alt='" + closeMsg + "'></a></td></tr></table></body></html>");
    win4Pic.document.close();
	
	return true;
}