For dynamic generated elements, you need to delegate event. For example:
$(document).on('click','#img1', function(){
img = 'produzione1.gif';
$('#macchine img').attr("src", img);
});
Now instead of using document, you should delegate to closest static container, maybe:
$(document).ready(function () { // when the document is loaded
var img;
$('.container').on('click', '#img1', function () {
img = 'produzione1.gif';
$('#macchine img').attr("src", img);
return false;
});
});