Single Page PDFs from Indesign

I’m trying to get an applescript to make single page PDF’s out of Indesign CS3.
The script works fine, but as soon as you section the pages (add page numbers, 255,256,257…etc),
the script no longer works as it is supposed to.
If I put the page numbers back to (1,2,3,4…etc.) it works again.
This one has me totally baffled.
Not sure if the problem is in the script or a setting in Indesign.

Any help would be great.
Thank You in advance.

tell application "Adobe InDesign CS3"
   tell (active document) to set {file_name, doc_pages, page_numbers} to {name, pages, name of pages}
   set pdf_style to name of PDF export presets
   set export_style to (choose from list pdf_style with prompt "Select PDF Export Preset") as string
   if export_style is "false" then return
   set folder_path to (choose folder with prompt "Select folder to Save PDF files") as string
   set oldPref to page numbering of general preferences
   set page numbering of general preferences to absolute
   set pagesToPrint to (choose from list page_numbers with prompt "Choose Pages to PDF" with multiple selections allowed)
   if pagesToPrint is false then return
   repeat with anItem in pagesToPrint
       if length of anItem is 4 then
           set new_number to contents of anItem
           set new_number to text -3 thru -1 of ("00" & anItem)
       end if
       set PDF_name to folder_path & file_name & "_" & new_number & ".pdf"
       set page range of PDF export preferences to (anItem as string)
       tell active document to export format PDF type to PDF_name using export_style without showing options
   end repeat
   set page numbering of general preferences to oldPref
   display dialog "Your PDFs are Done" buttons {"Done"} default button 1
end tell

Model: iMac
AppleScript: Version 2.1.1 (81)
Browser: Safari 525.22
Operating System: Mac OS X (10.4)


I guess it’s the script thats at fault here, i’ve never scripted this part of indesign before but looking at the dictionary
it looks like sectioning has its own commands so you need to be putting in some logic to allow for whether the pages are sections or standard pages.