/**
  * Will traverse input array with configuratoin per-item and create corresponding GIF files for the menu.
  * The data of the files are stored in $this->result
  *
  * @param	array		Array with configuration for each item.
  * @param	string		Type of images: normal ("NO") or rollover ("RO"). Valid values are "NO" and "RO"
  * @return	void
  * @access private
  * @see generate()
  */
 function makeGifs($conf, $resKey)
 {
     $isGD = $GLOBALS['TYPO3_CONF_VARS']['GFX']['gdlib'];
     if (!is_array($conf)) {
         $conf = array();
     }
     $totalWH = array();
     $items = count($conf);
     if ($isGD) {
         // generate the gif-files. the $menuArr is filled with some values like output_w, output_h, output_file
         $Hcounter = 0;
         $Wcounter = 0;
         $Hobjs = $this->mconf['applyTotalH'];
         if ($Hobjs) {
             $Hobjs = t3lib_div::intExplode(',', $Hobjs);
         }
         $Wobjs = $this->mconf['applyTotalW'];
         if ($Wobjs) {
             $Wobjs = t3lib_div::intExplode(',', $Wobjs);
         }
         $minDim = $this->mconf['min'];
         if ($minDim) {
             $minDim = tslib_cObj::calcIntExplode(',', $minDim . ',');
         }
         $maxDim = $this->mconf['max'];
         if ($maxDim) {
             $maxDim = tslib_cObj::calcIntExplode(',', $maxDim . ',');
         }
         if ($minDim) {
             $conf[$items] = $conf[$items - 1];
             $this->menuArr[$items] = array();
             $items = count($conf);
         }
         // TOTAL width
         if ($this->mconf['useLargestItemX'] || $this->mconf['useLargestItemY'] || $this->mconf['distributeX'] || $this->mconf['distributeY']) {
             $totalWH = $this->findLargestDims($conf, $items, $Hobjs, $Wobjs, $minDim, $maxDim);
         }
     }
     $c = 0;
     $maxFlag = 0;
     $distributeAccu = array('H' => 0, 'W' => 0);
     foreach ($conf as $key => $val) {
         $GLOBALS['TSFE']->register['count_HMENU_MENUOBJ']++;
         $GLOBALS['TSFE']->register['count_MENUOBJ']++;
         if ($items == $c + 1 && $minDim) {
             $Lobjs = $this->mconf['removeObjectsOfDummy'];
             if ($Lobjs) {
                 $Lobjs = t3lib_div::intExplode(',', $Lobjs);
                 foreach ($Lobjs as $remItem) {
                     unset($val[$remItem]);
                     unset($val[$remItem . '.']);
                 }
             }
             $flag = 0;
             $tempXY = explode(',', $val['XY']);
             if ($Wcounter < $minDim[0]) {
                 $tempXY[0] = $minDim[0] - $Wcounter;
                 $flag = 1;
             }
             if ($Hcounter < $minDim[1]) {
                 $tempXY[1] = $minDim[1] - $Hcounter;
                 $flag = 1;
             }
             $val['XY'] = implode(',', $tempXY);
             if (!$flag) {
                 break;
             }
         }
         $c++;
         if ($isGD) {
             // Pre-working the item
             $gifCreator = t3lib_div::makeInstance('tslib_gifBuilder');
             $gifCreator->init();
             $gifCreator->start($val, $this->menuArr[$key]);
             // If useLargestItemH/W is specified
             if (count($totalWH) && ($this->mconf['useLargestItemX'] || $this->mconf['useLargestItemY'])) {
                 $tempXY = explode(',', $gifCreator->setup['XY']);
                 if ($this->mconf['useLargestItemX']) {
                     $tempXY[0] = max($totalWH['W']);
                 }
                 if ($this->mconf['useLargestItemY']) {
                     $tempXY[1] = max($totalWH['H']);
                 }
                 // regenerate the new values...
                 $val['XY'] = implode(',', $tempXY);
                 $gifCreator = t3lib_div::makeInstance('tslib_gifBuilder');
                 $gifCreator->init();
                 $gifCreator->start($val, $this->menuArr[$key]);
             }
             // If distributeH/W is specified
             if (count($totalWH) && ($this->mconf['distributeX'] || $this->mconf['distributeY'])) {
                 $tempXY = explode(',', $gifCreator->setup['XY']);
                 if ($this->mconf['distributeX']) {
                     $diff = $this->mconf['distributeX'] - $totalWH['W_total'] - $distributeAccu['W'];
                     $compensate = round($diff / ($items - $c + 1));
                     $distributeAccu['W'] += $compensate;
                     $tempXY[0] = $totalWH['W'][$key] + $compensate;
                 }
                 if ($this->mconf['distributeY']) {
                     $diff = $this->mconf['distributeY'] - $totalWH['H_total'] - $distributeAccu['H'];
                     $compensate = round($diff / ($items - $c + 1));
                     $distributeAccu['H'] += $compensate;
                     $tempXY[1] = $totalWH['H'][$key] + $compensate;
                 }
                 // regenerate the new values...
                 $val['XY'] = implode(',', $tempXY);
                 $gifCreator = t3lib_div::makeInstance('tslib_gifBuilder');
                 $gifCreator->init();
                 $gifCreator->start($val, $this->menuArr[$key]);
             }
             // If max dimensions are specified
             if ($maxDim) {
                 $tempXY = explode(',', $val['XY']);
                 if ($maxDim[0] && $Wcounter + $gifCreator->XY[0] >= $maxDim[0]) {
                     $tempXY[0] == $maxDim[0] - $Wcounter;
                     $maxFlag = 1;
                 }
                 if ($maxDim[1] && $Hcounter + $gifCreator->XY[1] >= $maxDim[1]) {
                     $tempXY[1] = $maxDim[1] - $Hcounter;
                     $maxFlag = 1;
                 }
                 if ($maxFlag) {
                     $val['XY'] = implode(',', $tempXY);
                     $gifCreator = t3lib_div::makeInstance('tslib_gifBuilder');
                     $gifCreator->init();
                     $gifCreator->start($val, $this->menuArr[$key]);
                 }
             }
             // displace
             if ($Hobjs) {
                 foreach ($Hobjs as $index) {
                     if ($gifCreator->setup[$index] && $gifCreator->setup[$index . '.']) {
                         $oldOffset = explode(',', $gifCreator->setup[$index . '.']['offset']);
                         $gifCreator->setup[$index . '.']['offset'] = implode(',', $gifCreator->applyOffset($oldOffset, array(0, -$Hcounter)));
                     }
                 }
             }
             if ($Wobjs) {
                 foreach ($Wobjs as $index) {
                     if ($gifCreator->setup[$index] && $gifCreator->setup[$index . '.']) {
                         $oldOffset = explode(',', $gifCreator->setup[$index . '.']['offset']);
                         $gifCreator->setup[$index . '.']['offset'] = implode(',', $gifCreator->applyOffset($oldOffset, array(-$Wcounter, 0)));
                     }
                 }
             }
         }
         // Finding alternative GIF names if any (by altImgResource)
         $gifFileName = '';
         if ($conf[$key]['altImgResource'] || is_array($conf[$key]['altImgResource.'])) {
             if (!is_object($cObj)) {
                 $cObj = t3lib_div::makeInstance('tslib_cObj');
             }
             $cObj->start($this->menuArr[$key], 'pages');
             $altImgInfo = $cObj->getImgResource($conf[$key]['altImgResource'], $conf[$key]['altImgResource.']);
             $gifFileName = $altImgInfo[3];
         }
         // If an alternative name was NOT given, find the GIFBUILDER name.
         if (!$gifFileName && $isGD) {
             $gifCreator->createTempSubDir('menu/');
             $gifFileName = $gifCreator->fileName('menu/');
         }
         $this->result[$resKey][$key] = $conf[$key];
         // Generation of image file:
         if (file_exists($gifFileName)) {
             // File exists
             $info = @getimagesize($gifFileName);
             $this->result[$resKey][$key]['output_w'] = intval($info[0]);
             $this->result[$resKey][$key]['output_h'] = intval($info[1]);
             $this->result[$resKey][$key]['output_file'] = $gifFileName;
         } elseif ($isGD) {
             // file is generated
             $gifCreator->make();
             $this->result[$resKey][$key]['output_w'] = $gifCreator->w;
             $this->result[$resKey][$key]['output_h'] = $gifCreator->h;
             $this->result[$resKey][$key]['output_file'] = $gifFileName;
             $gifCreator->output($this->result[$resKey][$key]['output_file']);
             $gifCreator->destroy();
         }
         $this->result[$resKey][$key]['output_file'] = t3lib_div::png_to_gif_by_imagemagick($this->result[$resKey][$key]['output_file']);
         $Hcounter += $this->result[$resKey][$key]['output_h'];
         // counter is increased
         $Wcounter += $this->result[$resKey][$key]['output_w'];
         // counter is increased
         if ($maxFlag) {
             break;
         }
     }
 }