<?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');
}
?>
<section class="banner_category" style="background-image: url('<?php echo theme_url(); ?>images/listing/listing-banner.jpg');">
		<div class="container">
			<!-- <h2 class="banner_subtitle">check out over <span>200+</span></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 'hhhhhhhhhhh'.$page_title; ?></li> 
		    <?php } ?>
			</ul>
		</div>
	</div>

	<section class="product_listing">
		<div class="container">
			<div class="row">
      <?php if(is_array($res) && !empty($res)) { ?>
				<div class="col-lg-12 col-md-12 col-xs-12">
					<div class="product_right" id="prodListingContainer">
						<div class="row">
						
							<div class="clearfix"></div>
              <?php foreach ($res as $val) {
                    $link_url = site_url($val['friendly_url']);
                    ?>
							<div class="col-md-4 col-sm-4 col-xs-6 listpager">
								<div class="box_item">
									<div class="item_images">
										<a href="<?php echo $link_url; ?>" title="<?php echo imagealtTitle('', $val['category_name'], ''); ?>">
											<img src="<?php echo get_image('category', $val['category_image'], '298', '298', 'R'); ?>" alt="<?php echo imagealtTitle('', $val['category_name'], ''); ?>" title="<?php echo imagealtTitle('', $val['category_name'], ''); ?>">
										</a>
									</div>
									<div class="hover_box">
                                     <a href="<?php echo $link_url; ?>" title="<?php echo imagealtTitle('', $val['category_name'], ''); ?>"><?php echo $val['category_name']; ?></a>
									</div>
									<div class="description02">
										<h3><a href="<?php echo $link_url; ?>" title="<?php echo imagealtTitle('', $val['category_name'], ''); ?>"><?php echo $val['category_name']; ?></a></h3>
									</div>
								</div>
							</div>
              <?php } ?>
							
						</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>

  