The script is far too long to be posted in a script code. Please download the demo.