
function docready() {
    $("a.header__favlink, .side-menu a, a.logo, .trc__desc a, a.trc__desc, a.artist, .coll a, .artist-item a, a.sect__link, .pagination a, .footer__menu a, .speedbar a").addClass('wajax');
	// активируем нужные ссылки для переходов по страницам без перезагрузки. перечисление через запятую. 
	
	$('.sect__content--coll').each(function(){
		if ($(window).width() > 765) {
			var time = $(this).data('timeout');
			autoRun = setInterval( ()=> {
				var t = $(this).find('.a2'), tall = $(this).find('.coll'), 
					n = t.next().length > 0 ? t.next() : $(this).find('.coll:first'),
					nn = n.next().length > 0 ? n.next() : $(this).find('.coll:first');
				tall.removeClass('a2 a3');
				n.addClass('a2');
				nn.addClass('a3');
			},time);
		};
	}); 

	$('.sect__content--tracks').each(function(){
		var count = 0;
		$(this).find('.trc').each(function(){
			count = count+1;
			countnew = String('00' + count).slice(-2);
			$(this).prepend('<div class="trc__count">'+countnew+'.</div>');
		});
	}); 

	$('.js-show-clip').each(function(){
        var a = $(this), b = a.parent().find('iframe'), c = b.data('src'), d=c.split('/');
		a.append('<img src="//img.youtube.com/vi/'+d[4]+'/sddefault.jpg" loading="lazy" alt="">');
    });	

	$('.js-comm-author').each(function(){
        var a = $(this), b = a.closest('.js-comm'), c = a.text().substr(0,1), 
            f = b.find('.js-comm-avatar'), e = f.children('img').attr('src'),
			d = ["#c57c3b","#753bc5","#79c53b","#eb3b5a","#45aaf2","#2bcbba","#778ca3"], rand = Math.floor(Math.random() * d.length);
		if (e == '/templates/'+dle_skin+'/dleimages/noavatar.png') {
            f.html('<div class="comm__letter d-flex jc-center ai-center" style="background-color:'+d[rand]+'">'+c+'</div>');
		};
    });	

};

$(document).ready(function(){

	docready();

	/* ====================== BUILDING ====================== */

	var append = `
	<div class="overlay"></div>
	<div class="mobile-menu">
		<div class="mobile-menu__header d-flex ai-center">
			<button class="mobile-menu__btn-close btn-without-bg fal fa-times" aria-label="Закрыть мобильное меню"></button>
		</div>
		<div class="mobile-menu__content"></div>
	</div>
	<button id="scrolltop" class="scrolltop fal fa-arrow-up" aria-label="Наверх"></button>
	`;
	$('body').append(append);
	
	function btnActive() {
		var ls = JSON.parse(localStorage.getItem('sett'));
		$('.side-menu__design').each(function(){
			$(this).find('button').removeClass('is-active');
		});
		$('[data-design="'+ls[0]+'"').addClass('is-active');
		$('[data-btn="'+ls[1]+'"').addClass('is-active');
		$('[data-col="'+ls[2]+'"').addClass('is-active');
	};
	btnActive();
	$.fn.hasAttr = function(name) {  
		return this.attr(name) !== undefined;
	 };
	$('.side-menu__design').on('click','button:not(.is-active)',function(){
		var ls = JSON.parse(localStorage.getItem('sett'));
		if ( $(this).hasAttr('data-design') ) { var d = $(this).data('design'); ls[0] = d };
		if ( $(this).hasAttr('data-btn') ) { var d = $(this).data('btn'); ls[1] = d };
		if ( $(this).hasAttr('data-col') ) { var d = $(this).data('col'); ls[2] = d };
		localStorage.setItem('sett',JSON.stringify(ls));
		$('body').removeAttr('class');
		switchTheme();
		btnActive();
	});

	/* ====================== EVENTS ====================== */

	$('.search-block__input').blur(function(){
		$('body').removeClass('search-is-active');
	});
	$('.search-block__input').focus(function(){
		var scrWidth = window.innerWidth - document.body.offsetWidth;
		$('body').css({'--scrWidth':scrWidth+'px'});
		$('body').toggleClass('search-is-active');
		var searchWidth = $('.search-block__input').outerWidth();
		$('body').css({'--searchWidth':searchWidth+'px'});
	});

	$(document).on('click','.trc__fav a:not(.js-show-login)',function(){
		$(this).toggleClass('is-active');
	});

	$(document).on('click','.js-show-login',function(){
		$('.overlay, .login').fadeIn(200);
		$('body').addClass('modal-is-opened');
		return false;
	})
	.on('click','.js-show-login-panel',function(){
		$('.header__login-panel').fadeToggle(0);
		$(this).toggleClass('is-active');
	})
	.on('click','.mobile-menu__content .header__menu-has-submenu > a',function(){
		$(this).parent().toggleClass('is-active');
		$(this).parent().siblings().removeClass('is-active');
		return false;
	});
	
	$(document).on('click','.js-show-clip',function(){
		$(this).remove();
		$('iframe.d-none').removeClass('d-none');
		$('[data-src]').each(function(){ 
			trg = $(this).data('src'); 
			$(this).attr('src',trg).removeAttr('data-src');
		});	
	});

	$(".js-show-mobile-menu").click(function(){
		if ($('.mobile-menu--is-generated').length === 0) {
			$('.header__logo').clone().addClass('flex-grow-1').prependTo('.mobile-menu__header');
			$('.js-this-in-mobile-menu1').each(function() {
				$(this).appendTo('.mobile-menu__content');
			});	
			$('.js-this-in-mobile-menu').each(function() {
				$(this).clone().appendTo('.mobile-menu__content');
			});	
		};
		$('.overlay').fadeIn(200);
		$('.mobile-menu').addClass('is-active mobile-menu--is-generated');
		$('body').addClass('mobile-menu-is-opened');
	});
	$(document).on('click','.overlay, .login__close, .mobile-menu__btn-close',function(){
		$('.overlay, .login, .ctrl').fadeOut(200,function(){ $('.ctrl').remove(); });
		$('.mobile-menu').removeClass('is-active');
		$('body').removeClass('modal-is-opened mobile-menu-is-opened');
	});
	
	/* ====================== DLE SCRIPTS ====================== */

	$(document).on('click','.ac-form__editor textarea, .fr-wrapper, .ac-form',function(){
		$('.ac-form').addClass('is-active').find('.message-info').show();
		$('.ac-toggle').removeClass('ac-toggle');
	})
	.on('click','.login__social a, .serv__social a',function(){
	   	var href = $(this).attr('href'), width  = 820, height = 420, 
	   		left   = (screen.width  - width)/2, top   = (screen.height - height)/2-100;   
		auth_window = window.open(href, 'auth_window', "width="+width+",height="+height+",top="+top+",left="+left+"menubar=no,resizable=no,scrollbars=no,status=no,toolbar=no");
       	return false;
	}); 
	var gotop = $('#scrolltop'); 
	$(window).scroll (function () {
		if ( $(this).scrollTop () > 300 ) { gotop.addClass('is-active'); } 
		else { gotop.removeClass('is-active'); }
	});	
	gotop.click(function(){
		$('html, body').animate({ scrollTop : 0 }, 'slow');
	});
});

/* END */