How to make a View sorted according to votes casted on their images?

It is easy for images, voting on galleries is also possible, but meaningless. Much better will be, if we can sort galleries according to average votes casted on images, that belongs to particular gallery.