<?php 

// Check to ensure this file is included in Freeway!
defined('_FEXEC') or die();
?>
    <table border="0" width="100%" cellspacing="0" cellpadding="<?php echo CELLPADDING_SUB; ?>">
<?php
// BOF: Lango Added for template MOD
   if (SHOW_HEADING_TITLE_ORIGINAL == 'yes') {
$header_text = '&nbsp;'
//EOF: Lango Added for template MOD
?>
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr>
                        <td class="pageHeading">
             <?php 
               if ( (ALLOW_EVENTS_CATEGORY_DESCRIPTIONS == 'true') && (tep_not_null($events_category['events_categories_heading_title'])) ) {
                 echo $category['events_categories_heading_title'];
               } else {
                 echo HEADING_EVENTS_TITLE;
               }
             ?>
            </td>
            <td class="pageHeading" align="right"><?php echo tep_image(DIR_WS_IMAGES . $events_category['events_categories_image'], $events_category['events_categories_name'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?></td>
          </tr>
	  <?php if ( (ALLOW_EVENTS_CATEGORY_DESCRIPTIONS == 'true') && (tep_not_null($events_category['events_categories_description'])) ) { ?>
	  <tr>
            <td align="left" colspan="2" class="category_desc"><?php echo $events_category['events_categories_description']; ?></td>
	  </tr>
	  <?php } ?>
        </table></td>
      </tr>
<?php
// BOF: Lango Added for template MOD
}else{
$header_text = HEADING_EVENTS_TITLE;
}
// EOF: Lango Added for template MOD
	if(!isset($hide_row_top)) {
?>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
      </tr>
<?php } ?>	  
      <tr>
        <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td><table border="0" width="100%" cellspacing="0" cellpadding="2">
              <tr>
<?php
   if (isset($ecPath) && strpos('_', $ecPath)) {
// check to see if there are deeper events categories within the current events category
      $events_category_links = array_reverse($ecPath_array);
      for($i=0, $n=sizeof($events_category_links); $i<$n; $i++) {
        $events_categories_query = tep_db_query("select count(*) as total from " . TABLE_EVENTS_CATEGORIES . " ec, " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ecd where ec.parent_id = '" . (int)$events_category_links[$i] . "' and ec.events_categories_id = ecd.events_categories_id and ecd.language_id = '" . (int)$languages_id . "'");
        $events_categories = tep_db_fetch_array($events_categories_query);
        if ($events_categories['total'] < 1) {
          // do nothing, go through the loop
        } else {
          $events_categories_query = tep_db_query("select ec.events_categories_id, ecd.events_categories_name, ec.events_categories_image, ec.parent_id from " . TABLE_EVENTS_CATEGORIES . " ec, " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ecd where ec.parent_id = '" . (int)$events_category_links[$i] . "' and ec.events_categories_id = ecd.events_categories_id and ecd.language_id = '" . (int)$languages_id . "' order by sort_order, ecd.events_categories_name");
          break; // we've found the deepest category the customer is in
        }
      }
    } else {
      $events_categories_query = tep_db_query("select ec.events_categories_id, ecd.events_categories_name, ec.events_categories_image, ec.parent_id from " . TABLE_EVENTS_CATEGORIES . " ec, " . TABLE_EVENTS_CATEGORIES_DESCRIPTION . " ecd where ec.parent_id = '" . (int)$current_events_category_id . "' and ec.events_categories_id = ecd.events_categories_id and ecd.language_id = '" . (int)$languages_id . "' order by sort_order, ecd.events_categories_name");
    }

    $number_of_events_categories = tep_db_num_rows($events_categories_query);

    $rows = 0;
    while ($events_categories = tep_db_fetch_array($events_categories_query)) {
      $rows++;
      $ecPath_new = tep_get_events_path($events_categories['events_categories_id']);
      $width = (int)(100 / MAX_DISPLAY_CATEGORIES_PER_ROW) . '%';
      echo '                <td align="center" class="smallText" width="' . $width . '" valign="top"><a href="' . tep_href_link(FILENAME_DEFAULT, $ecPath_new) . '">' . tep_image(DIR_WS_IMAGES . $events_categories['events_categories_image'], $events_categories['events_categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br>' . $events_categories['events_categories_name'] . '</a></td>' . "\n";
      if ((($rows / MAX_DISPLAY_CATEGORIES_PER_ROW) == floor($rows / MAX_DISPLAY_CATEGORIES_PER_ROW)) && ($rows != $number_of_events_categories)) {
        echo '              </tr>' . "\n";
        echo '              <tr>' . "\n";
      }
    }

// needed for the new events module shown below
    $new_events_events_category_id = $current_events_category_id;
?>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td><?php echo tep_draw_separator('pixel_trans.gif', '100%', '10'); ?></td>
          </tr>
          <tr>
            <td><?php include(DIR_WS_MODULES . FILENAME_NEW_EVENTS); ?></td>
          </tr>
        </table></td>
      </tr>
    </table>
