$(document).ready(function() {
	$(".person .Img A").click(function() {
		$(this).parent().prev().attr('src', $(this).attr('href'));
		return false;
	}).clearFocusBorder();
	
	$(".user-profile-menu LI:not(.disabled):not(.active-edit):not(.active)").hover(
/*		function() {
			$(this).prepend("<a href='"+$(this).attr('href')+"edit/' class='edit'>Редактировать</a>");
		}, 
		function() {
			$(this).find('.edit').remove();
		}*/
	);
	
	$(".user-profile A.delete-photo").click(function() {
		if( confirm("Удалить фотографию?") ) {
			$.get("./?delete_photo=1", function() {
				$(".photo IMG").attr('src', sHtmlRoot+'_i/ancry.gif');
				$(".user-profile A.delete-photo").hide();
			})
		}
		return false;
	});
	
	$(".user-profile A.delete-avatar").click(function() {
		if( confirm("Удалить аватарку?") ) {
			$.get("./?delete_avatar=1", function() {
				$(".avatar IMG:first").attr('src', sHtmlRoot+'_i/no_avatar.jpg');
				$(".user-profile A.delete-avatar").hide();
			})
		}
		return false;
	});
	
	$("A.delete-photo-from-album").click(function() {
		if( confirm("Удалить фотографию из альбома?") ) {
			var link = $(this);
			$.get("./?delete_photo_from_album="+link.attr('href').substring(14), function() {
				link.nextAll('TEXTAREA').val('');
				link.parents('TR').find('.photo_preview IMG').attr('src', sHtmlRoot+'_i/_.gif');
				link.hide();
			})
		}
		return false;
	});
	
	$(".photoalbum A").lightBox({
		imageBlank: sHtmlRoot + '_i/lightbox/lightbox-blank.gif',
		imageLoading: sHtmlRoot + '_i/lightbox/lightbox-btn-loading.gif',
		imageBtnClose: sHtmlRoot + '_i/lightbox/lightbox-btn-close.gif',
		imageBtnPrev: sHtmlRoot + '_i/lightbox/lightbox-btn-prev.gif',
		imageBtnNext: sHtmlRoot + '_i/lightbox/lightbox-btn-next.gif',
		containerResizeSpeed: 350,
		txtImage: 'Фотография',
		txtOf: 'из'
   });
   
   
	$(".rate-material").click(function() {
		$.getJSON("./?rate="+$(this).attr('href').substring(1), function(result) {
			$(".material-rating .plusses").html(result.p);
			$(".material-rating .minuses").html(result.m);
			$(".rate-material").fadeOut();
		});
   		return false;
	});
	
	$(".rate-anket").click(function() {
		$.getJSON("./?rate_anket="+$(this).attr('href').substring(1), function(result) {
			$(".anket-rating .plusses").html(result.p);
			$(".anket-rating .minuses").html(result.m);
			$(".rate-anket").fadeOut();
		});
   		return false;
	});
	
	$(".rate-comment").click(function() {
		var comment_id = $(this).parents('tr').attr('comment_id');
		var comments_type = $(this).parents('table').attr('comments_type');
		if( comments_type != "pubs" ) comments_type = "";
		$.getJSON("./?rate_comment="+comment_id+"&rate="+$(this).attr('href').substring(1)+"&comments_type="+comments_type, function(result) {
			$("TR[comment_id="+comment_id+"] .plusses").html(result.p);
			$("TR[comment_id="+comment_id+"] .minuses").html(result.m);
			$("TR[comment_id="+comment_id+"] .rate-comment").fadeOut();
		});
   		return false;
	});
   
   
	$("#overlay").click(function() {
		$('.ui-popup').hide();
		$('.popup').hide();
		$("#overlay").hide();
	});
	
	$(".close-popup").click(function() {
		$(this).parents('.ui-popup').hide();
		$("#overlay").hide();
		return false;
	}); 
   

	$(".add-comment").click(function() {
		$(".agree-box").attr('checked', 0);
		$(".ui-popup TEXTAREA").val('');
		$(".ui-popup :submit").attr('disabled', 1);
		$("#overlay").css('opacity', 0).show().fadeTo('fast', 0.5);
		$(".ui-popup").fadeIn('fast');
   		return false;
	});
	
	$('.agree-box').click(function() {
		$(".ui-popup :submit").attr('disabled', 1-$(this).attr('checked'));
	});
	
	
	$(".reply-quote").click(function() {
		$(".agree-box").attr('checked', 0);
		$(".ui-popup :submit").attr('disabled', 1);
		$(".ui-popup TEXTAREA").val('[QUOTE USER='+$(this).parents('TD:first').prev().find('STRONG A').html()+']'+$(this).prev().attr('orig')+'[/QUOTE]');
		$("#overlay").css('opacity', 0).show().fadeTo('fast', 0.5);
		$(".ui-popup").fadeIn('fast');
   		return false;
	});
	
	$(".user-status:not(.my) A").hover(
		function() {
			$(this).data("old_txt", $(this).html());
			$(this).html('Изменить')
		},
		function() {
			$(this).html($(this).data("old_txt"))
		}
	).click(function() {
		$("#overlay").css('opacity', 0).show().fadeTo('fast', 0.01);
		$(this).nextAll('.popup').show();
   		return false;
	});

	$(".user-status .popup INPUT:button").click(function() {
		if( uid = $(this).parents('.one-friend').attr('user_id') )  {
			document.location.href="./?"+$(this).attr('action')+"=1"+"&uid="+uid;
		} else {
			document.location.href="./?"+$(this).attr('action')+"=1";
		}
   		return false;
	});
	
	$(".delete-comment").click(function () {
		var comment_id = $(this).parents('TR').attr('comment_id');
		if(confirm('Удалить этот комментарий?')) {
			document.location.href = './?delete_comment='+comment_id;
		}
	});
	
	 InitPubsCalendar();
	
});

function InitPubsCalendar() {
	$(".calendar-for-year A.arr").click(function() {
		ParDiv = $(this).parents(".calendar-for-year");
		ParDiv.hide();
		($(this).is('.leftarr')?ParDiv.prev():ParDiv.next()).show();
		return false;
	});
		
	
}

