Detect Internet connection speed

Hi everyone,

How would I go about, detecting the users Internet connection speed and then changing the quality (size) of a video depending on whether its 56k, 512k etc.

Thanks for any help!