Are the missing spaces in your JS posted code because of an error or is this how your JS is in reality?
functionnext() {...} S/B function next() {...} etc..

And where are the images kept? Do you have a DB or do you make one in JS?
But you don't show a function to find the value
...