// JK Pop up image viewer script- By JavaScriptKit.com
// Visit JavaScript Kit (http://javascriptkit.com)
// for free JavaScript tutorials and scripts
// This notice must stay intact for use
//modified by Ryan Ernst for dynamic sizing

function detectexist(obj){
	return (typeof obj !="undefined")
}

function jkpopimage(imgpath, title){
	pic = new Image()
	pic.src = imgpath
	pic.vspace = 0
	pic.hspace = 0
/*
	while (pic.width == 0){
		var ndx = 1000;
		while (ndx-- > 0)
		  ;
	}
	*/	
	pic.onload =  function(){showimage(pic, title)};
}

function showimage(img, windowtitle) {
	leftpos=(detectexist(window.screenLeft))? screenLeft+document.body.clientWidth/2-img.width/2 : detectexist(window.screenX)? screenX+innerWidth/2-img.width/2 : 0
	toppos=(detectexist(window.screenTop))? screenTop+document.body.clientHeight/2-img.height/2 : detectexist(window.screenY)? screenY+innerHeight/2-img.height/2 : 0
	
	if (window.opera){
		leftpos-=screenLeft
		toppos-=screenTop
	}
	
	var winattributes='width='+img.width+',height='+img.height+',left='+leftpos+',top='+toppos
	var jkpopwin;
	
	if (typeof jkpopwin=="undefined" || jkpopwin.closed)
		jkpopwin=window.open("","",winattributes)
	else
		jkpopwin.resizeTo(img.width, pic.height)
	
	jkpopwin.document.open()
	jkpopwin.document.write('<html><title>'+windowtitle+'</title><body background="' + img.src + '"></body></html>')
	jkpopwin.document.close()
	jkpopwin.focus()
}