// Automatically resize linked images within posts, for the Absolution theme.
// Absolution uses up approximately 425px with member info on left side of post content division.
// Max width of any linked images via the [img] BBCode should be limited to the remainder of the width of the post content.
// Written by ChrisV2

  function imagesize() {
    var theHolder = document.getElementsByName('linkimage');  // see if any linked images exist
    
    if (theHolder)  
      var maxImgWidth = document.getElementsByTagName("div")["page-wrap"].offsetWidth - 450;  // calc max image width
      var ImageMouseOverTitle = 'Click here to view image in a separate window.';
      {
          for (i=0; i<theHolder.length; i++)
             {
                chgimgsize = theHolder[i];
                if (chgimgsize.width > maxImgWidth)  // if linked image is too wide, reset its maximum width
                   {
                      chgimgsize.style.width = maxImgWidth + 'px';
                      eval("pop" + String(i) + " = new Function(\"pop = window.open('" + chgimgsize.src + " ','fullscale','width=400,height=400,scrollbars=1,resizable=1'); pop.focus();\")");
                      eval("chgimgsize.onclick = pop" + String(i) + ";");
                      if (document.all) chgimgsize.style.cursor = 'hand';
                      if (!document.all) chgimgsize.style.cursor = 'pointer';
                      chgimgsize.title = ImageMouseOverTitle;
                   }
             }
       }
    }

// -----------------------------------------------------------------------------------------------
// Register imagesize to be executed on load
if (window.addEventListener)
{
	// the "proper" way
	window.addEventListener("load", imagesize, false);
}
else 
if (window.attachEvent)
{
	// the IE way
	window.attachEvent("onload", imagesize);
}
