var d = 0,
z = 0,
gallery = document.getElementById('gallery').style;
function right(len) {
d = setInterval(function() {
if(z == -len) clearInterval(d);
else gallery.left = (z -= 5) + 'px';
}, 10);
}
<img onmouseover="right(50)" onmouseout="clearInterval(d)" />