Import code, tidy it a bit and update for django 1.5 and jquery 1.9.1