function docready() {
    $(".side-nav a, .tt, .ta a, .track-desc a, .album-item a, .collection-item a, .artist-item a, .sect-link, .pagi-nav a, .finfo a, .ft-one a, .speedbar a").addClass('wajax');
	// активируем нужные ссылки для переходов по страницам без перезагрузки. перечисление через запятую. 
	
	$('.sect-count').each(function(){
		var count = 0;
		$(this).find('.track-item').each(function(){
			count = count+1;
			countnew = String('00' + count).slice(-2);
			$(this).prepend('<div class="track-count">'+countnew+'</div>');
		});
	}); 
	
   $('.hide-this').wTextSlicer({
    height: '150',
    textExpand: 'Развернуть полностью',
    textHide: 'Свернуть'
   });
	$('.frate-box').each(function(){
        var a = $(this),
			b = parseInt(a.find('.frate-data .ratingtypeplusminus').text()),
			c = parseInt(a.find('.frate-data span[id]:last').text());
        if ( c >= b && c!=0) {
        var m = (c - b)/2,
			p = c - m,
			perc = (Math.round((c - (c - b)/2)/c*100)),
			percminus = 100 - perc;
		a.children('.frate-yes').find('span').html('('+perc+'%)');
		a.children('.frate-no').find('span').html('('+percminus+'%)');
		a.find('.frate-yes .frate-counts').after('<div class="frate-bar fx-1"><div class="frate-fill anim-all" style="width:'+perc+'%;"></div></div>');
		a.find('.frate-no .frate-counts').after('<div class="frate-bar fx-1"><div class="frate-fill anim-all" style="width:'+percminus+'%;"></div></div>');
        } else {
            a.find('.frate-yes .frate-counts').after('<div class="frate-bar fx-1"><div class="frate-fill anim-all"></div></div>');
            a.find('.frate-no .frate-counts').after('<div class="frate-bar fx-1"><div class="frate-fill anim-all"></div></div>');
         };
		a.addClass('done');
    });	
    $('#dle-content > #dle-ajax-comments').appendTo($('#full-comms')); 
};

