<?php get_header(); ?>

<?php // Include the default slider if activated ?>
<?php include (TEMPLATEPATH . '/slider.php'); ?>

<?php // Include the login box ?>
<?php include (TEMPLATEPATH . '/loginform.php'); ?>

<?php // content start ?>
<div id="content" class="content<?php echo get_option('fungames_sidebar_position'); ?>">

  <?php // Include custom slider if activated ?>
  <?php include (TEMPLATEPATH . '/slider_custom.php'); ?>
  
  <?php
  // Get index banner
  $catcount = 0;
  $banner = stripslashes(get_option('fungames_adindex'));
  ?>
  
  <?php // Generate Game Boxes ?>
  
  <?php         
  // Get categories, hide empty, exclude defined
  $exclude = fungames_get_excluded_categories();
  $categories = get_categories($exclude);
  
  // Get box count. If emty then set to 6 (default)
  $fungames_box_count = get_option('fungames_box_count');
  if ( empty($fungames_box_count) ) { $fungames_box_count = 6; }
  
  // Calculate the height of a game box
  $height = fungames_calculate_height($fungames_box_count);  
  
  // Get the post order
  $order = '';
  if ( get_option('fungames_order_games') == 'Random') { $order = '&orderby=rand'; }
   
  // Generate the query string.
  $get_post_query = 'numberposts='.intval($fungames_box_count).$order.'&category=';

  // Generate Game Boxes... Loop through all categories
  foreach ($categories as $category) {
    // Get the current category ID
    $cat_id = $category->cat_ID;
    
    // Get games from this category
    $games = get_posts($get_post_query.$cat_id);
    
    // Check if we have some games in this category
    if ( $games ) { 
      // There are some games.. Create the game box
      get_template_part('index', get_option('fungames_box_design') );
    } 
  } // END category loop
  ?>
 
  <?php // show game list if plugin exists ?>
  <?php if (function_exists('get_game_list')) { get_game_list(); } ?>
  
  <?php // Display front page text if exists ?>
  <?php $frontpage_text = stripslashes( get_option('fungames_frontpage_text') ); ?>  
  <?php if ( $frontpage_text ): ?>
  <div class="clear"></div>
  <div class="contentbox customtext">
    <?php echo $frontpage_text; ?>
  </div>
  <?php endif; ?>
  
  <?php fungames_action_after_index_content(); ?>
  
</div><?php // end content ?>

<?php get_sidebar(); ?>
<?php get_footer(); ?>