<?php if (theme_get_setting('scrolltop_display')): ?>
<div id="toTop"><span class="glyphicon glyphicon-chevron-up"></span></div>
<?php endif; ?>

<?php if ($page['highlighted']) :?>
    <?php print render($page['highlighted']); ?>
<?php endif; ?>

<?php include ($directory . '/includes/header.inc.php'); ?>

<!-- #header-top -->
<div id="header-top" class="clearfix">
    
    <!-- #header-top-inside -->
    <div id="header-top-inside" class="clearfix">
        
        <div id="home-page-banner" class="carousel slide" data-ride="carousel">
        
            <?php print ($page['banner_home_left'])? render($page['banner_home_left']) : null; ?>
            
            <?php
            $banners = array();
            $query = db_select('node', 'n');
            $query->fields('n', array('nid', 'title', 'created'))
                ->condition('type', 'home_page_banner');
            $result = $query->execute();
            while($row = $result->fetchAssoc()):
                $node = node_load($row['nid']);
                $fImage = field_get_items('node', $node, 'field_banner_image');
                $fImageURI = str_ireplace('public://', '', $fImage[0]['uri']);
                $banners[] = array('nid' => $row['nid'], 'title' => $node->title, 'image' => $fImageURI);
            endwhile;
            $count = count($banners);
            ?>
        
            <!-- Indicators -->
            <ol class="carousel-indicators">
                <?php 
                for($i = 0; $i < $count; $i++): 
                    $class = ($i == 0)? 'active' : null;
                    echo '<li data-target="#home-page-banner" data-slide-to="'. $i .'" class="'. $class .'"></li>';
                endfor;
                ?>
            </ol>
        
            <!-- Wrapper for slides -->
            <div class="carousel-inner" role="listbox">
                <?php 
                $i = 0;
                foreach($banners as $banner): 
                    $class = ($i == 0)? 'active' : null;
                    echo '
                    <div class="item '. $class .'">
                        <a href="javascript:void(null);" style="background-image: url(\''. base_path() . 'sites/default/files/'. $banner['image'] .'\')">&nbsp;</a>
                    </div>
                    ';
                    $i++;
                endforeach;
                ?>
            </div>
        
            <script> jQuery(document).ready(function($) {  $('.carousel').carousel(); }); </script>
                
            <?php print ($page['banner_home_right'])? render($page['banner_home_right']) : null; ?>
            
        </div>
        <!-- EOF:#header-top-right -->
        
        <!-- #header-footer -->
        <div id="header-footer" class="clearfix">
            <?php print ($page['header_footer'])? render($page['header_footer']) : null; ?>
            <div class="hidden-md hidden-lg">
              <?php print ($page['header_top_left'])? render($page['header_top_left']) : null; ?>
              <?php print ($page['header_top_right'])? render($page['header_top_right']) : null; ?>
            </div>
        </div>
        <!-- EOF:#header-top-left-footer -->
        
    </div>
    <!-- EOF: #header-top-inside -->

</div>
<!-- EOF: #header-top -->

<?php /*/ ?>
<!-- #top-content -->
<div id="top-content" class="clearfix">

    <!-- #top-content-inside -->
    <ul id="top-content-inside" class="clearfix" style="overflow: hidden;">
        <?php 
        $helpIcons = db_query(
            'SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = :node_type AND n.status = :node_status', 
            array(':node_type' => 'help_icon_circle', ':node_status' => 1)
        );
        foreach($helpIcons as $helpIcon): 
            $node = node_load($helpIcon->nid);
            $fImage = field_get_items('node', $node, 'field_help_image_circle');
            $fImageURI = str_ireplace('public://', '', $fImage[0]['uri']);
            $body = field_get_items('node', $node, 'body');
            echo '
            <li class="help_icon_circle" style="background-image: url(\''. base_path() . 'sites/default/files/'. $fImageURI .'\')">
                <span class="title">'. $node->title .'</span>
            </li>
            ';
        endforeach;
        ?>
    </ul>
    <!-- EOF:#top-content-inside -->

</div>
<!-- EOF: #top-content -->
<?php //*/ ?>

<!-- #page -->
<div id="page" class="clearfix front-page">
    
    <!-- #main-content -->
    <div id="main-content">
        <div class="container">
        
            <!-- #messages-console -->
            <?php if ($messages):?>
            <div id="messages-console" class="clearfix">
                <div class="row">
                    <div class="col-md-12">
                    <?php print $messages; ?>
                    </div>
                </div>
            </div>
            <?php endif; ?>
            <!-- EOF: #messages-console -->
            
            <section class="<?php print $main_grid_class; ?>">

                <!-- #main -->
                <div id="main" class="clearfix">
                
                    <!-- EOF:#content-wrapper -->
                    <div id="content-wrapper">
                        <?php print render($page['content']); ?>
                    </div>
                    <!-- EOF:#content-wrapper -->

                </div>
                <!-- EOF:#main -->

            </section>

        </div>
    </div>
    <!-- EOF:#main-content -->

    <?php if ($page['bottom_content']):?>
    <!-- #bottom-content -->
    <div id="bottom-content" class="clearfix">
        <div class="container">

            <!-- #bottom-content-inside -->
            <div id="bottom-content-inside" class="clearfix">
                <div class="row">
                    <div class="col-md-12">
                    <?php print render($page['bottom_content']); ?>
                    </div>
                </div>
            </div>
            <!-- EOF:#bottom-content-inside -->

        </div>
    </div>
    <!-- EOF: #bottom-content -->
    <?php endif; ?>

</div>
<!-- EOF:#page -->

<div id="front-page-news" class="clearfix">
    <div class="container">
        <div class="row">
            <div class="col-md-12">
            <?php 
            $query = db_select('node', 'n');
            $query->fields('n', array('nid', 'title', 'created'))
                ->condition('type', 'news_article')
                ->orderBy('created', 'DESC')
                ->range(0, 4);
            $result = $query->execute();
            while($row = $result->fetchAssoc()):
                $node = node_load($row['nid']);
                $fImage = field_get_items('node', $node, 'field_news_image');
                $fImageURI = str_ireplace('public://', '', $fImage[0]['uri']);
                $body = field_get_items('node', $node, 'body'); // $body[0]['value']
                echo '
                <a href="node/'. $row['nid'] .'" class="news-item col-md-3" style="background-image: url(\''. base_path() . 'sites/default/files/'. $fImageURI .'\')">
                    <div class="news-caption">
                        <span class="title">'. $node->title .'</span>
                    </div>
                </a>
                ';
                // <p>'. ucfirst(strtolower(substr(strip_tags($body[0]['value']), 0, 100))) .'...</p>
            endwhile;
            ?>
            </div>
        </div>
    </div>
</div>

<?php if ($page['promoted']):?>
<!-- #promoted -->
<div class="container">
  <div class="row">
  <div class="col-md-12">
    <div id="promoted" class="clearfix">
        <div id="promoted-inside" class="clearfix">
        <?php print render($page['promoted']); ?>
        </div>
    </div>
  </div>
  </div>
</div>
<!-- EOF: #promoted -->
<?php endif; ?>

<?php include ($directory . '/includes/footer.inc.php'); ?>