#
# FUNKTION: Erstellung einer HTML-Datei für die Steuerung der Bilder-Galerie
#
INC_NAME_INDEX_GALLERY='inc_index_html_file_gallery.txt'

# Variablen überprüfen
PICTURE_NUMBERS=${PICTURE_NUMBERS:=1}
TEXT_FILE_DIRECTORY=${TEXT_FILE_DIRECTORY:='EMPTY'}
CSS_DIRECTORY=${CSS_DIRECTORY:='EMPTY'}
EXTRA_DIRECTORY=${EXTRA_DIRECTORY:='EMPTY'}
HTML_EXTRA_DIRECTORY=${HTML_EXTRA_DIRECTORY:='EMPTY'}
IMAGES_EXTRA_DIRECTORY=${IMAGES_EXTRA_DIRECTORY:='EMPTY'}
TOOLS_MENUE_GLOBAL_FEED_LINE_A=${TOOLS_MENUE_GLOBAL_FEED_LINE_A:='EMPTY'}
TOOLS_MENUE_GLOBAL_FEED_LINE_B=${TOOLS_MENUE_GLOBAL_FEED_LINE_B:='EMPTY'}
CHAPTER_LINK_COUNT_MAX=${CHAPTER_LINK_COUNT_MAX:=5}
HTML_PAGES_LINK_COUNT_MAX=${HTML_PAGES_LINK_COUNT_MAX:=5}
GALLERY_LINK_NAME_MAX_CHAR=${GALLERY_LINK_NAME_MAX_CHAR:=25}
PICTURE_GALLERY_INFORMATION_FILE_NAME=${PICTURE_GALLERY_INFORMATION_FILE_NAME:='EMPTY'}
GALLERY_FILE_NAME_STYLESHEET=${GALLERY_FILE_NAME_STYLESHEET:='EMPTY'}
GALLERY_FILE_NAME_FAVICON=${GALLERY_FILE_NAME_FAVICON:='favicon.ico'}
PICTURE_GALLERY_NAME_TITLE_TAG=${PICTURE_GALLERY_NAME_TITLE_TAG:='Kobold'}
GALLERY_TITLE_MAX_CHAR=${GALLERY_TITLE_MAX_CHAR:=128}
PICTURE_GALLERY_NAME_DEFAULT=${PICTURE_GALLERY_NAME_DEFAULT:='Picture-Gallery'}
GALLERY_CHARSET=${GALLERY_CHARSET:='utf-8'}
# LANGUAGE_NAME_PART_B -> inc_language_selection.txt
LANGUAGE_NAME_PART_B=${LANGUAGE_NAME_PART_B:='EMPTY'}
GALLERY_INDEX_TEXT_INFO=${GALLERY_INDEX_TEXT_INFO:='Information'}
GALLERY_INDEX_TEXT_INFO_ALT=${GALLERY_INDEX_TEXT_INFO_ALT:='Information'}
GALLERY_INDEX_TEXT_START=${GALLERY_INDEX_TEXT_START:='START'}
GALLERY_INDEX_TEXT_PREVIOUS=${GALLERY_INDEX_TEXT_PREVIOUS:='PREVIOUS'}
GALLERY_INDEX_TEXT_NEXT=${GALLERY_INDEX_TEXT_NEXT:='NEXT'}
GALLERY_INDEX_TEXT_END=${GALLERY_INDEX_TEXT_END:='END'}
GALLERY_INDEX_TEXT_SLIDESHOW=${GALLERY_INDEX_TEXT_SLIDESHOW:='Slide projector'}
GALLERY_INDEX_TEXT_SECOND=${GALLERY_INDEX_TEXT_SECOND:='Sec.'}
GALLERY_INDEX_TEXT_SLIDSHOW_START=${GALLERY_INDEX_TEXT_SLIDSHOW_START:='START'}
GALLERY_INDEX_TEXT_SLIDSHOW_STOP=${GALLERY_INDEX_TEXT_SLIDSHOW_STOP:='STOP'}
GALLERY_CHARSET=$(echo ${GALLERY_CHARSET} | tr [:upper:] [:lower:])
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 1-1 \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
  exit 1
  fi
