Link variants to certain product image code

I have the debut theme and made custom variants I coded myself, I want to link these to a certain photo on my product page. I understand there is a conventional way of doing this in the product editor, however since these variants are custom I will need to code this from scratch probably using the onclick function to cause the image to show.

Can someone point me in the right direction to how this normally runs when you select the variant image in the product editor, or the code that is used to do this.

That way I can see how it normally works and can try and code it into my site myself.