Looks like the function paints on the first canvas no matter what event fired it. You could do this :
...
function ev_mousemove (ev) {
var x, y;
var context = ev.target.getContext('2d');
...
Which should reroute the following functions to the correct canvas.