Fixed bug with material selection dialog

@aelx311: Check it out and merge it in if it works for you. 

Two changes:

1. Renamed a bunch of arrays that were called 'item' to make it clear they were arrays. (first 3 commits)
2. Fixed the dialog selection bug (most recent commit - see commit message for detailed description)