JavaScript Preloader in Modal Div from HTML Table concatenates to new img URL
<p>This code is meant for a real estate website I am updating for my company.  Basically, There is a table with the property name, address, etc, and an image.  Originally, I was coding this website in ASP.net switch over to regular Javascript for a few reasons (hosting overhead etc).</p>

<p>Sections of this code are from a few different tutorials out there, one of which is an ASP.net modal div image "enlarger" tutorial, which is sort of the basis combined with a few other sites.  I have yet to comment in their names etc, but I plan on giving them credit in the code.  Thier links are below before I post my code.
<hr />
<a href="http://archive.aspsnippets.com/post/2009/07/06/Image-Gallery-using-ASPNet-GridView-control.aspx" rel="nofollow">http://archive.aspsnippets.com/post/2009/07/06/Image-Gallery-using-ASPNet-GridView-control.aspx</a>
<hr />
My code is essentially as follows (I will trim the fat and excess line breaks in the style section):</p>

<p>First are the modal style tags from that tutorial by Mudassar Khan (partially relevant):</p>

<pre><code>&lt;style&gt;

    body {margin:0;padding:0;height:100%;}
    .modal {display: none;position: absolute;top: 0px;left: 0px;background-color:black;z-index:100;opacity: 0.8; filter: alpha(opacity=60);-moz-opacity:0.8;min-height: 100%;} 
    &amp;#divImage{display: none;z-index: 1000;position: fixed;top: 0;left: 0;background-color:White;height: 550px;width: 600px;padding: 3px;border: solid 1px black;} 
  &lt;style&gt;
Then comes his script, which I may have tweaked here and there:


&lt;script type="text/javascript"&gt;

        function LoadDiv(url) {

            var img = new Image();
            var bcgDiv = document.getElementById("divBackground");
            var imgDiv = document.getElementById("divImage");
            var imgFull = document.getElementById("imgFull");
            var imgLoader = document.getElementById("imgLoader");

   img.src = url;
   var tcopy = img.src.slice(0,(img.src.length-4)) + "_big.png";
   img.src = tcopy;

            img.onload = function () {
                imgFull.src = tcopy
                imgFull.style.display = "block";
                imgLoader.style.display = "none";
            };

            var width = document.body.clientWidth;
            if (document.body.clientHeight &gt; document.body.scrollHeight) {
                bcgDiv.style.height = document.body.clientHeight + "px";
            }
            else {
                bcgDiv.style.height = document.body.scrollHeight + "px";
            }

            imgDiv.style.left = (width - 650) / 2 + "px";
            imgDiv.style.top = "20px";
            bcgDiv.style.width = "100%";
            bcgDiv.style.display = "block";
            imgDiv.style.display = "block";
            return false;
        }
        function HideDiv() {
            var bcgDiv = document.getElementById("divBackground");
            var imgDiv = document.getElementById("divImage");
            var imgFull = document.getElementById("imgFull");

            imgLoader.style.display = "block"; // I added as it seems to bring back the loader gif

            if (bcgDiv != null) {
                bcgDiv.style.display = "none";
                imgDiv.style.display = "none";
                imgFull.style.display = "none";
            }
        } 
&lt;/script&gt; 
</code></pre>

<p>Now All this above script gets called upon a onClick Event Handler on an image of each of the real estate companies properties.  This will work well to both preload images with the little animated gif and the close button works fine.  It works on more than one image, BUT if the image is already preloaded, I cant think of a way to force the redisplay of an already preloaded image if a user clicks on the photo, then clicks close to hide the div tag and then clicks on the same preloaded image.</p>

<p>That event handler looks like this:</p>

<pre><code>img onClick="return LoadDiv(this.src);" src="http://www.ourcompany.com/images/prop_thumbs/Some_plaza.png" style="min-width:200 px;max-height:150 px;max-width:200 px;"
</code></pre>

<p>I thought global booleans would work, but then I realized, theres no telling which and what is preloaded, so the boolean might not help if you can't pass something meaningful back and forth.</p>

<p>I'm not asking any one to do my work for me, however I would appreciate suggestions in the right direction.</p>

<p>Regards and TIA!</p>
