var tgt;
var currentUrl;
var currentThumb;
var loadedImgs = new Array();

function popImg(theUrl, w, h, thumbID){
	// find the target image
	if(tgt == undefined){
		var div = document.getElementById('popupTarget');
		var img = div.getElementsByTagName('img');
		for (i = 0; i < img.length; i++) {
	  		if(img[i].src.indexOf("/clear.gif") > -1){
	  			continue;
	  		} else {
	  			tgt = img[i];
	  			break;
	  		}
		}
	}
	
	// not yet loaded?
	if (!loadedImgs[thumbID] == 1){
		currentUrl = theUrl;
		currentThumb = thumbID;
		
		// find the thumb and show
		var tmpA = document.getElementById(thumbID);
		var tmpImgs  = tmpA.getElementsByTagName('img');
		var tmp = tmpImgs[0];
	  	tgt.width  = w;
	  	tgt.height = h;
	  	tgt.src = tmp.src;
	  	
	  	// load the new image
	  	var newImg = new Image();
  			newImg.onload = function(){
  			loadedImgs[currentThumb] = 1;
			tgt.src = this.src;
		}
  		newImg.src = currentUrl;
  	// already loaded
	} else {
		tgt.width  = w;
	  	tgt.height = h;
		tgt.src = theUrl;
	}
  	
}
