The image below shows all the internal parts that make it work. The pivot (middle part) is mounted vertically with the wide end plugged into a mounting hole in the bottom of the car frame. The pointed end is what the pivot arm (bottom piece) is mounted and balanced on, and the horse heads are clipped into the pivot arm ends.
So it basically just uses a simple pendulum effect for action. Most of the action of the heads moving in and out is accomplished going in and coming out of curves.