This should be easy. Just remove your code on lines 9-11. Then we check if the id's first character is the same as the last image clicked id's first character.
Since you made the first IDs 1a, 2a, and 3a, and the second IDs 1b, 2b, and 3b, it's easy to detect when they are the same.
1a will be the same as 1b, if you designed the html correctly (which you didn't, somewhat).
Here is the small change I made: http://jsfiddle.net/thetenfold/kRz59/
To demonstrate the change, you can change the 1b image's src to anything you want, but it will always match up with 1a (and even 1c, 1d, etc).