Kirupa XML Photogallery question

Does anybody knows how to make the next and prev button in the Kirupa XML photogallery code disappear(prev) when the first image is loaded and (next) when the last one is loaded and then be both visible when there’s an image before and after?This is the link:
http://www.kirupa.com/developer/mx2004/xml_flash_photogallery.htm
Thanks a lot
Massimo