
$(function(){
	// Кнопка "Разрешить/Запретить присоединение" в Личном кабинете
	$('#group_on_off .button').hover(function() {
		$(this).css('position', 'relative');
		$(this).parent().find('.rounded-popup').show();
	}, function() {
		$(this).css('position', 'static');
		$(this).parent().find('.rounded-popup').hide();
	});

	// Кнопка "Присоединиться/Отсоединиться" в визитке компании
	$('#user-info-header .group .button').hover(function(){
		$(this).parent().find('.rounded-popup').show();
	}, function(){
		$(this).parent().find('.rounded-popup').hide();
	});

	// Кнопки "Присоединиться/Отсоединиться/Разрешить/Запретить/Исключить" в Сообществе
	$('#content .users-list .item-actions .group .action .center a.button').hover(function() {
		$(this).css('position', 'relative');
		$(this).parent().parent().css('position', 'relative');
		$(this).parent().parent().find('.rounded-popup').show();
	}, function() {
		$(this).css('position', 'static');
		$(this).parent().parent().css('position', 'static');
		$(this).parent().parent().find('.rounded-popup').hide();
	});

	// Отобразить/Скрыть объявление группы
	$('#content .result-list1 .item .grey_links')
		.find('.action.application-hide span').click(group_app_hide)
		.end()
		.find('.action.application-show span').click(group_app_show);
});

function group_app_hide()
{
	var appid   = $(this).parent().parent().parent().parent().parent().parent().attr('request_id');
	var apphide = $(this).parent().parent().find('.action.application-hide');
	var appshow = $(this).parent().parent().find('.action.application-show');
	var appidtr   = $(this).parent().parent().parent().parent().parent().parent();
	$.post('/_ajax/group/', {
		apphide: appid
	}, function(data){
		if (data && data.js && data.js.status && data.js.status == 'ok') {
			apphide.addClass('hidden');
			appshow.removeClass('hidden');
			appidtr.removeClass('hidd');
			appidtr.addClass('hidd');
		}
	},
	'json');
}

function group_app_show()
{
	var appid   = $(this).parent().parent().parent().parent().parent().parent().attr('request_id');
	var apphide = $(this).parent().parent().find('.action.application-hide');
	var appshow = $(this).parent().parent().find('.action.application-show');
	var appidtr   = $(this).parent().parent().parent().parent().parent().parent();
	$.post('/_ajax/group/', {
		appshow: appid
	}, function(data){
		if (data && data.js && data.js.status && data.js.status == 'ok') {
			appshow.addClass('hidden');
			apphide.removeClass('hidden');
			appidtr.removeClass('hidd');
		}
	},
	'json');
}

