/* global jQuery:false */
/* global TOURIMO_STORAGE:false */

(function() {
	"use strict";

	// Init skin-specific actions on first run
	// Attention! Don't forget to add the class "inited" and check it to prevent re-initialize the elements
	jQuery( document ).on(
		'action.ready_tourimo', function() {			
		}
	);

	// Init skin-specific hidden elements when their parent container becomes visible
	// Attention! Don't forget to add the class "inited" and check it to prevent re-initialize the elements
	jQuery( document ).on(
		'action.init_hidden_elements', function() {
		}
	);

	// Skin-specific scroll actions
	jQuery( document ).on(
		'action.scroll_tourimo', function() {
		}
	);

	// Skin-specific resize actions
	jQuery( document ).on(
		'action.resize_tourimo', function() {
			tourimo_skin_elementor_spacer_height(); 
		}
	);

	jQuery( window ).load( function() {
		"use strict";

		// Elementor Images
		jQuery('.elementor a img[class*="align"]').each(function(){
			if (jQuery(this).hasClass('alignright')) {
				jQuery(this).removeClass('alignright')
				jQuery(this).parent().addClass('alignright');
			}
			if (jQuery(this).hasClass('alignleft')) {
				jQuery(this).removeClass('alignleft')
				jQuery(this).parent().addClass('alignleft');
			}
		});

		// Elementor Tabs
		jQuery('.elementor-tab-content').each(function() { 
			var tab = jQuery(this);
			var img = tab.find('img:first-of-type');
			if ( img.length > 0 ) {
				var src = img.attr('src');
				img.remove();
				img = '<div class="elementor-tab-side-image" style="background-image: url(' + src + ');"></div>';
				tab.addClass('with_image').prepend(img);
			}
		});
	});

	jQuery( window ).load( function() {
		"use strict";
		tourimo_skin_elementor_spacer_height();

		// Social Feed 
		jQuery('[class*="social-feed-container"] .content').each(function(){
			jQuery(this).find('.media-body strong').appendTo(jQuery(this).find('.pull-left'));
		});
	});

	jQuery( window ).scroll( function() {
		"use strict";
	});

	// Return true if page already scrolled to element
	function tourimo_skin_scroll_to_elem(elem) {
		var hT = elem.offset().top,
		hH = elem.outerHeight(),
		wH = jQuery( window ).height(),
		wS = jQuery( window ).scrollTop();
		if (wS > (hT+hH-wH) && (hT > wS) && (wS+wH > hT+hH)){
			return true;
		} else {
			return false;
		}
	}

	// Change Elementor Spacer height
	function tourimo_skin_elementor_spacer_height() {
		jQuery('.elementor-spacer-inner').each(function(){
			jQuery(this).css('max-height', '');
			var height = jQuery(this).height();	
			height = height / 14;
			height = height + 'rem';
			jQuery(this).css('max-height', height);
		});
	}

})();
