function animate(elemname, duration_ms, step_ms) {
var elem = document.getElementById(elemname);
var start_time = new Date();
var x = 0;
do {
elem.style.left = x;
x = (x + 10) % 200;
hold(step_ms);
} while (duration_ms > new Date() - start_time);
}
animate("animated_element_1", 10000, 100)
@
animate("animated_element_2", 7000, 80);
alert("all done");