function p505_gallery_changePhoto(direction)
{
	data = $('#p015_gallery_photos_srcs').children();
	dataCanRates = $('#p015_gallery_photos_canrates').children();
	dataRatingFinals = $('#p015_gallery_photos_ratingfinals').children();
	dataIds = $('#p015_gallery_photos_ids').children();
	
	if(direction == 1)
	{
		p505_gallery_bigPhoto_TheLast++;
		
		if(data[p505_gallery_bigPhoto_TheLast] == null)
		{
			p505_gallery_bigPhoto_TheLast = 0;
		}
	}
	else
	{
		p505_gallery_bigPhoto_TheLast--;
		
		if(data[p505_gallery_bigPhoto_TheLast] == null)
		{
			p505_gallery_bigPhoto_TheLast = data.length - 1;
		}
	}
	
	if(data[p505_gallery_bigPhoto_TheLast] != null)
	{
		$('#p505_gallery_bigPhoto').attr("src", path + 'data/' + data[p505_gallery_bigPhoto_TheLast].innerHTML);
		
		p505_gallery_makeRatingForPhoto(dataIds[p505_gallery_bigPhoto_TheLast].innerHTML, dataCanRates[p505_gallery_bigPhoto_TheLast].innerHTML, dataRatingFinals[p505_gallery_bigPhoto_TheLast].innerHTML, p505_gallery_bigPhoto_TheLast);
		
		document.location.hash = p505_gallery_bigPhoto_TheLast;
		
		p505_gallery_updateNumberOfPhoto();
		p505_gallery_updateCommentForm(dataIds[p505_gallery_bigPhoto_TheLast].innerHTML);
		p505_gallery_updateCommentsText(dataIds[p505_gallery_bigPhoto_TheLast].innerHTML);
	}
}

function p505_gallery_showPhoto(key)
{
	key = key.substr(1, key.length);
	
	data = $('#p015_gallery_photos_srcs').children();
	dataCanRates = $('#p015_gallery_photos_canrates').children();
	dataRatingFinals = $('#p015_gallery_photos_ratingfinals').children();
	dataIds = $('#p015_gallery_photos_ids').children();
	
	if(data[key] != null)
	{
		$('#p505_gallery_bigPhoto').attr("src", path + 'data/' + data[key].innerHTML);
		
		p505_gallery_makeRatingForPhoto(dataIds[key].innerHTML, dataCanRates[key].innerHTML, dataRatingFinals[key].innerHTML, key);
		
		document.location.hash = key;
		
		p505_gallery_bigPhoto_TheLast = key;
	}
	
	p505_gallery_updateNumberOfPhoto();
	p505_gallery_updateCommentForm(dataIds[key].innerHTML);
	p505_gallery_updateCommentsText(dataIds[key].innerHTML);
}

function p505_gallery_updateNumberOfPhoto()
{
	data = $('#p015_gallery_photos_srcs').children();
	
	$('#p505_gallery_actualNumberOfPhoto').text(parseInt(p505_gallery_bigPhoto_TheLast) + 1);
	
	if(data[p505_gallery_bigPhoto_TheLast] == null)
	{
		$('#p505_gallery_actualNumberOfPhoto').text("0");
	}
}

function p505_gallery_updateCommentForm(id)
{
	$("#p505_groupGalleryAlbumDetail_commentsForm").text("");
	
	if(p504_auth == "1")
	{
		p504_frontend_commentsMakeForm('p505_groupGalleryAlbumDetail', id, 5);
	}
}

function p505_gallery_updateCommentsText(id)
{
	$("#p505_groupGalleryAlbumDetail_comments").text("");
	$("#p505_groupGalleryAlbumDetail_comments").prepend($("#p015_photo_DATA_comments" + id).html());
}

function p505_gallery_loadAllCommentsText(id, idElement, updateThePhoto)
{
	$.post(path + language + '/p505_frontend_groupGalleryAlbumDetail_AJAX_getComments/',
		{
			id: id,
			path: path
		},
		function(text)
		{
			$("#" + idElement + "_commentsCache").text('');
			$("#" + idElement + "_commentsCache").append(text);
			
			p505_gallery_updateCommentsText(updateThePhoto);
		}
	);
}
