(function ( $ ) {
	'use strict';

	qodefCore.shortcodes.ginevra_core_image_with_text = {};


	$( document ).ready(
		function () {
			qodefImageWithText.init();
		}
	);

	var qodefImageWithText = {
		init: function () {
			this.holder = $( '.qodef-image-with-text.qodef-has-appear' );

			if ( this.holder.length ) {
				this.holder.each(
					function () {
						qodefImageWithText.initItem( $( this ) );
					}
				);
			}
		},
		initItem: function ( $holder ) {

			qodefCore.qodefIsInViewport.check(
				$holder,
				function () {

					var $body = $( 'body' );

					if ( $body.hasClass( 'qodef-has-spinner' ) ) {

						var qodefWaitInterval = setInterval(
							function () {
								if ( $body.hasClass( 'qodef-spinner-finished' ) ) {

									clearInterval( qodefWaitInterval );

									qodef.qodefWaitForImages.check(
										$holder,
										function () {
											var $delay = Math.floor( Math.random() * (500 - 200 + 1) + 200 );

											setTimeout(
												function () {
													$holder.addClass( 'qodef--appeared' );
												},
												$delay
											);
										}
									);
								}
							},
							100
						);

					} else {
						qodef.qodefWaitForImages.check(
							$holder,
							function () {
								var $delay = Math.floor( Math.random() * (500 - 200 + 1) + 200 );

								setTimeout(
									function () {
										$holder.addClass( 'qodef--appeared' );
									},
									$delay
								);
							}
						);
					}
				},
			);
		},
	};

	qodefCore.shortcodes.ginevra_core_image_with_text.qodefImageWithText = qodefImageWithText;
	qodefCore.shortcodes.ginevra_core_image_with_text.qodefMagnificPopup = qodef.qodefMagnificPopup;

})( jQuery );

