This could probably be optimised a fair bit, but here is a basic example of how you could do it using setInterval
and clearInterval
Fiddle
Update
Here is another example of it wrapped into a function instead, bit easier to tweak the speed etc.
Fiddle