<?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['category_icon']!=''){ 
     $dimage=  get_image('category', $parentres['category_icon'], '', '', 'R');
    
}else if($parentres['parent_id']==$parent_id) {
    $dimage=  get_image('category', $parentres['category_icon'], '', '', 'R');
} else{
    $dimage=  theme_url().'images/listing/listing-banner.jpg'; 
    
}


?>
  <section class="banner_category" style="background-image: url('<?php echo $dimage; ?>');">
    <div class="container">
      
      <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>
       <?php if(isset($parentres['category_id'])){ echo category_breadcrumbs($parentres['category_id']); }else{ ?>
        <li><?php echo $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-3 col-sm-3 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'], ''); ?>">View More</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 } ?>
                <div class="text_desc bottom_div">
      <?php if(isset($parentres['category_description'])){ echo $parentres['category_description']; } ?>
                </div>
			</div>
		</div>
	</section>
  
      
  
<script>
  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>

<?php $this->load->view("bottom"); ?>


  