Are you familiar with the advanced editor and in particular scripting? If you don't know how to do either of these things any advice we give you won't make any sense.
You can find articles on both of these topics here (look under the Advanced Editor subheading to learn about the basics, like variables and so on, and under Scripting to learn the more advanced stuff).
If you already know how to work both of these features (or are having trouble learning them) just reply to this and we'll help you out. It's possible to do what you're asking without scripting, but it'll make things a lot easier to keep track of if you do use it.