I think this is actually a bug. Please modify your copy of include/functions.inc.php and change
$gallery_pos = strpos($template, '{GALLERY}');
// Failsafe-option if JAVASCRIPT-token is missing from custom theme
if (strpos($template, '{JAVASCRIPT}') === FALSE) {
if (stripos($template, '</head>') !== FALSE) {
$template = str_ireplace('</head>', '{JAVASCRIPT}' . $LINEBREAK . '</head>', $template);
} elseif (stripos($template, '<head>') !== FALSE) {
$template = str_ireplace('<head>', '<head>' . $LINEBREAK .'{JAVASCRIPT}', $template);
} elseif (stripos($template, '</title>') !== FALSE) {
$template = str_ireplace('</title>', '</title>' . $LINEBREAK . '{JAVASCRIPT}', $template);
}
}
to
// Failsafe-option if JAVASCRIPT-token is missing from custom theme
if (strpos($template, '{JAVASCRIPT}') === FALSE) {
if (stripos($template, '</head>') !== FALSE) {
$template = str_ireplace('</head>', '{JAVASCRIPT}' . $LINEBREAK . '</head>', $template);
} elseif (stripos($template, '<head>') !== FALSE) {
$template = str_ireplace('<head>', '<head>' . $LINEBREAK .'{JAVASCRIPT}', $template);
} elseif (stripos($template, '</title>') !== FALSE) {
$template = str_ireplace('</title>', '</title>' . $LINEBREAK . '{JAVASCRIPT}', $template);
}
}
$gallery_pos = strpos($template, '{GALLERY}');
ie. move that first line so that it comes after that block of code instead of before it.