$(document).ready(function(){
	
	docready();
	
	var vol = localStorage.getItem('vol');
	if ( vol == undefined ) { localStorage.setItem('vol', 0.5); };
	
	$('body').on('click', '.js-play', function() {
		var vol = localStorage.getItem('vol');
		$('.js-ctrl').removeClass('js-stop').addClass('js-play').find('.fa').removeClass('fa-stop').addClass('fa-play');
		$('.js-item').removeClass('show-player');
		$('.item-player').remove();
		$(this).removeClass('js-play').addClass('js-stop').find('.fa').removeClass('fa-play').addClass('fa-stop');
		var current = $(this).closest('.js-item'),
			data = current.data(),
			src = data.track, artist = data.artist, title = data.title, img = data.img;
		current.addClass('show-player');
		$('body').append('<div class="item-player"><audio preload="auto" controls><source src="'+src+'" /></audio></div>');
		$('body').find('.item-player audio').audioPlayer();
		$('body').find('.item-player audio').get(0).volume=vol;
		$('body').find('.item-player audio').get(0).play();
		$('.audioplayer').removeClass('audioplayer-stopped').addClass('audioplayer-playing fx-row fx-middle').find('.audioplayer-playpause').wrap('<div class="ap-left fx-row fx-middle fx-1"></div>');
		$('.audioplayer').find('.ap-left').append('<div class="ap-next"><span class="fa fa-fast-forward"></span></div><div class="ap-desc fx-row fx-middle fx-1"><div class="ap-img"><img src="'+img+'"></div><div class="ap-info fx-1"><div class="ap-artist nowrap">'+artist+'</div><div class="ap-title nowrap">'+title+'</div></div></div><a class="ap-dl" download target="_blank" href="'+src+'"><span class="fa fa-download"></span></a>');
		$('.audioplayer').find('.ap-left').prepend('<div class="ap-prev"><span class="fa fa-fast-backward"></span></div>');
	});
	$('body').on('click', '.js-stop', function() {
		$('.js-ctrl').removeClass('js-stop').addClass('js-play').find('.fa').removeClass('fa-stop').addClass('fa-play');
		$('.js-item').removeClass('show-player');
		$('.item-player').remove();
	});
	$('body').on('click', '.ap-next', function() {
		apNext();
	});
	$('body').on('click', '.ap-prev', function() {
		apPrev();
	});
   
	
	$('body').on('click','.wajax',function(){
		var $urlNext = $(this).attr('href');
        if ($urlNext !== undefined) {
			$.ajax({
				url: $urlNext,
				beforeSend: function() {
					ShowLoading('');
				},			 
                success: function(data) {
                    $('.content').html($('.content', data).html());
					window.history.pushState("", "", $urlNext);
					$('html, body').animate({ scrollTop : 0 }, 'slow');
                    var title = (/\<title>(.*[\s\S]*?)\<\/title>/g).exec(data)[1];
                    if(title.length != 0){ $('head title').text(title); };
					HideLoading('');
				   docready();
                },
				  error: function() {				
					HideLoading('');
					alert('что-то пошло не так');
				  }
			});
		};
		return false;
	});
	
	$(".menu-btn-toggle").click(function(){
		$(this).next('.hidden-menu').slideToggle(200);
		$(this).find('.fa').toggleClass('fa-angle-down fa-angle-up');
	});
	
	$(".btn-menu").click(function(){
		$('.col-left').toggleClass('viss');
		$(this).find('.fa').toggleClass('fa-bars fa-times');
	});
	
	$('.js-login').click(function(){
		if ( $('.login-overlay').length < 1 ) {
			$('.login-box').before('<div class="login-overlay"></div>');
			$('.login-box').prepend('<div class="login-close"><span class="fa fa-times"></span></div>');
		};
		$('.login-box, .login-overlay').fadeIn(200);
		$('body').addClass('zfix');
	});
	$('body').on('click','.login-overlay, .login-close',function(){
		$('.login-box, .login-overlay').fadeOut(200);
		$('body').removeClass('zfix');
	});
	
	$(".add-comm-btn").click(function(){
		$("#add-comms").slideToggle(200);
	});
	$(".reply").click(function(){
		$("#add-comms").slideDown(200);
	});
	$('body').on('click','.ac-textarea textarea, .fr-wrapper',function(){
		$('.add-comm-form').addClass('active').find('.ac-protect').slideDown(400);
	});
	$('.lb-soc a, .ac-soc a').on('click',function(){
	   var href = $(this).attr('href');
       var width  = 820;
       var height = 420;
       var left   = (screen.width  - width)/2;
       var 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;
	});
    $('#dle-content234 > #dle-ajax-comments').appendTo($('#full-comms')); 

	$('body').append('<div id="gotop"><span class="fa fa-arrow-up"></span></div>');
	var $gotop=$('#gotop'); 
	$(window).scroll (function () {
		if ($(this).scrollTop () > 300) {$gotop.fadeIn(200);
		} else {$gotop.fadeOut(200);}
	});	
	$gotop.click(function(){
		$('html, body').animate({ scrollTop : 0 }, 'slow');
	});
	
});


	function doRateLD( rate, id ) {
		ShowLoading('');
		$.get(dle_root + "engine/ajax/controller.php?mod=rating", { go_rate: rate, news_id: id, skin: dle_skin, user_hash: dle_login_hash }, function(data){
			HideLoading('');
			if ( data.success ) {
				var rating = data.rating;
				rating = rating.replace(/&lt;/g, "<");
				rating = rating.replace(/&gt;/g, ">");
				rating = rating.replace(/&amp;/g, "&");
				$("#ratig-layer-" + id).html(rating);
				$("#vote-num-id-" + id).html(data.votenum);
				var rt = parseInt($(rating).text()),
					m = (data.votenum - rt)/2,
					p = data.votenum - m,
					fill = Math.round(p/data.votenum*100),
					fillminus = 100 - fill,
					frate = $('#frate-' + id);
				frate.children('.frate-yes').find('span').html('('+fill+'%)');
				frate.children('.frate-no').find('span').html('('+fillminus+'%)');
				frate.find('.frate-yes .frate-fill').css({'width':''+fill+'%'});
				frate.find('.frate-no .frate-fill').css({'width':''+fillminus+'%'});
			} else if (data.error) {DLEalert ( data.errorinfo, dle_info );}
		}, "json");
	};
	
