Ho questa gallery mista php/js che non ne vuole sapere di andare, non so più che farci.. c'è un'anima pia in grado di darmi una mano? sono abbastanza disperata

In pratica dovrebbe cambiarmi l'src del'immagine chiamata enlarged e caricarmi quella invece pescata dinamicamente dalla cartella sul server.
Un'effetto ingrandimento fatto cambiando l'src di enlarged.

Ecco il codice della pagina:

codice:
						<tr>
							<td valign="top" style="padding:10px; width:304px; height:380px;">
									<?
									
									// CONFIGURATION
									
										$cols = 4; // columns number
										$table_bg_color = "black";  // table background color
										$table_border = "0";  // table border size
										$table_width = "100%";  // table width
										
										$width = 250;
										$height = 20;
										
									// DO NOT EDIT BELOW
									
										$i =1;
										$files = array ();
										$myDirectory = opendir("gallery/thumbs");
										echo "<table width='$table_width' border ='$table_border' cellpadding='1' cellspacing='0'><tr>";
										while ($file = readdir($myDirectory)) {
									  
										if (($file != ".") && ($file != "..") && ($file != "index.php") && !(is_dir("gallery/$file")) )
										{
									    $files[] = $file;
										if (is_int($i / $cols)) {
										list($width, $height) = getimagesize("gallery/$file");
										echo "<td align='center'>";
										echo "<a href='#' onClick='document.enlarged.src = gallery/$file;'>";
										echo "[img]gallery/thumbs/$file[/img]</a>";
										echo "</td></tr><tr>";
										}
										else
										{
										list($width, $height, $type, $attr) = getimagesize("gallery/$file");
										echo "<td align='center'>";
										echo "<a href='#' onClick='document.enlarged.src = gallery/$file;'>";
										echo "[img]gallery/thumbs/$file[/img]</a>";
										echo "</td>";
										}
										$i++;
										}
										}
										echo "</tr></table>";
										closedir($myDirectory);
										?>
								</td>
								<td valign="top" align="center" style="padding:10px 10px 10px 0px; width:420px;">
										[img]images/enlarge.gif[/img]
								</td>
						</tr>