This is a standard quadrature rotary encoder. You find lots of examples in the playground article:
http://arduino.cc/playground/Main/RotaryEncoders