I think I misunderstood the original question. @tsnj do a search for the "Supposition" plugin. It was created to do exactly what you want. It never left beta as I think there was still a minor bug that I wasn't satisfied with but didn't get around to solving. You may find it works fine for what you want though. At the very least, you or anyone else are welcome to use the existing code and improve upon it.
Joel Birch.