You would have to create some kind of mechanism to keep the overall state of interaction. This mechanism would be the client side equivalent of the server side viewstate. I suppose you could use global variables to do it. Here the lifetime of the javascript variables is explained.
The lifetime of Global variables starts when they are declared, and ends when the page is closed.
Having these said, you would use a variable counting the hovering times of the specific user. Then you would check the hover times AND your condition. Your code should look something like this:
globalHoverCount = globalHoverCount + 1;
if(globalHoverCount=1){ //globalHoverCount is the global variable
if($('img[src*="01"]')){
$('img').mouseover(function () {
$(this).attr('src', function(i, src) {
return src.replace( '01', '02' );
});
}) }
}
Hope I helped!