Forum OpenACS Q&A: AJAX with xowiki yui-carousel includelet

I am converting the xowiki yui-carousel includelet to enable deferred loading of thumbnails using an asyncRequest, like this:

http://developer.yahoo.com/yui/examples/carousel/csl_dynload2.html

To do this I need to write some serverside code to return the required image urls, paginated as required, as a JSON array.

How is this best done?

i) By writing a *.tcl script in ./packages/xowiki/www/ajax (using the existing chat.tcl as a model)?

or

ii) By creating an xowiki page that contains the code required and using '?master=0' when requesting the url from Javascript?

(I have already implemented the spotlight functionality with deferred loading of the large image, which works very well, but if I can sort out the deferred loading of the thumbnails too, it will mean the yui-carousel includelet will behave well even with very large numbers of images).

Many thanks
Richard