function p505_gallery_makeRatingForPhoto(id, canRate, finalRate, key)
{
	cache = '';
	
	if(canRate == 1) { cache += '<a onClick="p505_gallery_makeRatingForPhoto_action(\'' + id + '\', \'' + key + '\', 1); return false;" href="#" onmouseover="p508_rating_mouseActive(\'' + id + '\', 1, 1, ' + finalRate + ', \'p505_gallery_rating_star\');" onmouseout="p508_rating_mouseActive(\'' + id + '\', 0, 1, ' + finalRate + ', \'p505_gallery_rating_star\');">'; }
	cache += '<span id="p505_gallery_rating_star1">1</span>';
	if(canRate == 1) { cache += '</a>'; }
	
	if(canRate == 1) { cache += '<a onClick="p505_gallery_makeRatingForPhoto_action(\'' + id + '\', \'' + key + '\', 2); return false;" href="#" onmouseover="p508_rating_mouseActive(\'' + id + '\', 1, 2, ' + finalRate + ', \'p505_gallery_rating_star\');" onmouseout="p508_rating_mouseActive(\'' + id + '\', 0, 2, ' + finalRate + ', \'p505_gallery_rating_star\');">'; }
	cache += '<span id="p505_gallery_rating_star2">2</span>';
	if(canRate == 1) { cache += '</a>'; }
	
	if(canRate == 1) { cache += '<a onClick="p505_gallery_makeRatingForPhoto_action(\'' + id + '\', \'' + key + '\', 3); return false;" href="#" onmouseover="p508_rating_mouseActive(\'' + id + '\', 1, 3, ' + finalRate + ', \'p505_gallery_rating_star\');" onmouseout="p508_rating_mouseActive(\'' + id + '\', 0, 3, ' + finalRate + ', \'p505_gallery_rating_star\');">'; }
	cache += '<span id="p505_gallery_rating_star3">3</span>';
	if(canRate == 1) { cache += '</a>'; }
	
	if(canRate == 1) { cache += '<a onClick="p505_gallery_makeRatingForPhoto_action(\'' + id + '\', \'' + key + '\', 4); return false;" href="#" onmouseover="p508_rating_mouseActive(\'' + id + '\', 1, 4, ' + finalRate + ', \'p505_gallery_rating_star\');" onmouseout="p508_rating_mouseActive(\'' + id + '\', 0, 4, ' + finalRate + ', \'p505_gallery_rating_star\');">'; }
	cache += '<span id="p505_gallery_rating_star4">4</span>';
	if(canRate == 1) { cache += '</a>'; }
	
	if(canRate == 1) { cache += '<a onClick="p505_gallery_makeRatingForPhoto_action(\'' + id + '\', \'' + key + '\', 5); return false;" href="#" onmouseover="p508_rating_mouseActive(\'' + id + '\', 1, 5, ' + finalRate + ', \'p505_gallery_rating_star\');" onmouseout="p508_rating_mouseActive(\'' + id + '\', 0, 5, ' + finalRate + ', \'p505_gallery_rating_star\');">'; }
	cache += '<span id="p505_gallery_rating_star5">5</span>';
	if(canRate == 1) { cache += '</a>'; }
	
	$('#gallery-detail-rating').text('');
	$('#gallery-detail-rating').prepend(cache);
	
	p508_rating_mouseActive_turnOn(finalRate, 'p505_gallery_rating_star');
}

function p505_gallery_makeRatingForPhoto_action(id, key, number)
{
	$.post(path + language + '/' + p505_gallery_makeRatingForPhoto_action_URL + '/',
		{
			id: id,
			number: number,
		},
		function(xml)
		{		
			message = $(xml).find('message').text();
			
			if(message == '1')
			{
				rating = $(xml).find('rating').text();
				
				$('#p015_gallery_photos_canrates_' + key).text(0);
				$('#p015_gallery_photos_ratingfinals_' + key).text(rating);
				
				p505_gallery_makeRatingForPhoto($('#p015_gallery_photos_ids_' + key).text(), $('#p015_gallery_photos_canrates_' + key).text(), $('#p015_gallery_photos_ratingfinals_' + key).text(), key);
			}
		}
	);
}
