/**
  * gets the DB rows for all images and calls the HTML output function
  *
  */
 function Joom_ShowMinis()
 {
     $user =& JFactory::getUser();
     $mainframe =& JFactory::getApplication('site');
     // selected category
     $this->catid = $mainframe->getUserStateFromRequest('joom.button.catid', 'catid', 0, 'int');
     // pagination
     $limitstart = JRequest::getInt('limitstart', 0);
     $limit = $mainframe->getUserStateFromRequest('joom.button.limit', 'limit', 50, 'int');
     // ensure that image can be seen later on
     $where = "WHERE \n                   jgc.published = '1'\n                AND jgc.access  <= " . $user->get('aid') . "\n                AND jg.published = '1'\n                AND jg.approved  = '1'";
     if ($this->catid) {
         $where .= "\n                AND jg.catid = '" . $this->catid . "'";
         $this->catpath = Joom_getCatPath($this->catid);
     }
     // query
     $query = "  SELECT \n                  jg.id, \n                  jg.catid, \n                  jg.imgtitle, \n                  jg.imgthumbname, \n                  jgc.name \n                FROM \n                  #__joomgallery AS jg\n                LEFT JOIN \n                  #__joomgallery_catg AS jgc ON jgc.cid = jg.catid\n              " . $where;
     // execute the query if list_limit = 0 -> all pictures
     if ($limit == 0) {
         $this->_db->setQuery($query);
         $rows = $this->_db->loadObjectList();
         $total = count($rows);
     } else {
         // take the query and replace the 'select *' with 'select count(jg.id)' -> $querycount
         // to count total rows for navigation
         $countquery = str_replace('SELECT jg.id, jg.catid, jg.imgtitle, jg.imgthumbname, jgc.name', 'SELECT COUNT(id)', $query);
         $this->_db->setQuery($countquery);
         $total = $this->_db->loadResult();
         if ($total <= $limit) {
             $limitstart = 0;
         }
         $this->_db->setQuery($query, $limitstart, $limit);
         $rows = $this->_db->loadObjectList();
     }
     jimport('joomla.html.pagination');
     $this->_pagination = new JPagination($total, $limitstart, $limit);
     Joom_ShowMiniJoom_HTML::Joom_ShowMinis_HTML($rows);
 }
    /**
     * HTML output of the mini thumbnails for the JoomBu
     *
     *@param array DB result
     */
    function Joom_ShowMinis_HTML($rows)
    {
        $mainframe =& JFactory::getApplication('site');
        $document =& JFactory::getDocument();
        $config = Joom_getConfig();
        // template CSS is usually not loaded now, but it's better to have it
        $load_template_css = true;
        // make available in the plugin params?
        if ($load_template_css) {
            $template = $mainframe->getTemplate();
            $template_file = false;
            if (is_file(JPATH_THEMES . DS . $template . DS . 'css' . DS . 'template.css')) {
                $template_file = 'templates/' . $template . '/css/template.css';
            } else {
                if (is_file(JPATH_THEMES . DS . $template . DS . 'css' . DS . 'template_css.css')) {
                    $template_file = 'templates/' . $template . '/css/template_css.css';
                }
            }
            if ($load_template_css) {
                $document->addStyleSheet(_JOOM_LIVE_SITE . $template_file);
                // to avoid scroll bar with some templates
                $document->addStyleDeclaration("    body{\n      height:90%;\n    }");
            }
        }
        // for overlib effect # at the moment always loaded by joom.javascript.php
        #$document->addScript(_JOOM_LIVE_SITE.'includes/js/overlib_mini.js');
        // for accordion
        $document->addStyleSheet('components/com_joomgallery/assets/css/joom_detail.css');
        JHTML::_('behavior.mootools');
        #$document->addScript('components/com_joomgallery/assets/js/accordion/js/accordion.js');
        $script = "\n    window.addEvent('domready', function(){ \n      new Accordion(\$\$('h4.joomgallery-toggler'), \$\$('div.joomgallery-slider'), \n        {onActive: function(toggler, i) { \n          toggler.addClass('joomgallery-toggler-down'); \n          toggler.removeClass('joomgallery-toggler'); },\n         onBackground: function(toggler, i) { \n          toggler.addClass('joomgallery-toggler'); \n          toggler.removeClass('joomgallery-toggler-down'); },\n          duration: 300,display:-1,show:1,opacity: false,alwaysHide: true}); });";
        $document->addScriptDeclaration($script);
        // JavaScript for inserting the tag
        $script = "\n    function insertJoomPluWithId(jg_id) {\n      jg_detail = document.getElementById('jg_bu_detail').checked;\n      jg_linked = document.getElementById('jg_bu_linked').checked;\n      jg_align  = document.getElementById('jg_bu_align').value;\n      if(jg_detail) {\n        jg_detail = ' detail';\n      } else {\n        jg_detail = '';\n      }\n      if(jg_linked) {\n        jg_linked = '';\n      } else {\n        jg_linked = ' not linked';\n      }\n      if(jg_align) {\n        jg_align  = ' ' + jg_align;\n      } else {\n        jg_align  = '';\n      }\n      jg_plu_tag  = '{joomplu:' + jg_id + jg_detail + jg_linked + jg_align + '}';\n      window.parent.jInsertEditorText(jg_plu_tag, 'text');\n      window.parent.document.getElementById('sbox-window').close();\n    }";
        $document->addScriptDeclaration($script);
        ?>
<div class="gallery minigallery">
  <div class="jg_header">
    <?php 
        echo JText::_('JGS_BU_INTRO');
        ?>
  </div>
  <div class="sectiontableheader">
    <h4 class="joomgallery-toggler">
      <?php 
        echo JText::_('JGS_BU_EXTENDED');
        ?>
&nbsp;
    </h4>
  </div>
  <div class="joomgallery-slider">
    <div class="jg_bu_extended_options">
      <span class="jg_bu_extended_option_left">
        <?php 
        echo JText::_('JGS_BU_DETAIL');
        ?>
&nbsp;
        <input type="checkbox" id="jg_bu_detail">
      </span>
      <span class="jg_bu_extended_option_middle">
        <?php 
        echo JText::_('JGS_BU_LINKED');
        ?>
&nbsp;
        <input type="checkbox" id="jg_bu_linked" checked="checked">
      </span>
      <span class="jg_bu_extended_option_right">
        <?php 
        echo JText::_('JGS_BU_ALIGN');
        ?>
        <select id="jg_bu_align">
          <option value="">
          </option>
          <option value="right">
            <?php 
        echo JText::_('JGS_BU_ALIGN_RIGHT');
        ?>
&nbsp;
          </option>
          <option value="left">
            <?php 
        echo JText::_('JGS_BU_ALIGN_LEFT');
        ?>
&nbsp;
          </option>
        </select>
      </span>
    </div>
  </div>
  <div class="sectiontableheader">
    <h4 class="joomgallery-toggler">
      <?php 
        echo JText::_('JGS_BU_SEARCH');
        ?>
    </h4>
  </div>
  <div class="joomgallery-slider">
    <div class="jg_bu_search">
    <form action="index.php?option=com_joomgallery&func=joomplu&tmpl=component&e_name=text" method="post">
<?php 
        echo $this->_pagination->getListFooter();
        ?>
      <div class="jg_bu_filter">
        <?php 
        echo Jtext::_('JGS_FILTER_BY_CATEGORY');
        ?>
&nbsp;
<?php 
        echo Joom_ShowDropDownCategoryList($this->catid, 'catid', 'onchange="this.form.submit();"');
        ?>
      </div>
    </form>
    </div>
  </div>
  <div class="jg_bu_minis">
<?php 
        foreach ($rows as $row) {
            if (!$this->catid) {
                $catpath = Joom_GetCatPath($row->catid);
                $cat_name = true;
            } else {
                $catpath = $this->catpath;
                $cat_name = false;
            }
            ?>
    <div class="jg_bu_mini">
<?php 
            if ($row->imgthumbname != '' && is_file(JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $row->imgthumbname))) {
                $tnfile = JPath::clean(JPATH_ROOT . DS . $config->jg_paththumbs . $catpath . $row->imgthumbname);
                $tnfile = str_replace(' ', '%20', $tnfile);
                $imginfo = getimagesize($tnfile);
                $srcLink = _JOOM_LIVE_SITE . $config->jg_paththumbs . $catpath . $row->imgthumbname;
                $srcWidth = $imginfo[0];
                $srcHeight = $imginfo[1];
                $overlib = Joom_ShowMiniJoom_HTML::getOverlibHtml($row, $srcLink, $cat_name);
                ?>
      <a href="javascript:insertJoomPluWithId('<?php 
                echo $row->id;
                ?>
');" onmouseover="return overlib('<?php 
                echo $overlib;
                ?>
',WIDTH,<?php 
                echo $srcWidth;
                ?>
,<?php 
                /* HEIGHT,<?php echo $srcHeight; ?>,*/
                ?>
ABOVE)" onmouseout="return nd()" >
        <img src="<?php 
                echo _JOOM_LIVE_SITE . $config->jg_paththumbs . $catpath . $row->imgthumbname;
                ?>
" border="0" height="40" width="40" alt="Thumbnail" /></a>
<?php 
            } else {
                ?>
      <div class="jg_bu_no_mini" onmouseover="return overlib('<?php 
                echo sprintf(JText::_('JGS_NO_THUMB_TOOLTIP_TEXT', true), $row->id, $row->imgtitle);
                ?>
', CAPTION, '<?php 
                echo JText::_('JGS_NO_THUMB');
                ?>
', BELOW, RIGHT)" onmouseout="return nd()" >
        <?php 
                echo JText::_('JGS_NO_THUMB');
                ?>
&nbsp;
      </div>
<?php 
            }
            ?>
    </div>
<?php 
        }
        if (!count($rows)) {
            ?>
    <div class="jg_bu_no_images">
      <?php 
            echo JText::_('JGS_NO_IMAGES');
            ?>
&nbsp;
    </div>
<?php 
        }
        ?>
  </div>
</div>
<?php 
    }