(function($) {

	$(document).on('metaslider/initialized', function(e, identifier) {

		if ($(identifier).closest('.metaslider.ms-theme-retsu').length) {
			var slideshow = $(identifier);

			// Adjust slideshow height
			slideshow.css('overflow', 'hidden');

			// We look for Image, External URL and Post Feed slides only
			var target = '.slides > li.ms-image, .slides > li.ms-external, .slides > li.ms-postfeed';

			// Add custom theme wrappers
			slideshow.find(target).each(function(i) {
				var slide = $(this);

				if (slide.find('.ms-grid-inner').length === 0) {
					var hasImageClass = $(this).find('.ms-slide-no-image').length === 1 ? ' ms-grid-inner-1-col' : '';

					$(this).wrapInner(`<div class="ms-grid-inner${hasImageClass}"></div>`);
				}
			});
			

			slideshow.find('.ms-grid-inner img').each(function() {
				var img = $(this);

				if (img.parent('a').length === 1) {
					img.parent('a').wrap('<div class="ms-img-inner ms-with-link"></div>');
					img.css('height', img.attr('height'));
				} else {
					img.wrap('<div class="ms-img-inner ms-without-link"></div>');
					img.css('height', img.attr('height'));
				}
			});
		}
 	});

})(jQuery);