The gearbox is one of the coolest parts of the washing machine. If you spin the pulley on the gearbox one way, the inner shaft turns slowly back and forth, reversing direction about every half-revolution. If you spin the pulley the other way, the flange spins at high speed, spinning the whole tub with it.
Here you can see a gear with a link attached to it. This link is just like the one attached to an old steam train wheel -- as the gear (along with the link) turns, it pushes another pie-shaped piece of gear back and forth. This pie-shaped gear engages a small gear on the inner shaft, which leads to the spline. In addition to rotating the inner shaft in alternating directions, there are other gears within the system that provide a gear reduction to slow the rotation. Because the motor spins only at one speed, spin-cycle speed, a gear reduction is necessary to facilitate the slower wash cycle.
When the washer goes into spin cycle, the whole mechanism locks up, causing everything to spin at the same speed as the input, which is hooked up to the motor. The interesting thing here is that when the motor spins the gearbox in one direction, the agitator runs, and when it spins it the other way, the whole machine locks up. How does it do this?
In the figure above, notice the gear with the angled teeth. There is also a smaller gear with angled teeth behind the big one in the foreground. These are the only two gears with angled teeth. Depending on which way the gears are spinning, the angle on the teeth will tend to force the inner gear to slide either to the left or to the right inside the gearbox. If it slides to the left, it engages a mechanism that locks up the gearbox.
You can see a small notch in the outer shaft. This notch is hollow, and is attached to the shaft with the small helical gear. When the small gear moves, it moves this outer shaft with it, and the small notch engages the single tooth that is fixed to the lockup mechanism. When the gearbox is locked up, both the inner shaft, which drives the agitator, and the outer shaft, which drives the tub, spin at the same speed as the input pulley.