Oh dear that's approaching the limits of my JS knowledge, googling around seems to suggest doing it though.