(function ($) {
    var DEFAULTS = {
        selector: 'img.themeStyleAware',
        placeholder: '{themeStyle}',
        urlDataKey: 'url'
    };

    $(document.body).on('themeChanged', function(e, themeStyle) {
        var replaceValue = encodeURIComponent(themeStyle);
        $(DEFAULTS.selector).each(function () {
            var image = $(this);
            var url = image.data(DEFAULTS.urlDataKey);
            if (url) {
                image.attr('src', url.replace(DEFAULTS.placeholder, replaceValue));
            }
        });
    });

    window.ThemeStyleImages = {
        setDefaults: function (settings) {
            $.extend(true, DEFAULTS, settings);
        }
    }
})(jQuery);