
function MakeImageArray(n) {
    this.length = n;
    if (document.images) {
        for (var i = 0; i <= n-1; i++) {
          this[i] = new Image();
        }
    }
    return this;
}

function swapImage(pImageTag, pImage) {
  if (document.images) {
    pImageTag.src = pImage.src;
  }
} 

var popup;

function imgPopup(pUrl, pInitialWidth, pInitialHeight) {
	var windowFeatures = 'toolbar=no,directories=no,location=no,status=no,menubar=no,resizable=yes,scrollbars=yes,'
    + 'width=' + pInitialWidth + ',height=' + pInitialHeight+',left=0,top=0';
    
  popup = window.open(pUrl, 'imgPopup', windowFeatures);
  
  if (window.focus) { 
  	popup.focus()
  };
}

function sizeImgWin(win, img)
{
  var new_w = img.width;
	var new_h = img.height;
	var old_w = win.innerWidth || win.document.body.offsetWidth;
	var old_h = win.innerHeight || win.document.body.offsetHeight;

	if (!new_w) { new_w = old_w; }
	if (!new_h) { new_h = old_h; }

  var delta_w = new_w - old_w;
  var delta_h = new_h - old_h;
	
	if (old_h + delta_h > screen.height - 100) {
		delta_h = screen.height - old_h - 100;
	} else {
		delta_h += 25;
	}
	
	if (old_w + delta_w > screen.width - 20) {
		delta_w = screen.width - old_w - 20;
	}
	
	// alert("new_w="+new_w+", new_h="+new_h+",old_w="+old_w+", old_h="+old_h+", resizing by "+delta_w+", "+delta_h+"...");
	
	win.resizeBy(delta_w,delta_h);
	var pic = win.document.getElementById('pic');
	pic.src = img.src;
	pic.style.display = 'block';


//	win.focus();
}
