var imgX
var imgY
var myWindow
var myURL
var myTitle
var myImg
	
function imageDimension () {
	// calculate image size by looking at triggering object
	imgX = this.width; imgY = this.height;
	alert(imgX)
	// open new window with proper dimension
	// IF YOU WANT 'Close this window' TO SHOW, THAN ADD 22 TO imgY, OTHERWISE 0
	myWindow = window.open("","","width="+(imgX)+",height="+(imgY+22))
	// build HTML to be written to window
	myHTML = "<HTML><HEAD><TITLE>"+myTitle+"</TITLE></HEAD><BODY LEFTMARGIN=0 TOPMARGIN=0 MARGINHEIGHT=0 MARGINWIDTH=0>"
	myHTML += "<IMG SRC='"+myURL+"' WIDTH="+imgX+" HEIGHT="+imgY+">"
	myHTML += '<p align="right" style="font-size:10px; font-family:Verdana,Arial;margin-top:4px"><a href="javascript:;" onclick="window.close()">Sluit dit venster</a>&nbsp;&nbsp;</p>'
	myHTML += "</BODY></HTML>"
	myWindow.document.write(myHTML)
	myWindow.document.close()
}

function openImg(URL, xTitle) {
	//Modify URL: change "thumb" into "photo" to point to full size photo
	//var regexp = /thumb/i
	//URL = URL.replace(regexp,"photo")
	if(myWindow != null) {
		myWindow.close()
	}
	// store url and window title in global variables
	myURL = URL
	myTitle = xTitle
	// when image is source of myImg is loaded, execute function imageDimension
	// which calculates the size of the picture and build the new window
	myImg = new Image()
	myImg.onload = imageDimension
	// load the image, which triggers the function imageDimension
	myImg.src = URL
}

