rejigged script to be a jquery plugin, may change in future again