$(document).ready(function() {
		
	$('.top-menu li:has(div)').hover(
		function() {
			$('.hidden-menu').stop().hide();
			$(this).find('.hidden-menu').slideDown(300);
			$(this).addClass('menuactive');
		}, function() {			
			$(this).find('.hidden-menu').slideUp(0);		
			$(this).removeClass('menuactive');
	});
	
			var swiper = new Swiper('.sld1', {
				paginationClickable: true,
				pagination: '.swiper-pagination1'
				//loop: true
			});
			
			var swiper = new Swiper('.sld2', {
				paginationClickable: true,
				pagination: '.swiper-pagination2'
			});
	
	
	
	// рейтинг
	$('.main-news-rating .masha_index').remove();
	
	$('.main-news-rating').each(function(){
		var currentRating = $(this);
		currentRating.addClass('rating-done');
		var ratingValue = parseInt(currentRating.find('.frating').text());
		var ratingPeople = parseInt(currentRating.find('.main-ration-votes').text());
		
		if ( ratingValue > 0 ) {	
			
			rMinus = (ratingPeople-ratingValue)/2;
			rPlus = ratingPeople-rMinus;
			
			rPrcent = rPlus*100/ratingPeople;
			
			var currentPRC = rPrcent.toFixed(0);
			currentRating.find('.main-news-rating-proc').css({'width':''+currentPRC+'%'});
			currentRating.find('.main-news-rating-i').append(''+currentPRC+'%');
			
		} if ( ratingValue<0 ) {
				currentRating.find('.rating-o').removeAttr('style');
				currentRating.find('.rating-o').addClass('badrating');
				
				rMinus = (ratingPeople-ratingValue)/2;
				rPlus = ratingPeople-rMinus;
				
				rPrcent = rMinus*100/ratingPeople;
				
				var currentPRC = rPrcent.toFixed(0);
				currentRating.find('.main-news-rating-i').append('-'+currentPRC+'%');
				currentRating.find('.main-news-rating-proc').css({'width':''+currentPRC+'%'}).addClass('main-news-rating-proc2');
				
			} 
				
		if ( ratingValue == 0 ) {
			currentRating.find('.main-news-rating-i').append('0%');
		}
	});
	
	
	$('body').on('click', '.main-news-play', function(){
		$('.play-box').remove();
		$('.pause').hide();
		$('.main-news-play').show();
		$('.main-news-title').removeClass('active-song-title');
		var sdsdf = $(this);
		var playPage = $(this).attr('rel');
			
			var currentBlock = $(this).parent();		
			$.ajax({ 
				url: playPage, 
				success: function(data){
					var currentAudioLink = $(data).find('.full-news-player .dleaudioplayer li').data('url');
					
					$('body').append('<audio class="play-box" autoplay="autoplay"><source src="'+currentAudioLink+'" type="audio/mpeg"></audio>');
					sdsdf.hide();
					currentBlock.find('.pause').show();
					
					/*$('.pause').click(function(){
						$('.play-box').remove();
						sdsdf.show();
						$(this).hide();
					});*/	
					
					currentBlock.parent().parent().find('.main-news-title').addClass('active-song-title');
					
				}
			});
			
			
		
	});
	
	$('.pause').click(function(){
		$('.play-box').remove();
		$('.main-news-play').show();
		$(this).hide();
		$('.main-news-title').removeClass('active-song-title');
	});	
	
	
	$('.load-button').click(function(){
		var nextPage = $('#hidden-next-page a').attr('href');
		
		if (nextPage !== undefined) {
			$.ajax({ 
				url: nextPage, 
				success: function(data) { 
					$('.load-box').append($('.load-box', data).html()).imagesLoaded(function(){
						  //
						  
						  // рейтинг
							$('.main-news-rating .masha_index').remove();
							
							$('.load-box .main-news-rating:not(.rating-done)').each(function(){
								var currentRating = $(this);
								currentRating.addClass('rating-done');
								var ratingValue = parseInt(currentRating.find('.frating').text());
								var ratingPeople = parseInt(currentRating.find('.main-ration-votes').text());
								
								if ( ratingValue > 0 ) {	
									
									rMinus = (ratingPeople-ratingValue)/2;
									rPlus = ratingPeople-rMinus;
									
									rPrcent = rPlus*100/ratingPeople;
									
									var currentPRC = rPrcent.toFixed(0);
									currentRating.find('.main-news-rating-proc').css({'width':''+currentPRC+'%'});
									currentRating.find('.main-news-rating-i').append(''+currentPRC+'%');
									
								} if ( ratingValue<0 ) {
										currentRating.find('.rating-o').removeAttr('style');
										currentRating.find('.rating-o').addClass('badrating');
										
										rMinus = (ratingPeople-ratingValue)/2;
										rPlus = ratingPeople-rMinus;
										
										rPrcent = rMinus*100/ratingPeople;
										
										var currentPRC = rPrcent.toFixed(0);
										currentRating.find('.main-news-rating-i').append('-'+currentPRC+'%');
										currentRating.find('.main-news-rating-proc').css({'width':''+currentPRC+'%'}).addClass('main-news-rating-proc2');
										
									} 
										
								if ( ratingValue == 0 ) {
									currentRating.find('.main-news-rating-i').append('0%');
								}
							});
						  
						  //
						});
					$('.load-block .navigation:first').remove();
					$('#hidden-next-page').remove();
				}
			});
			
			
		} else {
			$('.load-button').remove();
			$('.load-block center').append('больше нет музыки...');
		}
		
		return false;
	});
	
	
	var topPlace = $('.top-singer');
	for (i=0;i<=topPlace.length;i++) {
		$(topPlace[i]).find('i').append(i+1);
	};
	
	
	$('.footer-up').click(function(){
		$('body,html').animate({
            scrollTop: 0
        }, 800);
        return false;
	});
	
	
	$('.mob-menu').click(function(){
		$('.top-menu, .sgdhg').slideToggle();
	});
	
});
