$(document).ready(function() {

	$('#slider').anythingSlider({
		autoPlay:true,
		delay:9000,
		startText: "",
		stopText: ""
	});

/*accordion begin*/
	$("#accordion").accordion({
//		autoHeight: false,
		active: 3,
		fillSpace: true
	});
/*accordion end*/

/* #promo auth effects begin*/
	$("#auth1_log, #auth1_pwd").parent().focusin(function() {
		$(this).find("span").fadeOut(300);
	});

	$("#auth1_log, #auth1_pwd").parent().focusout(function() {
		if ($(this).find("input").val() == "") {
			$(this).parent().find("span").fadeIn(300);
		}
	});
/* #promo auth effects end*/
	
	/*--ФИЛЬТР СЕКЦИИ МУЛЬТИМЕДИА--*/
	$('#sectionMedia ul.filter a').click(function(){
		elementID = $(this).attr('id');
		filterAction = elementID.replace('MediaFilter', '');
		if (!$('#'+elementID).hasClass('act')){
			$.ajax({
				type: 'get',
				dataType: 'json',
				url: '/listen/media.html?action='+filterAction,
				beforeSend: function(){
					$('#sectionMedia ul.media').animate({opacity: 0.3}, 200);
				},
				success: function(data){
					if (data['res'] == 1){
						mediaContent = Base64.decode(data['content']);
						$('#sectionMedia ul.media').html(mediaContent);
						$('#sectionMedia ul.media').animate({opacity: 1}, 200);
						$('#sectionMedia ul.filter a').removeClass('act');
						$('#'+elementID).addClass('act');
					}else{
						alert('Приносим извинения, попробуйте позже');
					}
				},
				error: function(){
					alert('Приносим извинения, попробуйте позже');
				}
			});
		}
	});
	
	/*--ФИЛЬТР СЕКЦИИ АФИША--*/
	$('#sectionAfisha ul.filter a').click(function(){
		elementID = $(this).attr('id');
		filterAction = elementID.replace('AfishaFilter', '');
		if (!$('#'+elementID).hasClass('act')){
			$.ajax({
				type: 'get',
				dataType: 'json',
				url: '/listen/afisha.html?action='+filterAction,
				beforeSend: function(){
					$('#sectionAfisha ul.media').animate({opacity: 0.3}, 200);
				},
				success: function(data){
					if (data['res'] == 1){
						afishaContent = Base64.decode(data['content']);
						$('#sectionAfisha ul.media').html(afishaContent);
						$('#sectionAfisha ul.media').animate({opacity: 1}, 200);
						$('#sectionAfisha ul.filter a').removeClass('act');
						$('#'+elementID).addClass('act');
					}else{
						alert('Приносим извинения, попробуйте позже');
					}
				},
				error: function(){
					alert('Приносим извинения, попробуйте позже');
				}
			});
		}
	});
	
	/*--ФИЛЬТР ДТП--*/
	$('#dtpFilter li a').click(function(){
		elementID = $(this).attr('id');
		dtpAction = elementID.replace('Dtp', '');
		if (!$(this).hasClass('act')){
			$.ajax({
				type: 'get',
				dataType: 'json',
				url: '/listen/dtp.html?action='+dtpAction,
				beforeSend: function(){
					$('#dtpContent').animate({opacity: 0.3}, 200);
				},
				success: function(data){
					if (data['res'] == 1){
						dtpContentResult = Base64.decode(data['content']);
						$('#dtpContent').html(dtpContentResult);
						$('#dtpContent').animate({opacity: 1}, 200);
						$('#dtpFilter li a').removeClass('act');
						$('#'+elementID).addClass('act');
					}else{
						alert('Приносим извинения, попробуйте позже');
					}
				},
				error: function(){
					alert('Приносим извинения, попробуйте позже');
				}
			});
		}
	});
	
	/*--ФИЛЬТР СОВМЕСТНЫХ ПОКУПОК--*/
	$('#spFilter li a').click(function(){
		elementID = $(this).attr('id');
		spAction = elementID.replace('SP', '');
		if (!$(this).hasClass('act')){
			$.ajax({
				type: 'get',
				dataType: 'json',
				url: '/listen/sp.html?action='+spAction,
				beforeSend: function(){
					$('#spContent').animate({opacity: 0.3}, 200);
				},
				success: function(data){
					if (data['res'] == 1){
						spContentResult = Base64.decode(data['content']);
						$('#spContent').html(spContentResult);
						$('#spContent').animate({opacity: 1}, 200);
						$('#spFilter li a').removeClass('act');
						$('#'+elementID).addClass('act');
					}else{
						alert('Приносим извинения, попробуйте позже');
					}
				},
				error: function(){
					alert('Приносим извинения, попробуйте позже');
				}
			});
		}
	});
});

