I am not certain what your question is! If that is what you want, then make it so! Are you trying to make a code that will make the changes?
Is the posted code your product, but it doesn't work? Let us know where you are stuck, please. You have done a great ob of stating the issue, but not quite describing what you want out of us! Where are you stuck?