    /**
    * Auto image resizing for viewtopic by Eelke Blok.
    * This is provided as-is, no support, no guarantees.
    */

    var maxImageWidth = 650; // Maximum size you do not want to resize, as well as size that will be resized to.
    var borderWidth = 1; // Width of the red dotted border around resized images.

    function init_resize(classname, element) {
      var s = document.getElementsByTagName(element);
      for (var i=0; i<s.length; i++) {
        if (s[i].className==classname) {
          var imgs = s[i].getElementsByTagName("img");
          for (var j=0; j<imgs.length; j++) {
            resize_image(imgs[j]);
            imgs[j].onload = auto_resize;
          }
        }
      }
    }

    function auto_resize() {
        resize_image(this);
    }

    function resize_image(image) {
      if (image.width > maxImageWidth) {
        var newWidth = maxImageWidth - 4*borderWidth;
        image.title = "Image resized, click for original size (" + image.width + "x" + image.height + ")";
        image.style.width = newWidth + "px";
        image.style.height = newWidth/image.width*image.height + "px";
        image.style.border = borderWidth + "px dashed red";
        image.style.cursor = "pointer";
        image.onclick = img_onclick;
      }
    }

    function img_onclick() {
        window.open(this.src);
    }

    function find_parent_block(obj) {
      if (obj.nodeName=="TD" || obj.nodeName=="BLOCKQUOTE" || obj.nodeName=="DIV" || obj.nodeName=="TH" || obj.nodeName=="BODY")
        return obj;
      return find_parent_block(obj.parentNode);
