(function()
{
    'use strict';
    var page = jQuery(document);

    page.on('contentloaded', function(e)
    {
        var block = jQuery(e.target);
        var iframes = block.find('.richtext iframe');

        iframes.each(function(index, iframe)
        {
            var original = jQuery(iframe);
            var width    = original.width();
            var height   = original.height();

            var copy = original.clone().removeAttr('width').removeAttr('height');
            var wrap = jQuery('<div class="iframe-box"/>').css('padding-bottom', 100 * (height / width) + '%').append(copy);

            original.replaceWith(wrap);
        });
    });

}());
