Personally I think this can all be done server side fairly easily. Going to take a quick stab at it.