Hmmm...and how do you know the value of imageset
Possibly it is coming in as a string, not a number?
Maybe you just need to do
imageset = CINT(imageset)
How about change this debug line
response.Write "(" & i & "?" & imageset & ":" & g & ")"
And you keep putting those extra parentheses into your response.write's! <grin/>