// Global Script autorun
$(function(){
	fancyboxAjaxSubmit();
	initCatalogMenu();
	anchorEngine();
	$(window).lazyLoadXT();
	initGoals();
});

function initGoals() {
	// Цели счетчиков

}

function fancyboxAjaxSubmit() {
	$('body').on('submit', '.fancybox-content form', function(e) {
		var el = $(this);
		if ( el.data('dialog-nosubmit') == true ) return true;
		
		e.preventDefault();
		var fancyContent = $(el).closest('.fancybox-content');
		fancyContent.html('<div class="p-4 text-center"><div class="spinner-grow text-success" role="status"><span class="sr-only">Loading...</span></div></div>');
		el.ajaxSubmit( function( data ) {
			$.fancybox.close();
			$.fancybox.open(data);
		} );
		return false;	
	});
}

function anchorEngine() {
	$('a.anchor-link').on('click', function(e) {
		e.preventDefault();

		var el = $(this).data('link');
		if (el) {
			$('body,html').animate({ scrollTop: $(el).offset().top - 80 }, 300);
		}
		
		return false;
	});	
}

function initCatalogMenu() {
    initMobileMenu();
}


function initMobileMenu() {
	var sidemenu = $('#mobile-catalog').slideMenu({
					    position:'left',
					    submenuLinkAfter:' <i class="fas fa-chevron-right"></i>',
					    backLinkBefore:'<i class="fas fa-chevron-left"></i> '
					});

	$('.slide-darker').click(function() {
	    sidemenu.close();
	});

}

function percentageToDegrees(percentage) {
	return percentage / 100 * 360
}

$.fn.extend({
    animateCss: function (animationName) {
        var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
        this.addClass('animate__animated ' + 'animate__' + animationName).one(animationEnd, function() {
            $(this).removeClass('animate__animated ' + 'animate__' + animationName);
        });
        return this;
    }
});