Well, that JavaScript turned into a giant clusterfuck really quickly. Oh well.