// Image popup script. Popup closes by clicking on it, or with body unload.

// use in page:
//<img border="0" src="imgthumbnail.jpg" onclick="imgpopopen('img.jpg', 720, 540, 'Description'); return false" width="200" height="150" alt="" />

var popbackground="#fffff8"

function detectexist(obj){
return (typeof obj !="undefined")
}

function imgpopopen(imgpath, popwidth, popheight, textdescription){

function getpos(){
  leftpos=(detectexist(window.screenLeft))? screenLeft+document.body.clientWidth/2-popwidth/2 : detectexist(window.screenX)? screenX+innerWidth/2-popwidth/2 : 0
  toppos=(detectexist(window.screenTop))? screenTop+document.body.clientHeight/2-popheight/2 : detectexist(window.screenY)? screenY+innerHeight/2-popheight/2 : 0
  if (window.opera){
    leftpos-=screenLeft
    toppos-=screenTop
  }
}

getpos()
var winattributes='width='+popwidth+',height='+popheight+',resizable=yes,border=0,left='+leftpos+',top='+toppos
var bodyattribute=(popbackground.indexOf(".")!=-1)? 'background="'+popbackground+'"' : 'bgcolor="'+popbackground+'" leftmargin="0" rightmargin="0" topmargin="0" marginwidth="0" marginheight="0"'
if (typeof imgpopwin=="undefined" || imgpopwin.closed)
imgpopwin=window.open("","",winattributes)
else{
imgpopwin.resizeTo(popwidth, popheight+30)
// imgpopwin.resizeTo(popwidth, popheight+56)
}
imgpopwin.document.open()
imgpopwin.document.write('<html><head><META HTTP-EQUIV="imagetoolbar" CONTENT="no"><title>'+textdescription+'</title></head><body '+bodyattribute+'><img src="'+imgpath+'" border="0" alt="Click to close this window" onClick="window.close();"></body></html>')
imgpopwin.document.close()
imgpopwin.focus()
}

function imgpopclose(){
  if (window.imgpopwin && window.imgpopwin.open && !window.imgpopwin.closed)
    window.imgpopwin.close();
}
