function Joom_GalleryDefault($start)
{
    $config = Joom_getConfig();
    $database =& JFactory::getDBO();
    $user =& JFactory::getUser();
    $query1 = " SELECT \n                *\n              FROM \n                #__joomgallery_catg\n              WHERE \n                 published = '1' \n                AND parent = 0\n            ";
    if ($config->jg_showrmsmcats == 0) {
        $query1 .= "  AND access<= '" . $user->get('aid') . "'";
    }
    if ($config->jg_ordercatbyalpha) {
        $query1 .= " ORDER BY \n                  name \n                LIMIT {$start}," . $config->jg_catperpage . "\n             ";
    } else {
        $query1 .= " ORDER BY \n                  ordering \n                LIMIT {$start}," . $config->jg_catperpage . "\n            ";
    }
    $database->setQuery($query1);
    $rows = $database->loadObjectList();
    if (!$rows == NULL) {
        $num_rows = ceil(count($rows) / $config->jg_colcat);
        $count_pics = count($rows);
        $index = 0;
        if ($config->jg_showallcathead) {
            ?>
  <div class="sectiontableheader">
    <?php 
            echo JText::_('JGS_CATEGORIES');
            ?>
&nbsp;
  </div>
<?php 
        }
        for ($row_count = 0; $row_count < $num_rows; $row_count++) {
            $linecolor = $row_count % 2 + 1;
            //Ausrichtung der Thumbs nur wirksam, wenn Random-Anzeige aktiviert
            if ($config->jg_showcatthumb == 1) {
                if ($config->jg_ctalign == 0) {
                    $ctalign = $row_count % 2 + 1;
                    if ($ctalign == 1) {
                        $ctalign = 'left';
                    } else {
                        $ctalign = 'right';
                    }
                }
                if ($config->jg_ctalign == 1) {
                    $ctalign = 'left';
                } elseif ($config->jg_ctalign == 2) {
                    $ctalign = 'right';
                } elseif ($config->jg_ctalign == 3) {
                    $ctalign = 'center';
                }
            } else {
                $ctalign = 'left';
            }
            ?>
  <div class="jg_row <?php 
            if ($linecolor == 1) {
                echo "sectiontableentry1";
            } else {
                echo "sectiontableentry2";
            }
            ?>
">
<?php 
            for ($col_count = 0; $col_count < $config->jg_colcat && $index < $count_pics; $col_count++) {
                if ($config->jg_ctalign == 0 && $linecolor == 1 || $config->jg_ctalign > 0) {
                    ?>
    <div class="jg_element_gal">
<?php 
                } else {
                    ?>
    <div class="jg_element_gal_r">
<?php 
                }
                $row1 = $rows[$index];
                if ($config->jg_showcatasnew) {
                    $isnew = Joom_CheckNewCatg($row1->cid);
                } else {
                    $isnew = '';
                }
                $pictures = Joom_GetNumberOfLinks($row1->cid);
                $numberofpictures = number_format($pictures, 0, ',', '.');
                if ($pictures == 1) {
                    $picorpics = JText::_('JGS_PICTURE');
                } else {
                    $picorpics = JText::_('JGS_PICTURES');
                }
                if ($row1->img_position == 0 || $row1->img_position == NULL) {
                    $img_position = 'left';
                } elseif ($row1->img_position == 1) {
                    $img_position = 'right';
                } elseif ($row1->img_position == 2) {
                    $img_position = 'middle';
                }
                if ($config->jg_showcatthumb == 1) {
                    $allsubcats = Joom_GetAllSubCategories($row1->cid, $config->jg_showrandomcatthumb);
                    if ($allsubcats) {
                        $randomcat = $allsubcats[mt_rand(0, count($allsubcats) - 1)];
                    } else {
                        //keine Kategorie mit Bildern gefunden
                        $randomcat = '0';
                    }
                }
                if ($config->jg_showtotalcathits) {
                    if ($config->jg_showrandomcatthumb > 2 && $config->jg_showcatthumb == 1) {
                        //wenn Zufallsbild aus Cat oder Cat und Subcats und Anzeige des
                        //Cat Bildes, die schon vorher festgestellten Cats uebernehmen
                        $totalsubcats = $allsubcats;
                    } else {
                        $totalsubcats = Joom_GetAllSubCategories($row1->cid, 4);
                    }
                    $totalhits = Joom_GetTotalHits($totalsubcats);
                }
                if ($config->jg_showcatthumb > 0) {
                    if ($user->get('aid') >= $row1->access) {
                        if ($config->jg_showcatthumb == 1) {
                            //random pic, nur wenn $randomcat(s) vorhanden
                            if ($config->jg_showrandomcatthumb == 1 || $config->jg_showrandomcatthumb >= 2 && $randomcat != '0') {
                                $catid = $row1->cid;
                                $query = "  SELECT \n                              *,\n                              c.access \n                            FROM \n                              #__joomgallery AS p\n                            LEFT JOIN \n                              #__joomgallery_catg AS c ON c.cid = p.catid\n                          ";
                                if ($config->jg_showrandomcatthumb == 1) {
                                    $query .= "  WHERE \n                                p.catid = {$catid}\n                           ";
                                } elseif ($config->jg_showrandomcatthumb >= 2) {
                                    $query .= "  WHERE \n                                p.catid = {$randomcat}\n                           ";
                                }
                                $query .= "      AND p.published = '1' \n                                AND p.approved='1' \n                                AND c.access <= " . $user->get('aid') . " \n                                AND c.published = '1'\n                              ORDER BY \n                                rand() \n                              LIMIT 1\n                         ";
                                $database->setQuery($query);
                                $rows1 = $database->LoadObjectList();
                                $count = count($rows1);
                                if (isset($rows1[0])) {
                                    $row = $rows1[0];
                                }
                            } else {
                                $count = 0;
                            }
                            if ($count > 0) {
                                if ($config->jg_ctalign == 0 && $linecolor == 1 || $config->jg_ctalign > 0) {
                                    ?>
      <div class="jg_photo_container">
<?php 
                                } else {
                                    ?>
      <div class="jg_photo_container_r">
<?php 
                                }
                                ?>
        <a href="<?php 
                                echo JRoute::_('index.php?option=com_joomgallery&func=viewcategory&catid=' . $row1->cid . _JOOM_ITEMID);
                                ?>
">
          <img src="<?php 
                                echo _JOOM_LIVE_SITE . $config->jg_paththumbs . $row->catpath . '/' . $row->imgthumbname;
                                ?>
" align="<?php 
                                if ($ctalign == 'center') {
                                    echo 'middle';
                                } else {
                                    echo $ctalign;
                                }
                                ?>
" class="jg_photo" alt="<?php 
                                echo $row->imgtitle;
                                ?>
" />
        </a>
      </div>
<?php 
                            }
                        } elseif ($config->jg_showcatthumb == 2 && $row1->catimage != '') {
                            ?>
      <div class="jg_photo_container">
        <a href="<?php 
                            echo JRoute::_('index.php?option=com_joomgallery&func=viewcategory&catid=' . $row1->cid . _JOOM_ITEMID);
                            ?>
">
          <img src="<?php 
                            echo _JOOM_LIVE_SITE . $config->jg_paththumbs . $row1->catpath . '/' . $row1->catimage;
                            ?>
" align="<?php 
                            echo $img_position;
                            ?>
" class="jg_photo" alt="<?php 
                            echo $row1->name;
                            ?>
" />
        </a>
      </div>
<?php 
                        }
                    }
                    if ($config->jg_showcatthumb == 2) {
                        $ctalign = $img_position;
                        if ($ctalign == 'middle') {
                            $ctalign = 'center';
                        }
                    }
                    if ($config->jg_ctalign == 0 && $linecolor == 1 || $config->jg_ctalign > 0) {
                        ?>
      <div class="jg_element_txt">
<?php 
                    } else {
                        ?>
      <div class="jg_element_txt_r">
<?php 
                    }
                    ?>
        <ul>
          <li>
<?php 
                    if ($user->get('aid') >= $row1->access) {
                        ?>
            <a href="<?php 
                        echo JRoute::_('index.php?option=com_joomgallery&func=viewcategory&catid=' . $row1->cid . _JOOM_ITEMID);
                        ?>
">
              <b><?php 
                        echo $row1->name;
                        ?>
</b>
            </a>
<?php 
                    } else {
                        ?>
            <span class="jg_no_access" onMouseOver="return overlib('<?php 
                        echo JText::_('JGS_ALERT_YOU_NOT_ACCESS_THIS_DIRECTORY', true);
                        ?>
', CAPTION, '<?php 
                        echo addslashes($row1->name);
                        ?>
', BELOW, RIGHT);" onmouseout="return nd();">
              <b><?php 
                        echo $row1->name;
                        ?>
</b>
            </span>
<?php 
                    }
                } else {
                    if ($config->jg_ctalign == 0 && $linecolor == 1 || $config->jg_ctalign == 1 || $config->jg_ctalign == 3) {
                        // set $ctalign for using later in Joom_ShowCategoryTree()
                        if ($config->jg_ctalign == 3) {
                            $ctalign = 'center';
                        } else {
                            $ctalign = 'left';
                        }
                        ?>
      <div class="jg_element_txt">
<?php 
                    } else {
                        // set $ctalign for using in Joom_ShowCategoryTree
                        $ctalign = 'right';
                        ?>
      <div class="jg_element_txt_r">
<?php 
                    }
                    ?>
        <ul>
          <li>
<?php 
                    if ($user->get('aid') >= $row1->access) {
                        ?>
            <a href="<?php 
                        echo JRoute::_('index.php?option=com_joomgallery&func=viewcategory&catid=' . $row1->cid . _JOOM_ITEMID);
                        ?>
">
              <b><?php 
                        echo $row1->name;
                        ?>
</b>
            </a>
<?php 
                    } else {
                        ?>
            <span class="jg_no_access" onMouseOver="return overlib('<?php 
                        echo JText::_('JGS_ALERT_YOU_NOT_ACCESS_THIS_DIRECTORY', true);
                        ?>
', CAPTION, '<?php 
                        echo addslashes($row1->name);
                        ?>
', BELOW, RIGHT);" onmouseout="return nd();">
              <b><?php 
                        echo $row1->name;
                        ?>
</b>
            </span>
<?php 
                    }
                }
                if ($config->jg_rmsm > 0) {
                    if ($row1->access > 1) {
                        ?>
            <span class="jg_sm">
              <?php 
                        echo JText::_('JGS_SPECIAL_MEMBERS');
                        ?>
&nbsp;
            </span>
<?php 
                    } elseif ($row1->access > 0) {
                        if ($user->get('aid') >= $row1->access && !$config->jg_showrmsmcats || $config->jg_showrmsmcats) {
                            ?>
            <span class="jg_rm">
              <?php 
                            echo JText::_('JGS_REGISTERED_MEMBERS');
                            ?>
&nbsp;
            </span>
<?php 
                        }
                    }
                }
                ?>
          </li>
<?php 
                if ($user->get('aid') >= $row1->access) {
                    ?>
          <li>
            (<?php 
                    echo $numberofpictures;
                    ?>
 <?php 
                    echo $picorpics;
                    ?>
)<?php 
                    echo $isnew;
                    ?>
&nbsp;
          </li>
<?php 
                }
                if ($config->jg_showtotalcathits) {
                    ?>
          <li>
            <?php 
                    echo JText::_('JGS_HITS');
                    ?>
: <?php 
                    echo $totalhits;
                    ?>
&nbsp;
          </li>
<?php 
                }
                if ($row1->description) {
                    ?>
          <li>
            <?php 
                    echo $row1->description;
                    ?>
&nbsp;
          </li>
<?php 
                }
                ?>
        </ul>
      </div>
<?php 
                // use treeview to display subcategories
                if ($config->jg_showsubsingalleryview) {
                    Joom_ShowCategoryTree($row1->cid, $ctalign);
                }
                ?>
    </div>
<?php 
                $index++;
            }
            ?>
    <div class="jg_clearboth"></div>
  </div>
<?php 
        }
        if ($config->jg_showallcathead) {
            ?>
  <div class="sectiontableheader">
    &nbsp;
  </div>
<?php 
        }
    }
}
    function Joom_ShowSubCategories_HTML(&$rows)
    {
        $config = Joom_getConfig();
        $mainframe =& JFactory::getApplication('site');
        $database =& JFactory::getDBO();
        $user =& JFactory::getUser();
        $pic_count = count($rows);
        $num_rows = ceil($pic_count / $config->jg_colsubcat);
        $index = 0;
        ?>
  <div class="jg_subcat">
<?php 
        if ($config->jg_showsubcathead) {
            ?>
    <div class="sectiontableheader">
      <?php 
            echo JText::_('JGS_SUBCATEGORIES');
            ?>
&nbsp;
    </div>
<?php 
        }
        ?>
  </div>
<?php 
        //Ausrichtung entsprechend der globalen Vorgabe
        switch ($config->jg_subcatthumbalign) {
            case 1:
                $img_position = 'left';
                break;
            case 2:
                $img_position = 'right';
                break;
            case 3:
                $img_position = 'middle';
                break;
        }
        for ($row_count = 0; $row_count < $num_rows; $row_count++) {
            $linecolor = ($row_count + 1) % 2 + 1;
            ?>
  <div class="jg_row <?php 
            if ($linecolor == 1) {
                echo "sectiontableentry1";
            } else {
                echo "sectiontableentry2";
            }
            ?>
">
<?php 
            for ($col_count = 0; $col_count < $config->jg_colsubcat && $index < $pic_count; $col_count++) {
                $cur_name = $rows[$index];
                if ($config->jg_showcatasnew) {
                    $isnew = Joom_CheckNewCatg($cur_name->cid);
                } else {
                    $isnew = '';
                }
                $catpath = $cur_name->catpath . '/';
                ?>
    <div class="jg_subcatelem_cat">
<?php 
                if ($cur_name != NULL) {
                    if ($config->jg_showsubthumbs != 0) {
                        ?>
      <div class="jg_subcatelem_photo">
<?php 
                    }
                    if ($config->jg_showsubthumbs == 1) {
                        if ($user->get('aid') >= $cur_name->access && $cur_name->catimage != '') {
                            ?>
          <a href="<?php 
                            echo JRoute::_($this->viewcategory_url . $cur_name->cid . _JOOM_ITEMID);
                            ?>
">
            <img src="<?php 
                            echo _JOOM_LIVE_SITE . $config->jg_paththumbs . $catpath . $cur_name->catimage;
                            ?>
"  align="<?php 
                            echo $img_position;
                            ?>
" hspace="4" vspace="0" class="jg_photo" alt="<?php 
                            echo $cur_name->name;
                            ?>
" />
          </a>
<?php 
                        }
                        ?>
      </div>
      <div class="jg_subcatelem_txt">
        <img src="<?php 
                        echo $this->assetsimages_url . 'arrow.png';
                        ?>
" class="pngfile jg_icon" alt="arrow" />
<?php 
                        if ($user->get('aid') >= $cur_name->access) {
                            ?>
        <a href="<?php 
                            echo JRoute::_($this->viewcategory_url . $cur_name->cid . _JOOM_ITEMID);
                            ?>
">
          <?php 
                            echo $cur_name->name;
                            ?>
</a>
<?php 
                        } else {
                            ?>
        <span class="jg_no_access" onMouseOver="return overlib('<?php 
                            echo JText::_('JGS_ALERT_YOU_NOT_ACCESS_THIS_DIRECTORY', true);
                            ?>
', CAPTION, '<?php 
                            echo addslashes($cur_name->name);
                            ?>
', BELOW, RIGHT);" onmouseout="return nd();">
          <?php 
                            echo $cur_name->name;
                            ?>
&nbsp;
        </span>
<?php 
                        }
                        ?>
              (<?php 
                        echo Joom_GetNumberOfLinks($cur_name->cid);
                        ?>
)<?php 
                        echo $isnew;
                        ?>
&nbsp;
<?php 
                    }
                    if ($config->jg_showsubthumbs == 0) {
                        ?>
        <div class="jg_subcatelem_txt">
          <ul>
            <li>
              <img src="<?php 
                        echo $this->assetsimages_url . 'arrow.png';
                        ?>
" class="pngfile jg_icon" alt="arrow" />
<?php 
                        if ($user->get('aid') >= $cur_name->access) {
                            ?>
              <a href="<?php 
                            echo JRoute::_($this->viewcategory_url . $cur_name->cid . _JOOM_ITEMID);
                            ?>
">
                <?php 
                            echo $cur_name->name;
                            ?>
</a>
<?php 
                        } else {
                            ?>
              <span class="jg_no_access" onMouseOver="return overlib('<?php 
                            echo JText::_('JGS_ALERT_YOU_NOT_ACCESS_THIS_DIRECTORY', true);
                            ?>
', CAPTION, '<?php 
                            echo addslashes($cur_name->name);
                            ?>
', BELOW, RIGHT);" onmouseout="return nd();">
                <?php 
                            echo $cur_name->name;
                            ?>
&nbsp;
              </span>
<?php 
                        }
                        ?>
              (<?php 
                        echo Joom_GetNumberOfLinks($cur_name->cid);
                        ?>
) <?php 
                        echo $isnew;
                        ?>
&nbsp;
            </li>
<?php 
                    }
                    if ($config->jg_showsubthumbs == 2) {
                        $allsubcats = Joom_GetAllSubCategories($cur_name->cid, $config->jg_showrandomsubthumb);
                        if ($allsubcats) {
                            mt_srand();
                            $randomsubcat = $allsubcats[mt_rand(0, count($allsubcats) - 1)];
                        } else {
                            $randomsubcat = '0';
                        }
                    }
                    if ($config->jg_showtotalsubcathits) {
                        if ($config->jg_showrandomsubthumb > 2 && $config->jg_showsubthumbs == 2) {
                            $totalsubcats = $allsubcats;
                        } else {
                            $totalsubcats = Joom_GetAllSubCategories($cur_name->cid, 4);
                        }
                        $totalhits = Joom_GetTotalHits($totalsubcats);
                    }
                    if ($config->jg_showsubthumbs == 2) {
                        //random pic nur, wenn auch $randomsubcat(s) vorhanden
                        if ($config->jg_showrandomsubthumb == 1 || $config->jg_showrandomsubthumb >= 2 && $randomsubcat != '0') {
                            $subcatid = $cur_name->cid;
                            $query = "  SELECT \n                            *,\n                            c.access \n                          FROM \n                            #__joomgallery AS p\n                          LEFT JOIN \n                            #__joomgallery_catg AS c ON c.cid = p.catid\n                          WHERE \n                      ";
                            if ($config->jg_showrandomsubthumb == 1) {
                                $query .= "  p.catid = {$cur_name->cid}";
                            } elseif ($config->jg_showrandomsubthumb >= 2) {
                                $query .= "  p.catid = {$randomsubcat}";
                                $catpath = Joom_getCatPath($randomsubcat);
                            }
                            $query .= "  AND p.published = '1' \n                          AND p.approved  = '1' \n                          AND c.access   <= " . $user->get('aid') . " \n                          AND c.published = '1'\n                        ORDER BY \n                          rand() \n                        LIMIT 1\n                      ";
                            $database->setQuery($query);
                            $rows2 = $database->loadObjectList();
                            $count = count($rows2);
                        } else {
                            $count = 0;
                        }
                        if ($count > 0) {
                            $row3 = $rows2[0];
                            if ($row3->imgfilename != '') {
                                ?>
          <a href="<?php 
                                echo JRoute::_($this->viewcategory_url . $cur_name->cid . _JOOM_ITEMID);
                                ?>
">
            <img src="<?php 
                                echo _JOOM_LIVE_SITE . $config->jg_paththumbs . $catpath . $row3->imgfilename;
                                /*// vorher $row3->catpath.'/' anstatt $catpath */
                                ?>
" align="<?php 
                                echo $img_position;
                                ?>
" hspace="4" vspace="0" class="jg_photo" alt="<?php 
                                echo $cur_name->name . " :: " . $row3->imgtitle;
                                ?>
" />
          </a>
<?php 
                            }
                        }
                        ?>
      </div>
      <div class="jg_subcatelem_txt">
        <ul>
          <li>
            <img src="<?php 
                        echo $this->assetsimages_url . 'arrow.png';
                        ?>
" class="pngfile jg_icon" alt="arrow" />
<?php 
                        if ($user->get('aid') >= $cur_name->access) {
                            ?>
            <a href="<?php 
                            echo JRoute::_($this->viewcategory_url . $cur_name->cid . _JOOM_ITEMID);
                            ?>
">
              <?php 
                            echo $cur_name->name;
                            ?>
</a>
<?php 
                        } else {
                            ?>
            <span class="jg_no_access" onMouseOver="return overlib('<?php 
                            echo JText::_('JGS_ALERT_YOU_NOT_ACCESS_THIS_DIRECTORY', true);
                            ?>
', CAPTION, '<?php 
                            echo addslashes($cur_name->name);
                            ?>
', BELOW, RIGHT);" onmouseout="return nd();">
              <?php 
                            echo $cur_name->name;
                            ?>
&nbsp;
            </span>
<?php 
                        }
                        ?>
            (<?php 
                        echo Joom_GetNumberOfLinks($cur_name->cid);
                        ?>
) <?php 
                        echo $isnew;
                        ?>
&nbsp;
          </li>
<?php 
                    }
                    if ($config->jg_rmsm > 0) {
                        if ($cur_name->access > 1) {
                            ?>
          <li>
            <span class="jg_sm">
              <?php 
                            echo JText::_('JGS_SPECIAL_MEMBERS');
                            ?>
&nbsp;
            </span>
          </li>
<?php 
                        } elseif ($cur_name->access > 0) {
                            ?>
          <li>
            <span class="jg_rm">
              <?php 
                            echo JText::_('JGS_REGISTERED_MEMBERS');
                            ?>
&nbsp;
            </span>
          </li>
<?php 
                        }
                    }
                }
                if ($user->get('aid') >= $cur_name->access) {
                    if ($config->jg_showtotalsubcathits) {
                        ?>
          <li>
            <?php 
                        echo JText::_('JGS_HITS');
                        ?>
: <?php 
                        echo $totalhits;
                        ?>
&nbsp;
          </li>
<?php 
                    }
                    if ($cur_name->description) {
                        ?>
          <li>
            <?php 
                        echo $cur_name->description;
                        ?>
&nbsp;
          </li>
<?php 
                    }
                }
                $mainframe->triggerEvent('onAfterDisplayJoomCatThumb', array($cur_name->cid));
                ?>
        </ul>
      </div>
    </div>
<?php 
                $index++;
            }
            // for loop over cols in row
            ?>
    <div class="jg_clearboth"></div>
  </div>
<?php 
        }
        // for loop over rows
    }