    <?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 ($catid) {
      $QryStringArr['category_id'] = $catid;
    }
    if ($this->input->post('category_id')) {
      $QryStringArr['category_id'] = $this->input->post('category_id');
    }
    
    if ($this->input->get_post('keywordSearch') != '') {
      $QryStringArr['keywordSearch'] = $this->input->get_post('keywordSearch');
    }
    
    if ($this->input->get_post('sort') != '') {
      $QryStringArr['sort'] = $this->input->get_post('sort');
    }
    if ($this->input->get_post('color') != '') {
      $QryStringArr['color'] = implode(',', $this->input->get_post('color'));
    }
    if ($this->input->get_post('size') != '') {
      $QryStringArr['size'] = implode(',', $this->input->get_post('size'));
    }
    
    if ($this->input->get_post('price') != '') {
      $priceArr = explode('-', $this->input->get_post('price'));
      $minPrice = $priceArr[0];
      $maxPrice = $priceArr[1];
      $QryStringArr['price'] = $this->input->get_post('price');
      $range = 'Range: ₹'.$priceArr[0].' - ₹'.$priceArr[1];
    } else {
      $range = 'Range: ₹1 - ₹10';
      $minPrice = 100;
      $maxPrice = 10000;
    }
    
    $type = $this->uri->segment(1);
    if ($type > 0) {
      if ($type == 1) {
        $QryStringArr['type'] = $type;
      }
      if ($type == 2) {
        $QryStringArr['type'] = $type;
      }
      if ($type == 3) {
        $QryStringArr['type'] = $type;
      }
      if ($type == 4) {
        $QryStringArr['type'] = $type;
      }
    }
    
    $cat_res2 = $this->db->query("SELECT * FROM wps_categories WHERE status = '1' and parent_id = '0' order by sort_order asc ")->result_array();
    
    ?>
    <link href="<?php echo theme_url(); ?>css/jquery-ui.css" rel="stylesheet" type="text/css">
    <link href="<?php echo theme_url(); ?>css/jquery.mCustomScrollbar.css" rel="stylesheet" type="text/css" />
    <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 $heading_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 ($this->input->post('keyword_search') == '') {
                  if ($catid) {
                    echo category_breadcrumbs($catid);
                  } else {
                    echo '<li>' . $heading_title . '</li>';
                  }
                } else {
                  echo '<li>Search Result</li>';
                }
              ?>
    			</ul>
    		</div>
    	</div>
    	<section class="product_listing">
    		<div class="container">
    			<div class="row" id="prodListingContainer">
          <?php  if (is_array($products) && !empty($products)) { ?>
    		<form name="searchForm" id="searchForm" action="" method="post" >
    				<div class="col-lg-9 col-md-9 col-lg-push-3 col-md-push-3 col-xs-12">
    					<div class="product_right">
    						<div class="row">
    							<div class="col-md-12 col-sm-12 col-xs-12">
    								<div class="page_show">
    								
    									<ul>
    										<li class="hidden-xs">Showing <?=count($products);?> results</li>
    										<li>
    											<select name="sort" onchange="this.form.submit();">
    												<option value="1" <?php echo ($this->input->get_post('sort') == '1') ? 'selected' : ''; ?>>Recommended</option>
    												<option value="2" <?php echo ($this->input->get_post('sort') == '2') ? 'selected' : ''; ?>>What's New</option>
    												<option value="3" <?php echo ($this->input->get_post('sort') == '3') ? 'selected' : ''; ?>>Price: High to Low</option>
    												<option value="4" <?php echo ($this->input->get_post('sort') == '4') ? 'selected' : ''; ?>>Price: Low to High</option>
    												<option value="5" <?php echo ($this->input->get_post('sort') == '5') ? 'selected' : ''; ?>>Popularity</option>
    											</select>
    										</li>
    										<li><span>Sort:</span>
    										</li>
    									</ul>
    								</div>
    							</div>
    							<div class="clearfix"></div>
    						<?php foreach ($products as $key => $val) {
    							$productImage = get_db_field_value("wps_products_media", "media", "WHERE products_id = '" . $val['products_id'] . "' and is_default='Y'");
    							//echo $productImage;
    							?>
    							<div class="col-md-4 col-sm-4 col-xs-6 listpager">
    								<div class="box_item">
    								<?php if ($this->session->userdata('user_id') > 0) { ?>
    									<a href="<?php echo site_url('cart/add_to_wishlist/' . $val['products_id']); ?>" class="wishlist_icon" title="Wishlist"><i class="fa fa-heart-o"></i></a>
    								<?php }else{ ?>
    									<a href="javascript:void();" onclick="alert('Please login to add the product in your wishlist!');" class="wishlist_icon" title="Wishlist"><i class="fa fa-heart-o"></i></a>
    								<?php } ?>
                      
    									<div class="item_images">
    										<a href="<?=base_url($val['friendly_url']);?>" title="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>">
    											<img src="<?php echo get_image('products', $val['media'], 270, 270, 'AR'); ?>" alt="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>" title="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>">
    										</a>
    									</div>
    									<div class="hover_box">
                                           <a href="<?=base_url($val['friendly_url']);?>" title="View Details">View Details</a>
    									</div>
    									<div class="description02">
    										<h3><a href="<?=base_url($val['friendly_url']);?>" title="<?php echo imagealtTitle('', ucwords(strtolower($val['product_name'])), ''); ?>"><?=$val['product_name'];?></a></h3>
    										<?php if($val['product_discounted_price']>0){ ?>
    											<small> <?=display_price($val['product_discounted_price']);?>
    											<span class="old_price"><?=display_price($val['product_price']);?></span>
    											</small>
    										<?php }else{ ?>
    											<small><?=display_price($val['product_price']);?></small>
    										<?php } ?>
    									</div>
    								</div>
    							</div>
                              <?php } ?>					
    							
    						</div>
    					</div>
    				</div>
    				<div class="col-lg-3 col-md-3 col-sm-4  col-xs-12 col-lg-pull-9 col-md-pull-9">
    
    					<!-- NEw Sidebar Start -->
    	<div class="sidebar">
            <div class="sidebar_title1">Filters <i class="fa fa-filter pull-right"></i></div>
            <div class="sidebar_body">
                <div class="sidebar_group">
                    <div class="sidebar_heading"><a href="javascript:void();" class="sidebar_toggle"> Categories </a></div>
                    <div class="sidebar_inner">
                        <ul>
                            <li><a href="javascript:void();">Topwear</a></li>
                            <li><a href="javascript:void();">T-Shirts</a></li>
                            <li><a href="javascript:void();">Casual Shirts</a></li>
                            <li><a href="javascript:void();">Formal Shirts</a></li>
                            <li><a href="javascript:void();">Sweatshirts</a></li>
                            <li><a href="javascript:void();">Sweaters</a></li>
                            <li><a href="javascript:void();">Jackets</a></li>
                            <li><a href="javascript:void();">Blazers & Coats</a></li>
                            <li><a href="javascript:void();">Suits</a></li>
                            <li><a href="javascript:void();">Rain Jackets</a></li>
                            <li><a href="javascript:void();">Indian & Festive Wear</a></li>
                            <li><a href="javascript:void();">Kurtas & Kurta Sets</a></li>
                            <li><a href="javascript:void();">Sherwanis</a></li>
                            <li><a href="javascript:void();">Nehru Jackets</a></li>
                            <li><a href="javascript:void();">Dhotis</a></li>
                        </ul>
                    </div>
                </div>
                
                <div class="sidebar_group">
                    <div class="sidebar_heading">
                    <a href="javascript:void();" class="sidebar_toggle_1">Price </a>
                    </div>
                    <div class="sidebar_inner">
                        <div class="price_filter_1">
                            <!--<label for="amount">Price Range:</label>-->
                            <input type="text" id="amount" readonly>
                            <input type="hidden" name="price" id="price" value="<?php echo $this->input->post('price'); ?>" />
                            <div id="slider-range"></div>
                        </div>
                    </div>
                </div>
    
                <div class="sidebar_group">
                    <div class="sidebar_heading"><a href="javascript:void();" class="sidebar_toggle"> Brand </a></div>
                    <div class="sidebar_inner">
                        <div class="product_filter">
                                <ul>
                                    <?php
                                    $sl = 1;
                                    foreach ($brands as $c => $brandcval) {
                                        $brandArr = $this->input->post('brand');
                                        $brandchk = "";
                                       // print_r($brandArr);
                                        if (is_array($brandArr) && !empty($brandArr)) {
                                            $brandchk = (in_array($brandcval['brand_id'], $brandArr)) ? 'checked' : '';
                                         }
                                        ?>
                                        <li>
                                            <label for="brand<?=$sl;?>">
                                                <input name="brand[]" type="checkbox" value="<?php echo $brandcval['brand_id']; ?>" id="brand<?=$sl;?>"  onclick="$('#searchForm').submit();" <?php echo $brandchk; ?>> <span id="red"><?php echo $brandcval['brand_name']; ?></span>
                                            </label>
                                        </li>
                                        <?php
                                            $sl++;
                                        }
                                        ?>
                                </ul> 
                        </div>
                        </div>
                </div>
    
                <div class="sidebar_group">
                    <div class="sidebar_heading"><a href="javascript:void();" class="sidebar_toggle"> Styles </a></div>
                    <div class="sidebar_inner">
                        <div class="product_filter">
                                <ul>
                                    <?php
                                    $sl = 1;
                                    foreach ($styles as $c => $stlcval) {
                                        $styleArr = $this->input->post('style');
                                        $stchk = "";
                                        if (is_array($styleArr) && !empty($styleArr)) {
                                            $stchk = (in_array($stlcval['style_id'], $styleArr)) ? 'checked' : '';
                                         }
                                        ?>
                                        <li>
                                            <label for="style<?=$sl;?>">
                                                <input name="style[]" type="checkbox" value="<?php echo $stlcval['style_id']; ?>" id="style<?=$sl;?>"  onclick="$('#searchForm').submit();" <?php echo $stchk; ?>> <span id="red"><?php echo $stlcval['style_name']; ?></span>
                                            </label>
                                        </li>
                                        <?php
                                            $sl++;
                                        }
                                        ?>
                                </ul> 
                        </div>
                        </div>
                </div>
    
                <div class="sidebar_group">
                    <div class="sidebar_heading"><a href="javascript:void();" class="sidebar_toggle"> Room </a></div>
                    <div class="sidebar_inner">
                        <div class="product_filter">
                                <ul>
                                    <?php
                                    $sl = 1;
                                    foreach ($rooms as $c => $roomcval) {
                                        $roomArr = $this->input->post('room');
                                        $roomchk = "";
                                        if (is_array($roomArr) && !empty($roomArr)) {
                                            $roomchk = (in_array($roomcval['room_id'], $roomArr)) ? 'checked' : '';
                                         }
                                        ?>
                                        <li>
                                            <label for="room<?=$sl;?>">
                                                <input name="room[]" type="checkbox" value="<?php echo $roomcval['room_id']; ?>" id="room<?=$sl;?>"  onclick="$('#searchForm').submit();" <?php echo $roomchk; ?>> <span id="red"><?php echo $roomcval['room_name']; ?></span>
                                            </label>
                                        </li>
                                        <?php
                                            $sl++;
                                        }
                                        ?>
                                </ul> 
                        </div>
                        </div>
                </div>
    
                <div class="sidebar_group">
                    <div class="sidebar_heading"><a href="javascript:void();" class="sidebar_toggle"> Color </a></div>
                    <div class="sidebar_inner">
                        <div class="product_filter">
                                <ul>
                                    <?php
                                    $sl = 1;
                                    foreach ($colors as $c => $colorcval) {
                                        $colorArr = $this->input->post('color');
                                        $colorchk = "";
                                        if (is_array($colorArr) && !empty($colorArr)) {
                                            $colorchk = (in_array($colorcval['color_id'], $colorArr)) ? 'checked' : '';
                                         }
                                        ?>
                                        <li>
                                            <label for="color<?=$sl;?>">
                                                <input name="color[]" type="checkbox" value="<?php echo $colorcval['color_id']; ?>" id="color<?=$sl;?>"  onclick="$('#searchForm').submit();" <?php echo $colorchk; ?>> <span id="red"><?php echo $colorcval['color_name']; ?></span>
                                            </label>
                                        </li>
                                        <?php
                                            $sl++;
                                        }
                                        ?>
                                </ul> 
                        </div>
                        </div>
                </div>
    
    
                
                <!-- <div class="sidebar_group">
                    <div class="sidebar_heading"><a href="javascript:void();" class="sidebar_toggle"> Clothing & Accessories</a></div>
                    <div class="sidebar_inner">
                        <div class="product_filter">
                            <ul>
                                <li><label><input name="occasion" type="checkbox" value="1"> <span>Tshirts (274)</span></label></li>
                                <li><label><input name="occasion" type="checkbox" value="2"> <span>Jeans (240)</span></label></li>
                                <li><label><input name="occasion" type="checkbox" value="3"> <span>Shirts (123)</span></label></li>
                                <li><label><input name="occasion" type="checkbox" value="4"> <span>Trousers (56)</span></label></li>
                                <li><label><input name="occasion" type="checkbox" value="5"> <span>Sweatshirts (45)</span></label></li>
                                <li><label><input name="occasion" type="checkbox" value="6"> <span>Shorts (28)</span></label></li>
                                <li><label><input name="occasion" type="checkbox" value="7"> <span>Jackets (26)</span></label></li>
                                <li><label><input name="occasion" type="checkbox" value="8"> <span>Track Pants (20)</span></label></li>
                                <li><label><input name="occasion" type="checkbox" value="9"> <span>Kurtas (2)</span></label></li>
                                <li><label><input name="occasion" type="checkbox" value="10"> <span>Sports Shoes</span></label></li>
                            </ul>
                        </div>
                        </div>
                </div> -->
                
                
                <div class="sidebar_group">
                    <div class="sidebar_heading"><a href="javascript:void();" class="sidebar_toggle"> Size</a></div>
                    <div class="sidebar_inner">
                       <div class="product_filter">
                                <ul>
                                    <?php
                                    $sl = 1;
                                    foreach ($sizes as $c => $cval) {
                                        $sizeArr = $this->input->post('size');
                                        $chk = "";
                                        if (is_array($sizeArr) && !empty($sizeArr)) {
                                            $chk = (in_array($cval['size_id'], $sizeArr)) ? 'checked' : '';
                                         }
                                        ?>
                                        <li>
                                            <label for="size<?=$sl;?>">
                                                <input name="size[]" type="checkbox" value="<?php echo $cval['size_id']; ?>" id="size<?=$sl;?>"  onclick="$('#searchForm').submit();" <?php echo $chk; ?>> <span id="red"><?php echo $cval['size_name']; ?></span>
                                            </label>
                                        </li>
                                        <?php
                                            $sl++;
                                        }
                                        ?>
                                    </ul>
                        </div>
                        
                    </div>
                </div>
                
                
    
            </div>
        </div>
    
        <!-- New Sidebar End --->
    
    
    
    					<div>
    						<div>
    							 <!-- <div class="product_filter">
    								<div class="left_title">Categories <i class="fa fa-filter pull-right"></i>
    								</div>
    								<ul>
    									<li>
    										<label>
    											<input name="occasion" type="checkbox" value="1"> <span>Tshirts (274)</span>
    										</label>
    									</li>
    								</ul>
    							</div>  -->
    							<!-- <div class="product_filter showcase">
    								<div class="left_title">Color <i class="fa fa-filter pull-right"></i>
    								</div>
    								<ul id="content-1" class="content mCustomScrollbar">
    								<?php
    								$sl = 1;
    								foreach ($colors as $c => $cval) {
    									$colorArr = $this->input->post('color');
    									$chk = "";
    									if (is_array($colorArr) && !empty($colorArr)) {
    										$chk = (in_array($cval['color_id'], $colorArr)) ? 'checked' : '';
    									 }
    									?>
    									<li>
    										<label for="color<?=$sl;?>">
    											<input name="color[]" type="checkbox" value="<?php echo $cval['color_id']; ?>" id="color<?=$sl;?>"  onclick="$('#searchForm').submit();" <?php echo $chk; ?>> <span id="red"><?php echo $cval['color_name']; ?></span>
    										</label>
    									</li>
    									<?php
    										$sl++;
    									}
    									?>
    								</ul>
    							</div> -->
    							 <!-- <div class="product_filter showcase">
    								<div class="left_title">Size <i class="fa fa-filter pull-right"></i>
    								</div>
    								<ul id="content-1" class="content mCustomScrollbar">
    								<?php
    								$sl = 1;
    								foreach ($sizes as $c => $cval) {
    									$sizeArr = $this->input->post('size');
    									$chk = "";
    									if (is_array($sizeArr) && !empty($sizeArr)) {
    										$chk = (in_array($cval['size_id'], $sizeArr)) ? 'checked' : '';
    									 }
    									?>
    									<li>
    										<label for="size<?=$sl;?>">
    											<input name="size[]" type="checkbox" value="<?php echo $cval['size_id']; ?>" id="size<?=$sl;?>"  onclick="$('#searchForm').submit();" <?php echo $chk; ?>> <span id="red"><?php echo $cval['size_name']; ?></span>
    										</label>
    									</li>
    									<?php
    										$sl++;
    									}
    									?>
    								</ul>
    							</div> --> 
    							<!-- <div class="product_filter">
    								<div class="left_title">Size</div>
    								<ul class="size_list">
    									<li><a href="#">S</a>
    									</li>
    								</ul>
    							</div> -->
    						</div>
    					</div>
    				</div>
    				</form>
    
            <?php }else{ ?>
              <div class="text-center mt10">
                <h2 class="contact-title">Sorry, No Result Found!</h2>
                <img src="<?php echo theme_url(); ?>images/noresult.gif" width="350" title="No Result Found" alt="No Result Found" />
                <br/><br/>
                <button type="button" class="checkout_btn" onclick="window.location.href='<?php echo site_url('products'); ?>'">Browse Products</button>
              </div>
            <?php } ?>
             <?php if(isset($cat_res['category_description'])){ echo '<div class="col-md-12"><br/>'.$cat_res['category_description'].'</div>'; } ?>
    			</div>
    		</div>
    	</section>
    
    <?php $this->load->view("bottom"); ?>
    <script src="<?php echo theme_url(); ?>js/jquery-ui.js"></script>
    	<script src="<?php echo theme_url(); ?>js/jquery.mCustomScrollbar.concat.min.js"></script>
    	<script>
    			$( function() {
    				$( "#slider-range" ).slider({
    					range: true,
    					min: 0,
    					max: 10000,
    					values: [ <?php echo $minPrice; ?>, <?php echo $maxPrice; ?> ],
    					slide: function( event, ui ) {
    						$( "#amount" ).val( "₹" + ui.values[ 0 ] + " - ₹" + ui.values[ 1 ] );
    						$("#price").val(ui.values[ 0 ] + "-" + ui.values[ 1 ]);
    					},change: function (event, ui) {
    						$("#searchForm").submit();
    					}
    				});
    				$( "#amount" ).val( "₹" + $( "#slider-range" ).slider( "values", 0 ) +
    					" - ₹" + $( "#slider-range" ).slider( "values", 1 ) );
    			} );
    	</script>
    
        <script>
    $(document).on('click', '.sidebar_heading a.sidebar_toggle', function(e){
        var $this = $(this);
    	if(!$this.hasClass('sidebar_collapsed')) {
    		$this.parents('.sidebar_group').find('.sidebar_inner').slideUp();
    		$this.addClass('sidebar_collapsed')
    		
    	} else {
    		$this.parents('.sidebar_group').find('.sidebar_inner').slideDown();
    		$this.removeClass('sidebar_collapsed')
    		
    	}
    })
        </script>
    
    
    <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_list_rows; ?>;
          
          if (!triggeredPaging && page < actual_count) {
            triggeredPaging = 1;
            $.ajax({
              type: "POST",
              url: "<?php echo base_url(); ?>products/ajax_load_product_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>
