(function() { function load() { if (this.naturalWidth > this.clientWidth || this.naturalHeight > this.clientHeight) { this.style.cursor = "pointer"; this.onclick = function() { var overlay = document.createElement("div"); overlay.id = "overlay"; overlay.onclick = function() { document.body.removeChild(this); }; var img = document.createElement("img"); img.src = this.src; img.onload = function() { img.style.marginLeft = -img.clientWidth / 2 + "px"; img.style.marginTop = -img.clientHeight / 2 + "px"; close.style.marginTop = -img.clientHeight / 2 - close.offsetHeight / 2 + "px"; }; var inner = document.createElement("div"); inner.appendChild(img); overlay.appendChild(inner); var close = document.createElement("span"); close.innerHTML = "close"; inner.appendChild(close); document.body.appendChild(overlay); } } } var i, imgs = document.getElementsByTagName("img"); for (i = 0; i < imgs.length; i++) { if (!imgs[i].naturalWidth) { imgs[i].onload = load; } else { load.call(imgs[i]); } } }());