working prototype I made earlier on jsFiddle