Simple Algebra:
AvgVotes = Sum of all votes / Sum of all items
AvgRating = Sum of up votes for all items * 5 / Sum of all votes
CurVotes = Number of votes on current item
CurRating = Sum of up votes on current item * 5/ Number of votes on current item
TotalVotes = Sum of all votes + Sum of votes on current item
((AvgVotes * AvgRating) + (CurVotes * CurRating)) * 5 / TotalVotes
So plugging in your numbers evaluating the weight for A...
AvgVotes = 1000
AvgRating = 0 (Remember do not include numbers for the item you are evaluating in this calculation)
CurVotes = 1000
CurRating = 500 * 5 / 1000 = 2.5
Total Votes = 2000 + 1000 = 3000
((1000 * 0) + (1000 * 2.5)) * 5 / 3000 = 4.166
I forgot to add, do NOT include any items in any calculation or sum above that have no votes or it will throw the weights off.
EDIT - Simplified Solution:
I should note that there is a simplified solution to the problem that can be performed. I only demonstrated longhand form for comprehension. The compressed algorithm looks like:
Definitions:
SET = Anything not related to the current evaluation target where votes is greater than zero.
TARGET = The element you are currently trying to evaluate
25*(((Sum of SET up-votes)/(Sum of SET items)) + (Sum of TARGET up-votes)) / (Sum of TARGET votes + Sum of SET votes)
Again plugging in with your numbers evaluating 'A' for clarification and proof:
(25*((0/2)+500)) / (1000+2000) = 4.166