Check out click castsequence.
Bigfish has a thread in the macro forum.

Jafula has a macro thread, which is a sticky.
The first post links to Bigfish's thread, as well as to the wiki with a lot of examples of this.

It is a priority system.
Where the first spell that is available casts.
And you determine with commas (no action on this click), how long until the first spell is ready to cast again.
While a given spell is on a comma stage, the next spell that is not on a comma can cast.