function addPopupToImages() {
  
  // Get images
  var im = document.getElementsByTagName('img');
  for(var i=0; i<im.length; i++) {
    // Don't do it if in link
    if(im[i].parentNode.tagName  == 'A')
      continue;

    // Ensure the image is of type cache/45_ ... or image.php...
    var regex = /[0-9]+/;
    var parts = regex.exec(im[i].src);
    if(parts) {

      im[i].image_id = parts[0];
      im[i].onclick  = function() {
        var url = 'image.php?id=' + this.image_id;
        window.open(url, 'imagePopup', 'width=350,height=350');
      }
      im[i].style.cursor = 'pointer';
    }
  }

}
