variable electromagnet

The part about moving it 'both ways' by changing polarity would require the solenoid to be a permanent magnet instead of just a ferrous material. What I mean is, current direction doesn't change solenoid direction in most cases, so re-evaluate what it is you want to accomplish. Most solenoids have a spring that works as the return, the current just works against the spring. Same thing at work in speakers, come to think of it.