/*--ПОСТРАНИЧКА СООБЩЕНИЙ ФОРУМА--*/
function getPage(page, category)
{
	switch (category){
		case 'forum'	: forumPage(page); break;
		case 'autoforum': autoForumPage(page); break;
		case 'autoadvert': autoAdvertPage(page); break;
		case 'doadvert'	: doAdvertPage(page); break;
	}
}

function forumPage(page)
{
	$.ajax({
		type: 'get',
		dataType: 'json',
		url: '/listen/forumthread.html?page='+page,
		beforeSend: function(){
			$('#forumThreads').animate({opacity: 0.3}, 200);
		},
		success: function(data){
			if (data['res'] == 1){
				threadContent = Base64.decode(data['content']);
				$('#forumThreads').html(threadContent);
				$('#forumThreads').animate({opacity: 1}, 200);
			}else{
				alert('Приносим извинения, попробуйте позже');
			}
		},
		error: function(){
			alert('Приносим извинения, попробуйте позже');
		}
	});
}

function autoForumPage(page)
{
	$.ajax({
		type: 'get',
		dataType: 'json',
		url: '/listen/autoforumthread.html?page='+page,
		beforeSend: function(){
			$('#autoThreads').animate({opacity: 0.3}, 200);
		},
		success: function(data){
			if (data['res'] == 1){
				threadContent = Base64.decode(data['content']);
				$('#autoThreads').html(threadContent);
				$('#autoThreads').animate({opacity: 1}, 200);
			}else{
				alert('Приносим извинения, попробуйте позже');
			}
		},
		error: function(){
			alert('Приносим извинения, попробуйте позже');
		}
	});
}

function autoAdvertPage(page)
{
	$.ajax({
		type: 'get',
		dataType: 'json',
		url: '/listen/autoadvert.html?page='+page,
		beforeSend: function(){
			$('#autoAdvert').animate({opacity: 0.3}, 200);
		},
		success: function(data){
			if (data['res'] == 1){
				$('#autoFilter li a').removeClass('act');
				$('#autoAdvertFilter').addClass('act');
				threadContent = Base64.decode(data['content']);
				$('#autoAdvert').html(threadContent);
				$('#autoAdvert').animate({opacity: 1}, 200);
			}else{
				alert('Приносим извинения, попробуйте позже');
			}
		},
		error: function(){
			alert('Приносим извинения, попробуйте позже');
		}
	});
}

function doAdvertPage(page)
{
	$.ajax({
		type: 'get',
		dataType: 'json',
		url: '/listen/autodoadvert.html?page='+page,
		beforeSend: function(){
			$('#autoAdvert').animate({opacity: 0.3}, 200);
		},
		success: function(data){
			if (data['res'] == 1){
				$('#autoFilter li a').removeClass('act');
				$('#doAdvertFilter').addClass('act');
				threadContent = Base64.decode(data['content']);
				$('#autoAdvert').html(threadContent);
				$('#autoAdvert').animate({opacity: 1}, 200);
			}else{
				alert('Приносим извинения, попробуйте позже');
			}
		},
		error: function(){
			alert('Приносим извинения, попробуйте позже');
		}
	});
}

function bvfLogOut(url)
{
	$.get(url, function(){
		window.location.reload();
	});
}
