I tried to dig up some links for you re: InDesign's excellent support for automation in Javascript, but it seems like recent changes to Adobe help resources have caused link breakage, e.g. what should have been a link to the CS5 Scripting Guide was actually a page about how cool InDesign CS6 is going to be. In Turkish. You don't read Turkish, do you?
If not, forums regular Jongware has a bunch of really useful Javascript reference material publicly available in a variety of formats.You may want to pay a visit to the InDesign Scripting Forum if you are interested in that kind of thing.