If you use
PHP it will have to reload the page, and if you use JavaScript it may not depending on how you code it. By the way, Java is a completely different language than JavaScript.
The easiest way to do this is to set up a variable. And default it to 0.
Then check if the variable is = 0 and if so display the first 3 images.
Else Display the others ones.
Only way I personally know to do this in
PHP is to use Session Variabls. Just
click here for more information on Sessions.