If you need only loop then it should look like this (inside run_scan
)
var i = 0;
function loop() {
if (++i < lines) {
$(mask).animate({
'left':origin_left+$(mask).width()
},{
duration:duration,
complete:loop
});
} else {
// last line
callback();
}
}