I think what you are looking here are onfocus and onblur events:
The onFocus, onBlur and onChange
events are often used in combination
with validation of form fields.
Below is an example of how to use the
onChange event. The checkEmail()
function will be called whenever the
user changes the content of the field:
<input type="text" size="30" id="email" onchange="checkEmail()">
In your case, you could simply add handles for onblur and onfocus events to your images and change the image via DOM as required:
<img src="image.jpg" onblur="/*switch image back to original*/"
onfocus="/*replace image*/" />
If you want to learn JavaScript, I generally recommend looking at Javascript section in W3Schools.com. If you also want to understand how DOM works in more detail, see DOM section.
This should get you started!