<?php
$this->load->view("top");
$QryStringArr = array();  // To store all Query Variables so to move to other view;
$QryStringArr = array_unique($QryStringArr);
if (isset($this->meta_info['entity_id']) && $this->meta_info['entity_id'] != '') {
  $QryStringArr['category_id'] = $this->meta_info['entity_id'];
}
if ($this->input->get_post('keyword') != '') {
  $QryStringArr['keyword'] = $this->input->get_post('keyword');
}
if ($this->input->get_post('sort') != '') {
  $QryStringArr['sort'] = $this->input->get_post('sort');
}


 $parent_id=$parentres['category_id'];
if($parentres['bg_image']!=''){ 
     $dimage=  get_image('category', $parentres['bg_image'], '', '', 'R');
    
}else if($parentres['parent_id']==$parent_id) {
    $dimage=  get_image('category', $parentres['bg_image'], '', '', 'R');
} else{
    $dimage=  theme_url().'images/listing/listing-banner.jpg'; 
    
}


?>
  <section class="banner_category" style="background-image: url('<?=theme_url();?>img/inner-banner.jpg');">
        <div class="container">
            <h2 class="banner_subtitle">Free Shipping Within India Only</h2>
            <h1 class="banner_title"><?php echo $page_title; ?></h1>
        </div>
    </section>
	<div class="page_breadcrumbs">
		<div class="container">
			<ul>
      <li><a href="<?php echo site_url(); ?>" title="Home">Home</a>
        </li>
        <?php if(isset($parentres['category_id'])){ echo category_breadcrumbs($parentres['category_id']); }else{ ?>
        <li><?php echo $page_title; ?></li> 
		    <?php } ?>
			</ul>
		</div>
	</div>
<div class="clearfix"></div>
    <section class="ptb-50">
        <div class="inner">
        <div class="row">
                            <h2 class="gallery_title"> Lowest price on <?php echo $page_title; ?></h2>
                            <div class="clearfix"></div>
        <?php if(is_array($res) && !empty($res)) { 
    
        foreach ($res as $val) {
                    $link_url = site_url($val['friendly_url']);
                    ?>
                <div class="col-xxl-4 col-xl-4 col-lg-4 col-md-6 col-sm-6 col-12">
                                <div class="single-aboss-product">
                                    <div class="pro-img">
                                        <a href="<?php echo $link_url; ?>" title="<?php echo imagealtTitle('', $val['category_name_p'], ''); ?>">
                                            <img src="<?php echo get_image('category', $val['category_image'], '600', '400', 'R'); ?>" alt="<?php echo imagealtTitle('', $val['category_name_p'], ''); ?>" title="<?php echo imagealtTitle('', $val['category_name_p'], ''); ?>">
                                      
                                        </a>
                                    </div>
                                    <div class="product-head-title">
                                        <h4><a href="<?php echo $link_url; ?>" title="<?php echo imagealtTitle('', $val['category_name_p'], ''); ?>"><span> <?php if(isset($val['category_name_p'])){ echo $val['category_name_p']; } ?></span></a></h4>

                                    </div>
                                </div>
                   </div>
            <?php } } ?>
<?php
            if (isset($parentres['category_description'])) {
              echo $parentres['category_description'];
            }
            ?>
             </div>
        </div>
    </section>
  
<?php $this->load->view("bottom"); ?>
<script type="text/javascript">
  var page = 1;
  var triggeredPaging = 0;

  $(window).scroll(function () {
    $('#loadingdiv').hide();
    var scrollTop = $(window).scrollTop();
    var scrollBottom = (scrollTop + $(window).height());
    var containerTop = $('#prodListingContainer').offset().top;
    var containerHeight = $('#prodListingContainer').height();
    var containerBottom = Math.floor(containerTop + containerHeight);
    var scrollBuffer = 0;
    if ((containerBottom - scrollBuffer) <= scrollBottom) {
      page = $('.listpager').length;
      var queryString = '?stOffSet=' + page;
<?php
if (count($QryStringArr)) {
  foreach ($QryStringArr as $qrykey => $qryval) {
    ?>
          queryString += "&<?php echo $qrykey; ?>=<?php echo $qryval; ?>";
    <?php
  }
}
?>
      var actual_count = <?php echo $total_rows; ?>;

      if (!triggeredPaging && page < actual_count) {
        triggeredPaging = 1;
        $.ajax({
          type: "POST",
          url: "<?php echo base_url(); ?>category/ajax_load_category_view" + queryString,
          error: function (res) {
            //alert('Error');
            triggeredPaging = 0;
            $('#loadingdiv').hide();
            //console.log(arguments);
          },
          beforeSend: function (jqXHR, settings) {
            $('#loadingdiv').show();

          },
          success: function (res) {
            $('#loadingdiv').hide();
            $("#prodListingContainer").append(res);
            triggeredPaging = 0;
            //console.log(res);
            $('.listpager').fadeTo(1000, 0.5, function () {
              $(this).fadeTo(1000, 1.0);
            });
          }
        });
      }
    }
  });
</script>

  