Nice explanation. I keyed in on a relational table as in having a foreign key connection to the primary table as opposed to a many-to-many relationship. I don't use the WA behavior for this often because I find it often does not meet my needs and is not an easy to customize behavior. The extension would be much better if you could access the repeating value for other dynamic values like having a repeat region with an image id in the checkbox and a hidden value for something like sort_<?php echo $RepeatSelectionCounter_1; ?>, but I have not been able to get it to do that. The only indexed values I have been able to access of the master key and the "options table" key.
Can you expand a bit on what you are trying to accomplish. I see where your code could be helpful, but I'm not sure it is the same as what you are trying to do.
If you just want to display the images in the same order as the order of the selected check boxes, you can sort the subset of the relational table (get the images where page ID = x through the relational table) by the relational table's id. The inserts are done in the order the check boxes are submitted, so that would produce the same order without extra code. If the check boxes are updated later with earlier ones, you could use the same sort process as whatever value determines the order of the check boxes, to get the same thing.
If you have a sort field on your images, you can use that in a joined table recordset to get the images connected to a page to sort in the image sort order.
Where I see this being helpful is to get sort values into the many-to-many relational table so that you could open the page's images in a separate process (through the relational table), and resort the images for that page. The same images could appear in a different order on each page.
Is that what you are trying to do or am I missing something?