/*!  wTextSlicer v 1.01 */

jQuery.fn.wTextSlicer = function(options){
   var options = jQuery.extend({
    height: '200',
    textExpand: 'expand text',
    textHide: 'hide text'
    },options);
   return this.each(function() {
     var a = $(this),
       h = a.outerHeight();
     if ( h > options.height ) {
       a.addClass('slice slice-masked').attr('data-height',h).height(options.height).after('<div class="slice-btn"><span>'+options.textExpand+'</span></div>');
     };
     var bt = $(this).next('.slice-btn').children('span');
     bt.click(function() {
       var ah = parseInt(a.css("height"), 10);
       ah == h ? a.css({'height':options.height}) : a.css({'height':h});
       bt.text(bt.text() == options.textExpand ? options.textHide : options.textExpand);
       a.toggleClass('slice-masked');
     });
   });
};

$(document).ready(function() {
	if ($(window).width() > 250) {	
	var LinkTitle = $(document).attr('title');
	var LinkUrl = window.location.href;
	LinkTitle=encodeURIComponent(LinkTitle);
	LinkUrl=encodeURIComponent(LinkUrl);
	var leftvar = (screen.width-600)/2;
	var topvar = (screen.height-400)/2;
	
	var LinksItem = [
	'http://vkontakte.ru/share.php?url='+LinkUrl+'" onClick="popupWin = window.open(this.href, \'contacts\', \'location,width=600,height=400,left='+leftvar+',top='+topvar+'\'); popupWin.focus(); return false;"',
	'http://www.facebook.com/sharer.php?u='+LinkUrl+'&t='+LinkTitle+'" onClick="popupWin = window.open(this.href, \'contacts\', \'location,width=600,height=400,left='+leftvar+',top='+topvar+'\'); popupWin.focus(); return false;"',
	'http://twitter.com/share?text='+LinkTitle+'&url='+LinkUrl+'" onClick="popupWin = window.open(this.href, \'contacts\', \'location,width=600,height=400,left='+leftvar+',top='+topvar+'\'); popupWin.focus(); return false;"',
	'https://connect.ok.ru/offer?url='+LinkUrl+'&title='+LinkTitle+'" onClick="popupWin = window.open(this.href, \'contacts\', \'location,width=600,height=400,left='+leftvar+',top='+topvar+'\'); popupWin.focus(); return false;"',
	'https://plus.google.com/share?url='+LinkUrl+'" onClick="popupWin = window.open(this.href, \'contacts\', \'location,width=600,height=400,left='+leftvar+',top='+topvar+'\'); popupWin.focus(); return false;"'
	];
	
	$('.share').each(function(){
		var $share = $(this);
		for (i=0; i<LinksItem.length; i++)
		{
			var getLinks = $('<a href="'+LinksItem[i]+' target="_blank"></a>');
			getLinks.appendTo($share);
		}
	});
	};
});

