I cant troubleshoot your javascript for you, but my guess is that the problem has to do with the IDS.
since the elements "first" and "second" are in a repeat region, you are creating multiple instances of the same elements with the same ID's.
ID's for elements should be unique.
it is only loading the first one, because only the first uses a unique ID, the others are duplicates.