if [ "${LANGUAGE_NAME_PART_B}" = 'EMPTY' ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 1-2 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
LANGUAGE_NAME_PART_B=$(echo ${LANGUAGE_NAME_PART_B} | tr [:upper:] [:lower:])
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 1-3 \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
  exit 1
  fi
LANGUAGE_SHORT_CODE=$(echo ${LANGUAGE_NAME_PART_B} | tr [:lower:] [:upper:])
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 1-4 \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
  exit 1
  fi
PICTURE_GALLERY_FILE_NAME_PART_A=${PICTURE_GALLERY_FILE_NAME_PART_A:='EMPTY'}
PICTURE_GALLERY_FILE_NAME_PART_B=${LANGUAGE_NAME_PART_B}
PICTURE_GALLERY_FILE_NAME_PART_C=${PICTURE_GALLERY_FILE_NAME_PART_C:='EMPTY'}
if [ "${PICTURE_GALLERY_FILE_NAME_PART_A}" = 'EMPTY' ] || [ "${PICTURE_GALLERY_FILE_NAME_PART_B}" = 'EMPTY' ] || [ "${PICTURE_GALLERY_FILE_NAME_PART_C}" = 'EMPTY' ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 1-5 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
TEXT_FILE_NAME_CHAPTER_LIST_PART_A=${TEXT_FILE_NAME_CHAPTER_LIST_PART_A:='EMPTY'}
TEXT_FILE_NAME_CHAPTER_LIST_PART_B=${LANGUAGE_NAME_PART_B}
TEXT_FILE_NAME_CHAPTER_LIST_PART_C=${TEXT_FILE_NAME_CHAPTER_LIST_PART_C:='EMPTY'}
TEXT_FILE_NAME_EXTRA_HTML_FILE_LIST_PART_A=${TEXT_FILE_NAME_EXTRA_HTML_FILE_LIST_PART_A:='EMPTY'}
TEXT_FILE_NAME_EXTRA_HTML_FILE_LIST_PART_B=${LANGUAGE_NAME_PART_B}
TEXT_FILE_NAME_EXTRA_HTML_FILE_LIST_PART_C=${TEXT_FILE_NAME_EXTRA_HTML_FILE_LIST_PART_C:='EMPTY'}
PICTURE_GALLERY_EXTRA_HTML_PAGE_NAME_PART_A=${PICTURE_GALLERY_EXTRA_HTML_PAGE_NAME_PART_A:='EMPTY'}
PICTURE_GALLERY_EXTRA_HTML_PAGE_NAME_PART_B=${LANGUAGE_NAME_PART_B}
PICTURE_GALLERY_EXTRA_HTML_PAGE_NAME_PART_C=${PICTURE_GALLERY_EXTRA_HTML_PAGE_NAME_PART_C:='EMPTY'}
if [ "${TEXT_FILE_DIRECTORY}" = 'EMPTY' ]  || [ "${CSS_DIRECTORY}" = 'EMPTY' ] || [ "${EXTRA_DIRECTORY}" = 'EMPTY' ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 1-6 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
if [ "${HTML_EXTRA_DIRECTORY}" = 'EMPTY' ] || [ "${IMAGES_EXTRA_DIRECTORY}" = 'EMPTY' ] || [ "${GALLERY_FILE_NAME_STYLESHEET}" = 'EMPTY' ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 1-7 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
if [ "${TEXT_FILE_NAME_CHAPTER_LIST_PART_A}" = 'EMPTY' ] || [ "${TEXT_FILE_NAME_CHAPTER_LIST_PART_C}" = 'EMPTY' ] || [ "${LANGUAGE_NAME_PART_B}" = 'EMPTY' ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 1-8 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
if [ "${TEXT_FILE_NAME_EXTRA_HTML_FILE_LIST_PART_A}" = 'EMPTY' ] || [ "${TEXT_FILE_NAME_EXTRA_HTML_FILE_LIST_PART_C}" = 'EMPTY' ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 1-9 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
if [ "${PICTURE_GALLERY_EXTRA_HTML_PAGE_NAME_PART_A}" = 'EMPTY' ] || [ "${PICTURE_GALLERY_EXTRA_HTML_PAGE_NAME_PART_C}" = 'EMPTY' ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 1-10 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi

# Verzeichnisse überprüfen
TEXT_FILE_DIRECTORY_PATH="./${TEXT_FILE_DIRECTORY}"
if [ ! -d ${TEXT_FILE_DIRECTORY_PATH} ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 2-1 \nDIRECTORY: »${TEXT_FILE_DIRECTORY_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
CSS_DIRECTORY_PATH="../${CSS_DIRECTORY}"
if [ ! -d ${CSS_DIRECTORY_PATH} ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 2-2 \nDIRECTORY: »${CSS_DIRECTORY_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
EXTRA_DIRECTORY_PATH="../${EXTRA_DIRECTORY}"
if [ ! -d ${EXTRA_DIRECTORY_PATH} ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 2-3 \nDIRECTORY: »${EXTRA_DIRECTORY_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
HTML_EXTRA_DIRECTORY_PATH="./${HTML_EXTRA_DIRECTORY}"
if [ ! -d ${HTML_EXTRA_DIRECTORY_PATH} ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 2-4 \nDIRECTORY: »${HTML_EXTRA_DIRECTORY_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
HTML_EXTRA_CURRENT_LANGUAGE_DIRECTORY_PATH="${HTML_EXTRA_DIRECTORY_PATH}/${HTML_EXTRA_DIRECTORY}_${LANGUAGE_NAME_PART_B}"
if [ ! -d ${HTML_EXTRA_CURRENT_LANGUAGE_DIRECTORY_PATH} ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 2-5 \nDIRECTORY: »${HTML_EXTRA_CURRENT_LANGUAGE_DIRECTORY_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
HTML_IMAGES_EXTRA_DIRECTORY_PATH="${HTML_EXTRA_CURRENT_LANGUAGE_DIRECTORY_PATH}/${IMAGES_EXTRA_DIRECTORY}"
if [ ! -d ${HTML_IMAGES_EXTRA_DIRECTORY_PATH} ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 2-6 \nDIRECTORY: »${HTML_IMAGES_EXTRA_DIRECTORY_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi

# aktuellen Galerietitel ermitteln
PICTURE_GALLERY_NAME_CURRENT=${PICTURE_GALLERY_NAME_CURRENT:='EMPTY'}
if [ "${PICTURE_GALLERY_NAME_CURRENT}" = 'EMPTY' ]
then
  PICTURE_GALLERY_FILE_NAME_PATH="${TEXT_FILE_DIRECTORY_PATH}/${PICTURE_GALLERY_FILE_NAME_PART_A}${PICTURE_GALLERY_FILE_NAME_PART_B}${PICTURE_GALLERY_FILE_NAME_PART_C}"
  if [ -f ${PICTURE_GALLERY_FILE_NAME_PATH} ]
  then
  PICTURE_GALLERY_NAME_CURRENT="$(head -n 1 ${PICTURE_GALLERY_FILE_NAME_PATH})"
    if [ $? -ge 1 ]
    then
    echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 3-1 \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
    exit 1
    fi
  else
  PICTURE_GALLERY_NAME_CURRENT=''
  fi
fi
PICTURE_GALLERY_NAME_CURRENT=${PICTURE_GALLERY_NAME_CURRENT:0:$GALLERY_TITLE_MAX_CHAR}
# Verzeichnisse und Dateien im Verzeichnis extra löschen
find ${EXTRA_DIRECTORY_PATH} -maxdepth 2 -type f -exec rm -f {} \; 2> /dev/null
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: GALLERY FTOOLS CREATE-HTML-FILE-INDEX 3-2 \nDIRECTORY: »${EXTRA_DIRECTORY_PATH}«  \nFILE: CAN NOT DELETE FILES \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
  exit 1
  fi
for i in $(find ${EXTRA_DIRECTORY_PATH}/* -maxdepth 2 -type d 2> /dev/null)
do
  rmdir "${i}"
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: GALLERY FTOOLS CREATE-HTML-FILE-INDEX 3-3 \nDIRECTORY: »${EXTRA_DIRECTORY_PATH}«  \nFILE: CAN NOT DELETE SUB-DIRECTORYS \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
  exit 1
  fi
done

# HTML-Datei info.htm ins Verzeichnis extra kopieren
PICTURE_GALLERY_INFORMATION_FILE_SOURCE_PATH="${HTML_EXTRA_CURRENT_LANGUAGE_DIRECTORY_PATH}/${PICTURE_GALLERY_INFORMATION_FILE_NAME}"
PICTURE_GALLERY_INFORMATION_FILE_TARGET_PATH="${EXTRA_DIRECTORY_PATH}/${PICTURE_GALLERY_INFORMATION_FILE_NAME}"
PICTURE_GALLERY_INFORMATION_FILE_HTML_PATH="./${EXTRA_DIRECTORY}/${PICTURE_GALLERY_INFORMATION_FILE_NAME}"
PICTURE_TARGET_WIDTH=${PICTURE_TARGET_WIDTH:=800}
PICTURE_TARGET_HEIGHT=${PICTURE_TARGET_HEIGHT:=600}
PICTURE_GALLERY_TEXT_FRAME_WIDTH=$[$PICTURE_TARGET_WIDTH-50]
PICTURE_GALLERY_TEXT_FRAME_HEIGHT=$[PICTURE_TARGET_HEIGHT-20]
if [ -f ${PICTURE_GALLERY_INFORMATION_FILE_SOURCE_PATH} ]
then
  cp ${PICTURE_GALLERY_INFORMATION_FILE_SOURCE_PATH} ${PICTURE_GALLERY_INFORMATION_FILE_TARGET_PATH}
    if [ $? -ge 1 ]
    then
    echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 4-1 \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
    exit 1
    fi
else
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 4-3 \nFILE: »${PICTURE_GALLERY_INFORMATION_FILE_SOURCE_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi

### BEGINN: Erstellung der HTML-Start-Datei
GALLERY_FILE_NAME_INDEX=${GALLERY_FILE_NAME_INDEX:='index.htm'}
GALLERY_HTML_PAGE_NAME_A=${GALLERY_HTML_PAGE_NAME_A:='gallery_a.htm'}
GALLERY_HTML_PAGE_NAME_B_PART_A=${GALLERY_HTML_PAGE_NAME_B_PART_A:='gallery_b_'}
GALLERY_HTML_PAGE_NAME_B_PART_C=${GALLERY_HTML_PAGE_NAME_B_PART_C:='.htm'}
# Namen der 1. HTML-Datei für das 1. Hauptbild
GALLERY_HTML_PAGE_NAME_B_PART_B_1="${GALLERY_HTML_PAGE_NAME_B_PART_A}1${GALLERY_HTML_PAGE_NAME_B_PART_C}"
GALLERY_FILE_NAME_INDEX_PATH="../${GALLERY_FILE_NAME_INDEX}"
GALLERY_FILE_NAME_STYLESHEET=${GALLERY_FILE_NAME_STYLESHEET:='EMPTY'}
GALLERY_FILE_NAME_STYLESHEET_PATH="../${CSS_DIRECTORY}/${GALLERY_FILE_NAME_STYLESHEET}"
GALLERY_FILE_NAME_STYLESHEET_HTML_PATH="./${CSS_DIRECTORY}/${GALLERY_FILE_NAME_STYLESHEET}"
GALLERY_FILE_NAME_FAVICON_PATH="../${CSS_DIRECTORY}/${GALLERY_FILE_NAME_FAVICON}"
GALLERY_FILE_NAME_FAVICON_HTML_PATH="./${CSS_DIRECTORY}/${GALLERY_FILE_NAME_FAVICON}"
PICTURE_GALLERY_NAME_TITLE_TAG=${PICTURE_GALLERY_NAME_TITLE_TAG:='Kobold'}
GALLERY_CHARSET=${GALLERY_CHARSET:='utf-8'}
GALLERY_CHARSET=$(echo ${GALLERY_CHARSET} | tr [:upper:] [:lower:])
 if [ $? -ge 1 ]
 then
 echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 5-1 \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
 exit 1
 fi
GALLERY_PICTURE_LOGO=${GALLERY_PICTURE_LOGO:='EMPTY'}
GALLERY_PICTURE_INFO=${GALLERY_PICTURE_INFO:='EMPTY'}
GALLERY_PICTURE_GOTO=${GALLERY_PICTURE_GOTO:='EMPTY'}
THUMBNAIL_TARGET_WIDTH=${THUMBNAIL_TARGET_WIDTH:=100}
PICTURE_TARGET_WIDTH=${PICTURE_TARGET_WIDTH:=800}
PICTURE_TARGET_HEIGHT=${PICTURE_TARGET_HEIGHT:=600}
PICTURE_ORIGINAL_WIDTH_MAX=${PICTURE_WIDTH_MAX:=8000}
PICTURE_ORIGINAL_HEIGHT_MAX=${PICTURE_HEIGHT_MAX:=6000}
if [ $(echo "${THUMBNAIL_TARGET_WIDTH}" | grep -c "^[1-9][0-9]\{1,2\}$") -ne 1 ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 5-2 \nFILE: CONFIGURATION-FILE IS DAMAGED \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
if [ ${PICTURE_TARGET_WIDTH} -gt ${PICTURE_ORIGINAL_WIDTH_MAX} ] || [ ${PICTURE_TARGET_HEIGHT} -gt ${PICTURE_ORIGINAL_HEIGHT_MAX} ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 5-3 \nFILE: CONFIGURATION-FILE IS DAMAGED \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
if [ $(echo "${PICTURE_TARGET_WIDTH}" | grep -c "^[1-9][0-9]\{2,3\}$") -ne 1 ] || [ $(echo "${PICTURE_TARGET_HEIGHT}" | grep -c "^[1-9][0-9]\{2,3\}$") -ne 1 ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 5-4 \nFILE: CONFIGURATION-FILE IS DAMAGED \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
if [ ! -f ${GALLERY_FILE_NAME_STYLESHEET_PATH} ]
then
echo -e "\nERROR-CODE: GALLERY CREATE-HTML-FILE-INDEX 5-5 \nFILE: »${GALLERY_FILE_NAME_STYLESHEET_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
if [ "${GALLERY_PICTURE_LOGO}" = 'EMPTY' ] || [ "${GALLERY_PICTURE_INFO}" = 'EMPTY' ] || [ "${GALLERY_PICTURE_GOTO}" = 'EMPTY' ]
then
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 5-6 \nVARIABLE: NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
if [ ! -f ${GALLERY_FILE_NAME_FAVICON_PATH} ]
then
echo -e "\nERROR-CODE: GALLERY CREATE-HTML-FILE-INDEX 5-7 \nFILE: »${GALLERY_FILE_NAME_FAVICON_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi

# Array mit den zu ersetzenden Zeichen durch den entsprechenden HTML-Code -> inc_function.txt
if [ "${PICTURE_GALLERY_NAME_CURRENT}" != '' ]
then
  GALLERY_NAME_TITLE_TAG=${PICTURE_GALLERY_NAME_CURRENT}
  START=${START:+0}
  STOP=${STOP:+$CHAR_REPLACE_ARRAY_COUNT}
  STEP=${STEP:+1}
  N=${N:+$START}
  while [ ${N} -lt $STOP ]
  do
  PICTURE_GALLERY_NAME_CURRENT=${PICTURE_GALLERY_NAME_CURRENT:+${PICTURE_GALLERY_NAME_CURRENT//${TEXT_CHAR_ARRAY[$N]}/${CHAR_REPLACE_ARRAY[$N]}}}
  N=$[$N+$STEP]
  done
else
GALLERY_NAME_TITLE_TAG=${PICTURE_GALLERY_NAME_DEFAULT}
PICTURE_GALLERY_NAME_CURRENT=${PICTURE_GALLERY_NAME_DEFAULT}
fi
# Höhe und Breite der I-Frames festlegen
BIG_FRAME_WIDTH=${PICTURE_TARGET_WIDTH}
BIG_FRAME_HEIGHT=$[${PICTURE_TARGET_HEIGHT}+20]
LITTLE_FRAME_WIDTH=$[${THUMBNAIL_TARGET_WIDTH}+40]
LITTLE_FRAME_HEIGHT=${BIG_FRAME_HEIGHT}
# Bilder überprüfen; Höhe und Breite der verwendeten Bilder ermitteln
GALLERY_PICTURE_LOGO_PATH="${CSS_DIRECTORY_PATH}/${GALLERY_PICTURE_LOGO}"
GALLERY_PICTURE_LOGO_HTML_PATH=${GALLERY_PICTURE_LOGO_PATH#\.}
if [ -f ${GALLERY_PICTURE_LOGO_PATH} ]
then
# [0] -> bei animierten Bildern wird nur das 1. Bild berücksichtigt
GALLERY_PICTURE_LOGO_WIDTH=$(identify -format %w ${GALLERY_PICTURE_LOGO_PATH}[0])
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 6-1 \nFILE: CAN NOT PRINT WIDTH OF IMAGE »${GALLERY_PICTURE_LOGO_PATH}« \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
  exit 1
  fi
GALLERY_PICTURE_LOGO_HEIGHT=$(identify -format %h ${GALLERY_PICTURE_LOGO_PATH}[0])
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 6-2 \nFILE: CAN NOT PRINT HEIGHT OF IMAGE »${GALLERY_PICTURE_LOGO_PATH}« \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
  exit 1
  fi
else
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 6-3 \nFILE: »${GALLERY_PICTURE_LOGO_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
GALLERY_PICTURE_INFO_PATH="${CSS_DIRECTORY_PATH}/${GALLERY_PICTURE_INFO}"
GALLERY_PICTURE_INFO_HTML_PATH=${GALLERY_PICTURE_INFO_PATH#\.}
if [ -f ${GALLERY_PICTURE_INFO_PATH} ]
then
GALLERY_PICTURE_INFO_WIDTH=$(identify -format %w ${GALLERY_PICTURE_INFO_PATH}[0])
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 6-4 \nFILE: CAN NOT PRINT WIDTH OF IMAGE »${GALLERY_PICTURE_INFO_PATH}« \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
  exit 1
  fi
GALLERY_PICTURE_INFO_HEIGHT=$(identify -format %h ${GALLERY_PICTURE_INFO_PATH}[0])
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 6-5 \nFILE: CAN NOT PRINT HEIGHT OF IMAGE »${GALLERY_PICTURE_INFO_PATH}« \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
  exit 1
  fi
else
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 6-6 \nFILE: »${GALLERY_PICTURE_LOGO_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi
GALLERY_PICTURE_GOTO_PATH="${CSS_DIRECTORY_PATH}/${GALLERY_PICTURE_GOTO}"
GALLERY_PICTURE_GOTO_HTML_PATH=${GALLERY_PICTURE_GOTO_PATH#\.}
if [ -f ${GALLERY_PICTURE_GOTO_PATH} ]
then
GALLERY_PICTURE_GOTO_WIDTH=$(identify -format %w ${GALLERY_PICTURE_GOTO_PATH}[0])
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 6-7 \nFILE: CAN NOT PRINT WIDTH OF IMAGE »${GALLERY_PICTURE_GOTO_PATH}« \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
  exit 1
  fi
GALLERY_PICTURE_GOTO_HEIGHT=$(identify -format %h ${GALLERY_PICTURE_GOTO_PATH}[0])
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 6-8 \nFILE: CAN NOT PRINT HEIGHT OF IMAGE »${GALLERY_PICTURE_GOTO_PATH}« \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
  exit 1
  fi
else
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 6-9 \nFILE: »${GALLERY_PICTURE_GOTO_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi

# Breite der Button angleichen
declare -a BUTTON_CHAR_COUNT_ARRAY
BUTTON_CHAR_COUNT_ARRAY[0]=${#GALLERY_INDEX_TEXT_START}
BUTTON_CHAR_COUNT_ARRAY[1]=${#GALLERY_INDEX_TEXT_PREVIOUS}
BUTTON_CHAR_COUNT_ARRAY[2]=${#GALLERY_INDEX_TEXT_NEXT}
BUTTON_CHAR_COUNT_ARRAY[3]=${#GALLERY_INDEX_TEXT_END}
BUTTON_CHAR_COUNT_ARRAY_COUNT=${#BUTTON_CHAR_COUNT_ARRAY[@]}
START=${START:+0}
STOP=${STOP:+$BUTTON_CHAR_COUNT_ARRAY_COUNT}
STEP=${STEP:+1}
N=${N:+$START}
MAX_CHAR_COUNT=${BUTTON_CHAR_COUNT_ARRAY[0]}
while [ $N -lt $STOP ]
do
  if [ ${BUTTON_CHAR_COUNT_ARRAY[$N]} -gt ${MAX_CHAR_COUNT} ]
  then
  MAX_CHAR_COUNT=${BUTTON_CHAR_COUNT_ARRAY[$N]}
  fi
N=$[$N+$STEP]
done
MIN_CHAR_COUNT_1=$[$MAX_CHAR_COUNT-6]
MIN_CHAR_COUNT_2=$[$MAX_CHAR_COUNT-4]
MIN_CHAR_COUNT_3=$[$MAX_CHAR_COUNT-2]
declare -a BUTTON_NAME_VALUE_ARRAY
BUTTON_NAME_VALUE_ARRAY[0]=${GALLERY_INDEX_TEXT_START}
BUTTON_NAME_VALUE_ARRAY[1]=${GALLERY_INDEX_TEXT_PREVIOUS}
BUTTON_NAME_VALUE_ARRAY[2]=${GALLERY_INDEX_TEXT_NEXT}
BUTTON_NAME_VALUE_ARRAY[3]=${GALLERY_INDEX_TEXT_END}
BUTTON_NAME_VALUE_ARRAY_COUNT=${#BUTTON_NAME_VALUE_ARRAY[@]}
START=${START:+0}
STOP=${STOP:+$BUTTON_NAME_VALUE_ARRAY_COUNT}
STEP=${STEP:+1}
N=${N:+$START}
while [ $N -lt $STOP ]
do
  if [ ${BUTTON_CHAR_COUNT_ARRAY[$N]} -le ${MIN_CHAR_COUNT_1} ]
  then
  BUTTON_NAME_VALUE_ARRAY[$N]="&nbsp;---&nbsp;${BUTTON_NAME_VALUE_ARRAY[$N]}&nbsp;---&nbsp;"
  elif [ ${BUTTON_CHAR_COUNT_ARRAY[$N]} -le ${MIN_CHAR_COUNT_2} ]
  then
  BUTTON_NAME_VALUE_ARRAY[$N]="&nbsp;--&nbsp;${BUTTON_NAME_VALUE_ARRAY[$N]}&nbsp;--&nbsp;"
  elif [ ${BUTTON_CHAR_COUNT_ARRAY[$N]} -le ${MIN_CHAR_COUNT_3} ]
  then  
  BUTTON_NAME_VALUE_ARRAY[$N]="--&nbsp;${BUTTON_NAME_VALUE_ARRAY[$N]}&nbsp;--"
  else
  BUTTON_NAME_VALUE_ARRAY[$N]="-&nbsp;${BUTTON_NAME_VALUE_ARRAY[$N]}&nbsp;-"
  fi
N=$[$N+$STEP]
done

# Kapitel-Links einfügen
HYPERLINK_TO_EXTRA_HTML_FILES_OR_PICTURE_CHAPTER='<td>&nbsp;</td>'
JAVASCRIPT_CHAPTER_HEAD=''
TEXT_FILE_CHAPTER_LIST_PATH="${TEXT_FILE_DIRECTORY_PATH}/${TEXT_FILE_NAME_CHAPTER_LIST_PART_A}${TEXT_FILE_NAME_CHAPTER_LIST_PART_B}${TEXT_FILE_NAME_CHAPTER_LIST_PART_C}"
EXTRA_LINK_NUMBER_1=0
if [ -f ${TEXT_FILE_CHAPTER_LIST_PATH} ]
then
  TEXT_FILE_CHAPTER_LIST_LINE_COUNT=$(cat ${TEXT_FILE_CHAPTER_LIST_PATH} | wc -l)
    if [ $? -ge 1 ]
    then
    echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 7-1 \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
    exit 1
    fi
  START=${START:+1}
  STOP=${STOP:+$CHAPTER_LINK_COUNT_MAX}
  STEP=${STEP:+1}
  N=${N:+$START}
  while [ $N -le $STOP ]
  do
    if [ ${N} -le ${TEXT_FILE_CHAPTER_LIST_LINE_COUNT} ]
    then
      CHAPTER_CURRENT_LINE=$(head -n ${N} ${TEXT_FILE_CHAPTER_LIST_PATH} | tail -n 1)
	if [ $? -ge 1 ]
	then
	echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 7-2 \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
	exit 1
	fi
      if [ $(echo "${CHAPTER_CURRENT_LINE}" | grep -c "^[1-9][0-9]\{0,3\}:.*$") -eq 1 ]
      then
	EXTRA_LINK_NUMBER_1=$[EXTRA_LINK_NUMBER_1+$STEP]
	CHAPTER_PICTURE_NUMBER_CURRENT=$(echo ${CHAPTER_CURRENT_LINE} | cut -d : -f 1)
	if [ ${CHAPTER_PICTURE_NUMBER_CURRENT} -gt ${PICTURE_NUMBERS} ]
	then
	CHAPTER_PICTURE_NUMBER_CURRENT=${CHAPTER_PICTURE_NUMBER_CURRENT:+$PICTURE_NUMBERS}
	fi
	# -f 2-9 .. falls im Linknamen ein Doppelpunkt (:) auftaucht
	CHAPTER_LINK_NAME_CURRENT=$(echo ${CHAPTER_CURRENT_LINE} | cut -d : -f 2-9)
	CHAPTER_LINK_NAME_CURRENT=${CHAPTER_LINK_NAME_CURRENT:0:$GALLERY_LINK_NAME_MAX_CHAR}
	# Array mit den zu ersetzenden Zeichen durch den entsprechenden HTML-Code -> inc_function.txt
	START_2=${START_2:+0}
	STOP_2=${STOP_2:+$CHAR_REPLACE_ARRAY_COUNT}
	STEP_2=${STEP_2:+1}
	Q=${Q:+$START_2}
	while [ ${Q} -lt $STOP_2 ]
	do
	CHAPTER_LINK_NAME_CURRENT=${CHAPTER_LINK_NAME_CURRENT:+${CHAPTER_LINK_NAME_CURRENT//${TEXT_CHAR_ARRAY[$Q]}/${CHAR_REPLACE_ARRAY[$Q]}}}
	Q=$[$Q+$STEP_2]
	done
	HYPERLINK_TO_EXTRA_HTML_FILES_OR_PICTURE_CHAPTER="${HYPERLINK_TO_EXTRA_HTML_FILES_OR_PICTURE_CHAPTER}\n              <td class=\"td_bottom\">\n                <a target=\"gallerymain\" href=\"./${GALLERY_HTML_PAGE_NAME_B_PART_A}${CHAPTER_PICTURE_NUMBER_CURRENT}.htm\" onFocus=\"if(this.blur)this.blur()\" class=\"link_index\" onClick=\"chapter(${CHAPTER_PICTURE_NUMBER_CURRENT});\">${CHAPTER_LINK_NAME_CURRENT}</a>\n              </td>\n              <td>&nbsp;</td>"
      fi
    else
    N=$[$N+$STOP]
    fi
  N=$[$N+$STEP]
  done
  if [ ${EXTRA_LINK_NUMBER_1} -ge 1 ]
  then
JAVASCRIPT_CHAPTER_HEAD='
function chapter(a) {
  i = a;
  if(i > j) {i = j;}
  if(i < 1) {i = 1;}
}
'
  fi
fi

# Extra-HTML-Seiten einbinden
TEXT_FILE_HTML_FILE_LIST_PATH="${TEXT_FILE_DIRECTORY_PATH}/${TEXT_FILE_NAME_EXTRA_HTML_FILE_LIST_PART_A}${TEXT_FILE_NAME_EXTRA_HTML_FILE_LIST_PART_B}${TEXT_FILE_NAME_EXTRA_HTML_FILE_LIST_PART_C}"
PICTURE_TARGET_WIDTH=${PICTURE_TARGET_WIDTH:=800}
PICTURE_TARGET_HEIGHT=${PICTURE_TARGET_HEIGHT:=600}
HTML_EXTRA_FILE_TEXT_FRAME_WIDTH=$[$PICTURE_TARGET_WIDTH-50]
HTML_EXTRA_FILE_TEXT_FRAME_HEIGHT=$[PICTURE_TARGET_HEIGHT-20]
if [ -f ${TEXT_FILE_HTML_FILE_LIST_PATH} ]
then
  TEXT_FILE_HTML_FILE_LIST_LINE_COUNT=$(cat ${TEXT_FILE_HTML_FILE_LIST_PATH} | wc -l)
    if [ $? -ge 1 ]
    then
    echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 8-1 \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
    exit 1
    fi
  START=${START:+1}
  STOP=${STOP:+$HTML_PAGES_LINK_COUNT_MAX}
  STEP=${STEP:+1}
  N=${N:+$START}
  Q=${Q:+1}
  while [ $N -le $STOP ]
  do
    if [ ${N} -le ${TEXT_FILE_HTML_FILE_LIST_LINE_COUNT} ]
    then
      TEXT_FILE_HTML_FILE_LIST_CURRENT_LINE=$(head -n ${N} ${TEXT_FILE_HTML_FILE_LIST_PATH} | tail -n 1)
	if [ $? -ge 1 ]
	then
	echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 8-2 \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
	exit 1
	fi
      if [ $(echo "${TEXT_FILE_HTML_FILE_LIST_CURRENT_LINE}" | grep -c "^.\{1,25\}\.\(htm\|html\):.*$") -eq 1 ]
      then
	HTML_EXTRA_FILE_NAME_CURRENT=$(echo ${TEXT_FILE_HTML_FILE_LIST_CURRENT_LINE} | cut -d : -f 1)
	if [ $(echo ${HTML_EXTRA_FILE_NAME_CURRENT} | grep -c "^.*[[:blank:]].*$") -ge 1 ]
	then
	echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 8-3 \nFILE: »${HTML_EXTRA_CURRENT_LANGUAGE_DIRECTORY_PATH}/${HTML_EXTRA_FILE_NAME_CURRENT}« BLANK IN FILENAME NOT SUPPORTED !! \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
	exit 1
	fi
	# -f 2-9 .. falls im Linknamen ein Doppelpunkt (:) auftaucht
	HTML_EXTRA_FILE_LINK_NAME_CURRENT=$(echo ${TEXT_FILE_HTML_FILE_LIST_CURRENT_LINE} | cut -d : -f 2-9)
	HTML_EXTRA_FILE_LINK_NAME_CURRENT=${HTML_EXTRA_FILE_LINK_NAME_CURRENT:0:$GALLERY_LINK_NAME_MAX_CHAR}
	# Array mit den zu ersetzenden Zeichen durch den entsprechenden HTML-Code -> inc_function.txt
	START_2=${START_2:+0}
	STOP_2=${STOP_2:+$CHAR_REPLACE_ARRAY_COUNT}
	STEP_2=${STEP_2:+1}
	P=${P:+$START_2}
	while [ ${P} -lt $STOP_2 ]
	do
	HTML_EXTRA_FILE_LINK_NAME_CURRENT=${HTML_EXTRA_FILE_LINK_NAME_CURRENT:+${HTML_EXTRA_FILE_LINK_NAME_CURRENT//${TEXT_CHAR_ARRAY[$P]}/${CHAR_REPLACE_ARRAY[$P]}}}
	P=$[$P+$STEP_2]
	done
	PICTURE_GALLERY_EXTRA_HTML_PAGE_NAME_PART_B=${Q}
	CURRENT_HTML_EXTRA_FILE_TARGET=${PICTURE_GALLERY_EXTRA_HTML_PAGE_NAME_PART_A}${PICTURE_GALLERY_EXTRA_HTML_PAGE_NAME_PART_B}${PICTURE_GALLERY_EXTRA_HTML_PAGE_NAME_PART_C}
	CURRENT_HTML_EXTRA_FILE_SOURCE_PATH="${HTML_EXTRA_CURRENT_LANGUAGE_DIRECTORY_PATH}/${HTML_EXTRA_FILE_NAME_CURRENT}"
	CURRENT_HTML_EXTRA_FILE_TARGET_PATH="${EXTRA_DIRECTORY_PATH}/${CURRENT_HTML_EXTRA_FILE_TARGET}"
	CURRENT_HTML_EXTRA_FILE_HTML_PATH="./${EXTRA_DIRECTORY}/${CURRENT_HTML_EXTRA_FILE_TARGET}"
	if [ -f ${CURRENT_HTML_EXTRA_FILE_SOURCE_PATH} ]
	then
	  cp ${CURRENT_HTML_EXTRA_FILE_SOURCE_PATH} ${CURRENT_HTML_EXTRA_FILE_TARGET_PATH}
	    if [ $? -ge 1 ]
	    then
	    echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 8-4 \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
	    exit 1
	    fi
	  # Hyperlinks für die Extra-HTML-Seiten einfügen
	  HYPERLINK_TO_EXTRA_HTML_FILES_OR_PICTURE_CHAPTER="${HYPERLINK_TO_EXTRA_HTML_FILES_OR_PICTURE_CHAPTER}\n        <td class=\"td_bottom\">\n          <a target=\"gallerymain\" href=\"${CURRENT_HTML_EXTRA_FILE_HTML_PATH}\" onFocus=\"if(this.blur)this.blur()\" class=\"link_index\">${HTML_EXTRA_FILE_LINK_NAME_CURRENT}</a>\n        </td>\n        <td>&nbsp;</td>"
	else
	echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 8-6 \nFILE: »${CURRENT_HTML_EXTRA_FILE_SOURCE_PATH}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
	echo -e "TIP 1: CALL SHELLSCRIPT »bash gallery-tools.sh« -> POINT 6"
	echo -e "TIP 2: TO EDIT OR DELETE FILE »${TEXT_FILE_HTML_FILE_LIST_PATH}«\n"
	exit 1
	fi
	Q=$[$Q+$STEP]
      fi
    else
    N=$[$N+$STOP]
    fi
    N=$[$N+$STEP]
  done
fi

# Verzeichnis für die Bilder der Extra-HTML-Seiten erstellen
DIRECTORY_HTML_EXTRA_FILE_IMAGES="${HTML_EXTRA_CURRENT_LANGUAGE_DIRECTORY_PATH}/${IMAGES_EXTRA_DIRECTORY}"
DIRECTORY_GALLERY_EXTRA_FILE_IMAGES="${EXTRA_DIRECTORY_PATH}/${IMAGES_EXTRA_DIRECTORY}"
if [ ! -d ${DIRECTORY_GALLERY_EXTRA_FILE_IMAGES} ]
then
mkdir ${DIRECTORY_GALLERY_EXTRA_FILE_IMAGES}
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 9-1 \nDIRECTORY: CAN NOT CREATE DIRECTORY »./${DIRECTORY_GALLERY_EXTRA_FILE_IMAGES}« \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
  exit 1
  fi
fi
if [ -d ${DIRECTORY_HTML_EXTRA_FILE_IMAGES} ]
then
  for i in $(find ${DIRECTORY_HTML_EXTRA_FILE_IMAGES} -maxdepth 1 -type f -iregex "^.*\(\.jpg\|\.jpeg\|\.png\|\.gif\)$")
  do
    if [ $(echo ${i} | grep -c "^.*[[:blank:]].*$") -ge 1 ]
    then
    echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 9-2 \nFILE: »${DIRECTORY_HTML_EXTRA_FILE_IMAGES}/${EXTRA_FILE_IMAGE_NAME}« BLANK IN FILE-NAME NOT SUPPORTED !! \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
    exit 1
    fi
    EXTRA_FILE_IMAGE_NAME=${i##*/}
    for k in $(find ${EXTRA_DIRECTORY_PATH} -maxdepth 1 -type f -iregex "^.*\(\.htm\|\.html\)$")
    do
      # Bilder die in den Extra-HTML-Seiten verwendet werden, in das Galerie-Verzeichnis extra/images kopieren
      if [ $(grep -c "^.*<img .*${EXTRA_FILE_IMAGE_NAME}.*$" ${k}) -ge 1 ]
      then	
	CURRENT_HTML_EXTRA_FILE_IMAGES_SOURCE_PATH="${DIRECTORY_HTML_EXTRA_FILE_IMAGES}/${EXTRA_FILE_IMAGE_NAME}"
	CURRENT_EXTRA_FILE_IMAGES_TARGET_PATH="${DIRECTORY_GALLERY_EXTRA_FILE_IMAGES}/${EXTRA_FILE_IMAGE_NAME}"
	cp ${CURRENT_HTML_EXTRA_FILE_IMAGES_SOURCE_PATH} ${CURRENT_EXTRA_FILE_IMAGES_TARGET_PATH}
	  if [ $? -ge 1 ]
	  then
	  echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 9-3 \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
	  exit 1
	  fi
      fi
    done
  done
else
echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 9-4 \nDIRECTORY: »${DIRECTORY_HTML_EXTRA_FILE_IMAGES}« NOT FOUND \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
exit 1
fi

# BEGINN: Erstellung der HTML-Start-2-Datei
echo -e "<!DOCTYPE html>
<html>
<head>
<title>${GALLERY_NAME_TITLE_TAG} - ${LANGUAGE_SHORT_CODE} - ${PICTURE_GALLERY_NAME_TITLE_TAG}</title>
<meta charset=\"${GALLERY_CHARSET}\">
<script type=\"text/javascript\">
<!-- hide
var i=1;
var j=${PICTURE_NUMBERS};
var k;
var timer;
var stopp=0;

function firstimg() {
  i = 1;
  eval(\"parent.gallerymain.location.href=\\\"./${GALLERY_HTML_PAGE_NAME_B_PART_A}\" + i + \".htm\\\"\");
}

function previmg() {
  i--;
  if(i < 1) {
    i = 1;
  }
  eval(\"parent.gallerymain.location.href=\\\"./${GALLERY_HTML_PAGE_NAME_B_PART_A}\" + i + \".htm\\\"\");
}

function nextimg() {
  i++;
  if(i > j) {
    i = j;
  }
  eval(\"parent.gallerymain.location.href=\\\"./${GALLERY_HTML_PAGE_NAME_B_PART_A}\" + i + \".htm\\\"\");
}

function lastimg() {
  i = j;
  eval(\"parent.gallerymain.location.href=\\\"./${GALLERY_HTML_PAGE_NAME_B_PART_A}\" + i + \".htm\\\"\");
}
${JAVASCRIPT_CHAPTER_HEAD}
function slidevalue(a) {
  window.document.slideprojector.slide_value.value=a;
}

function startshow() {
  if(stopp == 0){
  i++;
    if(i <= j) {
    var img_zyklus_a=parseInt(window.document.slideprojector.slide_value.value);
    var img_zyklus_b = img_zyklus_a * 1000;
    eval(\"parent.gallerymain.location.href=\\\"./${GALLERY_HTML_PAGE_NAME_B_PART_A}\" + i + \".htm\\\"\");
      if(i < j) {
      timer=setTimeout(\"startshow()\",img_zyklus_b);
      }
    }
    else
    {
    i = j;
    }
  }
  else
  {
  stopp=0;
  }
}

function stopshow() {
  stopp=1;
  clearTimeout(timer);
  setTimeout(\"startshow()\",10);
}

function goto_img() {
  k=window.document.goto_image.goto_value.value;
  if(isNaN(k) == false) {
    i=parseInt(k)
    if(i > j) {i = j;}
    if(i < 1) {i = 1;}
    eval(\"parent.gallerymain.location.href=\\\"./${GALLERY_HTML_PAGE_NAME_B_PART_A}\" + i + \".htm\\\"\");
    window.document.goto_image.goto_value.value=i;
  }
  else
  {
  window.document.goto_image.goto_value.value=123;
  }
}

function stoperror() {
return true
}
window.onerror=stoperror;
//-->
</script>
<link rel=\"stylesheet\" type=\"text/css\" href=\"${GALLERY_FILE_NAME_STYLESHEET_HTML_PATH}\">
<link rel=\"icon\" href=\"${GALLERY_FILE_NAME_FAVICON_HTML_PATH}\">
</head>
<body id=\"body_index\">
<div id=\"div_center\">
  <table id=\"table_index\">
    <tr>
      <td>&nbsp;</td>
      <th colspan=\"2\" class=\"gallery_title\">${PICTURE_GALLERY_NAME_CURRENT}</th>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>
        <div id=\"div_right\">
          <table>
            <tr>
              ${HYPERLINK_TO_EXTRA_HTML_FILES_OR_PICTURE_CHAPTER}
              <td>&nbsp;</td>
              <td>&nbsp;</td>
              <td>
                <a target=\"gallerymain\" href=\"${PICTURE_GALLERY_INFORMATION_FILE_HTML_PATH}\" onFocus=\"if(this.blur)this.blur()\"><img src=\"${GALLERY_PICTURE_INFO_HTML_PATH}\" width=\"${GALLERY_PICTURE_INFO_WIDTH}\" height=\"${GALLERY_PICTURE_INFO_HEIGHT}\" title=\"${GALLERY_INDEX_TEXT_INFO_ALT}\" alt=\"${GALLERY_INDEX_TEXT_INFO_ALT}\"></a>
              </td>
              <td class=\"td_bottom\">
                <a target=\"gallerymain\" href=\"${PICTURE_GALLERY_INFORMATION_FILE_HTML_PATH}\" onFocus=\"if(this.blur)this.blur()\" class=\"link_index\">${GALLERY_INDEX_TEXT_INFO}</a>
              </td>
              <td>&nbsp;</td>
            </tr>
          </table>
        </div>
      </td>
    </tr>
    <tr>
      <td class=\"td_top\"><br><br><img src=\"${GALLERY_PICTURE_LOGO_HTML_PATH}\" width=\"${GALLERY_PICTURE_LOGO_WIDTH}\" height=\"${GALLERY_PICTURE_LOGO_HEIGHT}\">&nbsp;</td>
      <td><iframe name=\"gallerythumb\" scrolling=\"auto\" id=\"thumbnail\" src=\"./${GALLERY_HTML_PAGE_NAME_A}\" width=\"${LITTLE_FRAME_WIDTH}\" height=\"${LITTLE_FRAME_HEIGHT}\">INFO: I-FRAMES UNSUPPORTED</iframe></td>
      <td><iframe name=\"gallerymain\" scrolling=\"no\" id=\"main_img\" src=\"./${GALLERY_HTML_PAGE_NAME_B_PART_B_1}\" width=\"${BIG_FRAME_WIDTH}\" height=\"${BIG_FRAME_HEIGHT}\">INFO: I-FRAMES UNSUPPORTED</iframe></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>
        <form name=\"goto_image\">
          <table>
            <tr>
              <td>&nbsp;&nbsp;&nbsp;</td>
              <td><img src=\"${GALLERY_PICTURE_GOTO_HTML_PATH}\" width=\"${GALLERY_PICTURE_GOTO_WIDTH}\" height=\"${GALLERY_PICTURE_GOTO_HEIGHT}\" onClick=\"goto_img();\"></td>
              <td><input id=\"field_text\" type=\"text\" size=\"3\" maxlength=\"5\" name=\"goto_value\" value=\"123\"></td>
            </tr>
          </table>
        </form>
      </td>
      <td>
        <div id="div_center">
          <form name=\"gallery\">
            <table>
              <tr>
                <td><input class=\"button_index\" type=\"button\" name=\"first\" value=\"${BUTTON_NAME_VALUE_ARRAY[0]}\" onClick=\"firstimg();\"></td>
                <td><input class=\"button_index\" type=\"button\" name=\"previous\" value=\"${BUTTON_NAME_VALUE_ARRAY[1]}\" onClick=\"previmg();\"></td>
                <td><input class=\"button_index\" type=\"button\" name=\"next\" value=\"${BUTTON_NAME_VALUE_ARRAY[2]}\" onClick=\"nextimg();\"></td>
                <td><input class=\"button_index\" type=\"button\" name=\"last\" value=\"${BUTTON_NAME_VALUE_ARRAY[3]}\" onClick=\"lastimg();\"></td>
              </tr>
            </table>
          </form>
        </div>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>
        <div id=\"div_center\">
          <form name=\"slideprojector\">
            <table>
              <tr>
                <th colspan=\"11\" id=\"title_slideshow\">${GALLERY_INDEX_TEXT_SLIDESHOW}</th>
              </tr>
              <tr>
                <td rowspan=\"2\">&nbsp;<input type=\"hidden\" name=\"slide_value\" value=\"20\"></td>
                <td><input type=\"radio\" name=\"slide\" value=\"5\" onClick=\"slidevalue(5);\"></td>
                <td class=\"text_second\">5 ${GALLERY_INDEX_TEXT_SECOND}</td>
                <td><input type=\"radio\" name=\"slide\" value=\"10\" onClick=\"slidevalue(10);\"></td>
                <td class=\"text_second\">10 ${GALLERY_INDEX_TEXT_SECOND}</td>
                <td><input type=\"radio\" name=\"slide\" value=\"20\" checked onClick=\"slidevalue(20);\"></td>
                <td class=\"text_second\">20 ${GALLERY_INDEX_TEXT_SECOND}</td>
                <td><input type=\"radio\" name=\"slide\" value=\"30\" onClick=\"slidevalue(30);\"></td>
                <td class=\"text_second\">30 ${GALLERY_INDEX_TEXT_SECOND}</td>
                <td><input type=\"radio\" name=\"slide\" value=\"60\" onClick=\"slidevalue(60);\"></td>
                <td class=\"text_second\">60 ${GALLERY_INDEX_TEXT_SECOND}</td>
              </tr>
              <tr>
                <td colspan=\"5\" class=\"td_center;\"><input class=\"button_index\" type=\"button\" name=\"slideprojector_stop\" value=\"${GALLERY_INDEX_TEXT_SLIDSHOW_START}\" onClick=\"setTimeout('startshow()',5000);\"></td>
                <td colspan=\"5\" class=\"td_center;\"><input class=\"button_index\" type=\"button\" name=\"slideprojector_start\" value=\"${GALLERY_INDEX_TEXT_SLIDSHOW_STOP}\" onClick=\"stopshow();\"></td>
              </tr>
            </table>
          </form>
        </div>
      </td>
    </tr>
  </table>
</div>
</body>
</html>
" > ${GALLERY_FILE_NAME_INDEX_PATH}
  if [ $? -ge 1 ]
  then
  echo -e "\nERROR-CODE: CREATE-GALLERY AND TOOLS CREATE-HTML-FILE-INDEX 10 \nFILE: CAN NOT WRITE FILE »${GALLERY_FILE_NAME_INDEX_PATH}« \nSCRIPT-NAME: ${INC_NAME_INDEX_GALLERY}\n"
  exit 1
  fi

# Textkodierung prüfen und evtl. ändern
change_text_coding ${GALLERY_FILE_NAME_INDEX_PATH} ${GALLERY_CHARSET}
### ENDE: Erstellung der HTML-Start-2-Datei