function apPrev(){$(".js-item");var a=localStorage.getItem("vol"),e=$(".show-player").index(".js-item"),t=$(".js-item").eq(e-1).length?$(".js-item").eq(e-1):$(".js-item:last");$(".js-ctrl").removeClass("js-stop").addClass("js-play").find(".fa").removeClass("fa-stop").addClass("fa-play"),$(".js-item").removeClass("show-player"),$(".item-player").remove(),t.find(".js-play").removeClass("js-play").addClass("js-stop").find(".fa").removeClass("fa-play").addClass("fa-stop");var s=t,i=s.data(),d=i.track,l=i.artist,o=i.title,n=i.img;s.addClass("show-player"),$("body").append('<div class="item-player"><audio preload="auto" controls><source src="'+d+'" /></audio></div>'),$("body").find(".item-player audio").audioPlayer(),$("body").find(".item-player audio").get(0).volume=a,$("body").find(".item-player audio").get(0).play(),$(".audioplayer").removeClass("audioplayer-stopped").addClass("audioplayer-playing fx-row fx-middle").find(".audioplayer-playpause").wrap('<div class="ap-left fx-row fx-middle fx-1"></div>'),$(".audioplayer").find(".ap-left").append('<div class="ap-next"><span class="fa fa-fast-forward"></span></div><div class="ap-desc fx-row fx-middle fx-1"><div class="ap-img"><img src="'+n+'"></div><div class="ap-info fx-1"><div class="ap-artist nowrap">'+l+'</div><div class="ap-title nowrap">'+o+'</div></div></div><a class="ap-dl" download target="_blank" href="'+d+'"><span class="fa fa-download"></span></a>'),$(".audioplayer").find(".ap-left").prepend('<div class="ap-prev"><span class="fa fa-fast-backward"></span></div>')}function apNext(){$(".js-item");var a=localStorage.getItem("vol"),e=$(".show-player").index(".js-item"),t=$(".js-item").eq(e+1).length?$(".js-item").eq(e+1):$(".js-item:first");$(".js-ctrl").removeClass("js-stop").addClass("js-play").find(".fa").removeClass("fa-stop").addClass("fa-play"),$(".js-item").removeClass("show-player"),$(".item-player").remove(),t.find(".js-play").removeClass("js-play").addClass("js-stop").find(".fa").removeClass("fa-play").addClass("fa-stop");var s=t,i=s.data(),d=i.track,l=i.artist,o=i.title,n=i.img;s.addClass("show-player"),$("body").append('<div class="item-player"><audio preload="auto" controls><source src="'+d+'" /></audio></div>'),$("body").find(".item-player audio").audioPlayer(),$("body").find(".item-player audio").get(0).volume=a,$("body").find(".item-player audio").get(0).play(),$(".audioplayer").removeClass("audioplayer-stopped").addClass("audioplayer-playing fx-row fx-middle").find(".audioplayer-playpause").wrap('<div class="ap-left fx-row fx-middle fx-1"></div>'),$(".audioplayer").find(".ap-left").append('<div class="ap-next"><span class="fa fa-fast-forward"></span></div><div class="ap-desc fx-row fx-middle fx-1"><div class="ap-img"><img src="'+n+'"></div><div class="ap-info fx-1"><div class="ap-artist nowrap">'+l+'</div><div class="ap-title nowrap">'+o+'</div></div></div><a class="ap-dl" download target="_blank" href="'+d+'"><span class="fa fa-download"></span></a>'),$(".audioplayer").find(".ap-left").prepend('<div class="ap-prev"><span class="fa fa-fast-backward"></span></div>')}!function(b,a,t,e){var $="ontouchstart"in a,j=$?"touchstart":"mousedown",x=$?"touchmove":"mousemove",P=$?"touchcancel":"mouseup",I=function(a){var e=a/3600,t=Math.floor(e),s=a%3600/60,i=Math.floor(s),d=Math.ceil(a%3600%60);return 59<d&&(d=0,i=Math.ceil(s)),59<i&&(i=0,t=Math.ceil(e)),(0==t?"":0<t&&t.toString().length<2?"0"+t+":":t+":")+(i.toString().length<2?"0"+i:i)+":"+(d.toString().length<2?"0"+d:d)},E=function(a){var e=t.createElement("audio");return!(!e.canPlayType||!e.canPlayType("audio/"+a.split(".").pop().toLowerCase()+";").replace(/no/,""))};b.fn.audioPlayer=function(C){C=b.extend({classPrefix:"audioplayer",strPlay:"Играть",strPause:"Пауза",strVolume:"Громкость",strPlayI:'<span class="fa fa-play"></span>',strPauseI:'<span class="fa fa-pause"></span>',strVolumeI:'<span class="fa fa-volume-up"></span>'},C);var w={},a={playPause:"playpause",playing:"playing",stopped:"stopped",time:"time",timeCurrent:"time-current",timeDuration:"time-duration",bar:"bar",barLoaded:"bar-loaded",barPlayed:"bar-played",volume:"volume",volumeButton:"volume-button",volumeAdjust:"volume-adjust",noVolume:"novolume",muted:"muted",mini:"mini"};for(var e in a)w[e]=C.classPrefix+"-"+a[e];return this.each(function(){if("audio"!=b(this).prop("tagName").toLowerCase())return!1;var a=b(this),e=a.attr("src"),t=""===(t=a.get(0).getAttribute("autoplay"))||"autoplay"===t,s=""===(s=a.get(0).getAttribute("loop"))||"loop"===s,i=!1;void 0===e?a.find("source").each(function(){if(void 0!==(e=b(this).attr("src"))&&E(e))return!(i=!0)}):E(e)&&(i=!0);var d=b('<div class="'+C.classPrefix+'">'+(i?b("<div>").append(a.eq(0).clone()).html():'<embed src="'+e+'" width="0" height="0" volume="100" autostart="'+t.toString()+'" loop="'+s.toString()+'" />')+'<div class="'+w.playPause+'" title="'+C.strPlay+'"><a href="#">'+C.strPauseI+"</a></div></div>"),l=(l=i?d.find("audio"):d.find("embed")).get(0);if(i){d.find("audio").css({width:0,height:0,visibility:"hidden"}),d.append('<div class="'+w.time+" "+w.timeCurrent+'"></div><div class="'+w.bar+'"><div class="'+w.barLoaded+'"></div><div class="'+w.barPlayed+'"></div></div><div class="'+w.time+" "+w.timeDuration+'"></div><div class="'+w.volume+'"><div class="'+w.volumeButton+'" title="'+C.strVolume+'"><a href="#">'+C.strVolumeI+'</a></div><div class="'+w.volumeAdjust+'"><div><div></div></div></div></div>');var o=d.find("."+w.bar),n=d.find("."+w.barPlayed),r=d.find("."+w.barLoaded),p=d.find("."+w.timeCurrent),u=d.find("."+w.timeDuration),v=d.find("."+w.volumeButton),f=d.find("."+w.volumeAdjust+" > div"),m=0,c=function(a){theRealEvent=$?a.originalEvent.touches[0]:a,l.currentTime=Math.round(l.duration*(theRealEvent.pageX-o.offset().left)/o.width())},y=function(a){theRealEvent=$?a.originalEvent.touches[0]:a,l.volume=1-Math.abs((theRealEvent.pageX-(f.offset().left+f.width()))/f.width())},h=l.volume,g=l.volume=.111;Math.round(1e3*l.volume)/1e3==g?l.volume=h:d.addClass(w.noVolume),u.html("&hellip;"),p.html(I(0)),l.addEventListener("loadeddata",function(){var a;a=setInterval(function(){if(l.buffered.length<1)return!0;r.width(l.buffered.end(0)/l.duration*100+"%"),Math.floor(l.buffered.end(0))>=Math.floor(l.duration)&&clearInterval(a)},100),u.html(b.isNumeric(l.duration)?I(l.duration):"&hellip;"),f.find("div").height(100*l.volume+"%"),m=l.volume}),l.addEventListener("timeupdate",function(){p.html(I(l.currentTime)),n.width(l.currentTime/l.duration*100+"%")}),l.addEventListener("volumechange",function(){f.find("div").width(100*l.volume+"%"),0<l.volume&&d.hasClass(w.muted)&&d.removeClass(w.muted),l.volume<=0&&!d.hasClass(w.muted)&&d.addClass(w.muted),localStorage.setItem("vol",l.volume)}),l.addEventListener("ended",function(){d.removeClass(w.playing).addClass(w.stopped),apNext()}),o.on(j,function(a){c(a),o.on(x,function(a){c(a)})}).on(P,function(){o.unbind(x)}),v.on("click",function(){return d.hasClass(w.muted)?(d.removeClass(w.muted),l.volume=m):(d.addClass(w.muted),m=l.volume,l.volume=0),!1}),f.on(j,function(a){y(a),f.on(x,function(a){y(a)})}).on(P,function(){f.unbind(x)})}else d.addClass(w.mini);d.addClass(t?w.playing:w.stopped),d.find("."+w.playPause).on("click",function(){b(this).parent().parent().attr("class");return d.hasClass(w.playing)?(b(this).attr("title",C.strPlay).find("a").html(C.strPlayI),d.removeClass(w.playing).addClass(w.stopped),i?l.pause():l.Stop()):(b(this).attr("title",C.strPause).find("a").html(C.strPauseI),d.addClass(w.playing).removeClass(w.stopped),i?l.play():l.Play()),!1}),a.replaceWith(d)}),this}}(jQuery,window,document);


/* end */