Artikelbeschreibung document.write(''); document.write(''); document.write(''); document.write(''); document.write(''); (function (window) { // Stores past URLs that failed to load. Used for a quick lookup // and because `onerror` is not triggered in some browsers // if the response is cached. var errors = {}; // Check the existence of an image file at `url` by creating a // temporary Image element. The `success` callback is called // if the image loads correctly or the image is already complete. // The `failure` callback is called if the image fails to load // or has failed to load in the past. window.checkImage = function (url, success, failure) { var img = new Image(), // the loaded = false, errored = false; // Run only once, when `loaded` is false. If `success` is a // function, it is called with `img` as the context. img.onload = function () { if (loaded) { return; } loaded = true; if (success && success.call) { success.call(img); } }; // Run only once, when `errored` is false. If `failure` is a // function, it is called with `img` as the context. img.onerror = function () { if (errored) { return; } errors[url] = errored = true; if (failure && failure.call) { failure.call(img); } }; img.src = url; // If `url` is in the `errors` object, trigger the `onerror` // callback. if (errors[url]) { img.onerror.call(img); } // If the image is already complete (i.e. cached), trigger the // `onload` callback. if (img.complete) { img.onload.call(img); } }; })(this); // Scale Images function scaleImg(s_img) { if (s_img == document.getElementById('main_img')) { var maxWidth = 500; // Max width for the image var maxHeight = 375; // Max height for the image var ratio = 0; // Used for aspect ratio } else { var maxWidth = 90; // Max width for the image var maxHeight = 90; // Max height for the image var ratio = 0; // Used for aspect ratio } var width = s_img.width; // Current image width var height = s_img.height; // Current image height // Check if the current width is larger than the max if(width > maxWidth){ ratio = maxWidth / width; height = height * ratio; // Reset height to match scaled image width = width * ratio; // Reset width to match scaled image } // Check if current height is larger than max if(height > maxHeight){ ratio = maxHeight / height; width = width * ratio; // Reset width to match scaled image height = height * ratio; // Reset height to match scaled image } s_img.height = height; s_img.width = width; }; function success() { var mainImg = document.getElementById('main_img'); if (mainImg.src == this.src) { scaleImg(mainImg); mainImg.style.visibility = "visible"; mainImg.style.paddingTop = (document.getElementById('main_img_container').clientHeight - mainImg.height) / 2; } for (var i=1;i