window.addEventListener( 'elementor/frontend/init', () => {

	/*** General Functions ***/

	const isotope = () => {
		if ( 'function' === typeof vcexIsotopeGrids ) {
			vcexIsotopeGrids();
			if ( 'function' === typeof vcexIsotopeGridFilter ) {
				vcexIsotopeGridFilter();
			}
		}
		if ( 'function' === typeof vcexJustifiedGallery ) {
			vcexJustifiedGallery();
		}
	};

	const carousel = () => {
		if ( 'function' === typeof vcexCarousels ) {
			vcexCarousels();
		}
	};

	const sliderPro = () => {
		if ( 'function' === typeof window.wpexSliderPro ) {
			wpexSliderPro();
		}
	};

	/*** Elements ***/

	const imageGrid = () => {
		isotope();
	};

	const imageCarousel = () => {
		carousel();
	};

	const imageSlider = () => {
		sliderPro();
	};

	const testimonialsSlider = () => {
		sliderPro();
	};

	const skillBar = () => {
		if ( 'function' === typeof vcexSkillbar ) {
			vcexSkillbar();
		}
	};

	const imageBeforeAfter = () => {
		if ( 'function' === typeof vcexBeforeAfter ) {
			vcexBeforeAfter();
		}
	};

	const milestone = () => {
		if ( 'function' === typeof vcexMilestone ) {
			vcexMilestone();
		}
	};

	const postCards = () => {
		if ( 'function' === typeof wpexIsotope ) {
			wpexIsotope();
		}
		carousel();
	};


	/*** Attach Handlers ***/

	elementorFrontend.elementsHandler.attachHandler( 'vcex_image_grid', imageGrid );
	elementorFrontend.elementsHandler.attachHandler( 'vcex_image_carousel', imageCarousel );
	elementorFrontend.elementsHandler.attachHandler( 'vcex_image_flexslider', imageSlider );
	elementorFrontend.elementsHandler.attachHandler( 'vcex_testimonials_slider', testimonialsSlider );
	elementorFrontend.elementsHandler.attachHandler( 'vcex_skillbar', skillBar );
	elementorFrontend.elementsHandler.attachHandler( 'vcex_image_ba', imageBeforeAfter );
	elementorFrontend.elementsHandler.attachHandler( 'vcex_milestone', milestone );
	elementorFrontend.elementsHandler.attachHandler( 'wpex_post_cards', postCards );

//	elementorFrontend.hooks.addAction( 'frontend/element_ready/global', runVcexFunctions );

} );