Pretty lengthy code. I'm quite positive noone feels like sitting here and explaining it to you, but you can read up on a Dialogue tutorial. It should help you about 90% of the way, the rest is self explanatory.
Hold on and i'll try and find it for you.