From Adobe InDesign CS2 Scripting Guide (pages 13-14)
When you are iterating through a collection, JavaScript insists that the type of the item is the type of the
collection. When you iterate through a pageItems collection, for example, the type of each item will be
PageItem, rather than Rectangle, Oval, Polygon, GraphicLine, or TextFrame. To get the specific type
of an item when you are iterating through a collection of unlike items, use the getElements() method, as
shown in the following example:
for(myCounter = 0; myCounter < app.activeDocument.pages.item(0).pageItems.length; myCounter ++){
var myPageItem = app.activeDocument.pages.item(0).pageItems.item(myCounter);
var myPageItemType = myPageItem.getElements()[0].constructor.name;
alert(myPageItemType);
}