I'm not sure I fully understand the problem, and whether this is a design or implementation question. Break the problem down into its individual requirements. I'll give you my thoughts on the design...