﻿

        function loadedImage(imgElement) {

            var imgH;
            var imgW;

            if (document.defaultView) {

                imgH = parseInt(document.defaultView.getComputedStyle(imgElement, null).getPropertyValue("height"));
                imgW = parseInt(document.defaultView.getComputedStyle(imgElement, null).getPropertyValue("width"));

            }
            else {
                imgH=parseInt(imgElement.height);
                imgW=parseInt(imgElement.width);
            }
            
            var bDisplay = ((imgH <= 650) && (imgW <= 500));
            imgElement.style.display = (bDisplay) ? "inline" : "none";
            imgElement.style.visibility = (bDisplay) ? "visible" : "hidden";

            if (!bDisplay) {

                var aElem = document.createElement("a");
                var attHref = document.createAttribute("href");
                var attTarget = document.createAttribute("target");
                var txtNode = document.createTextNode(imgElement.src + " [" + imgW + " x " + imgH + " pixels]");

                attHref.value = imgElement.src;
                attTarget.value = "_blank";
                aElem.attributes.setNamedItem(attHref);
                aElem.attributes.setNamedItem(attTarget);
                aElem.appendChild(txtNode);

                imgElement.parentNode.replaceChild(aElem, imgElement);
            }

        }