<?php 
global $redux_demo;
$premiumSECtitle = $redux_demo['premium-sec-title'];
$premiumSECdesc = $redux_demo['premium-sec-desc'];
$preAdsCount = $redux_demo['premium-ads-counter'];
$featuredCatOn = $redux_demo['featured-caton'];
$featuredCat = $redux_demo['featured-ads-cat'];
?>
<section id="advertisement" class="removeMargin noBorder">
	<div class="row">
		<div class="mainHeading">
			<div class="large-7 medium-8 large-centered medium-centered columns">
				<h2><?php echo $premiumSECtitle;?></h2>
				<p><span class="line"><i class="fa fa-circle"></i></span></p>
				<p><?php echo $premiumSECdesc;?></p>
			</div>
		</div>
	</div><!-- END Heading Row-->			
	<div class="row">
		<div class="advContent"> 
			<div class="tabs-content">
				<div class="content active" id="panel1">
				<?php 
					$cat_id = get_cat_ID(single_cat_title('', false)); 
					global $paged, $wp_query, $wp;
					$args = wp_parse_args($wp->matched_query);
					$temp = $wp_query;
					$wp_query= null;
					if($featuredCatOn == 1){						
							$arags = array(
								'post_type' => 'post',
								'posts_per_page' => '-1',
								'cat' => $featuredCat,
							);
						}else{
							$arags = array(
								'post_type' => 'post',
								'posts_per_page' => '-1',								
							);
						}					
					$wp_query = new WP_Query($arags);
					$current = -1;
				?>
				<?php while ($wp_query->have_posts()) : $wp_query->the_post();
				$featuredMeta = get_post_meta($post->ID, 'featured_post', true);
				$postCatgory = get_the_category( $post->ID );
				$currCategory = $postCatgory[0]->term_id;
				$featured_post = "0";
				if($featuredCatOn == 1 && $currCategory == $featuredCat){
					$featured_post = "1";
				}else{
					$featured_post = "0";
				}				
				$post_price_plan_activation_date = get_post_meta($post->ID, 'post_price_plan_activation_date', true);
				$post_price_plan_expiration_date = get_post_meta($post->ID, 'post_price_plan_expiration_date', true);
				$post_price_plan_expiration_date_noarmal = get_post_meta($post->ID, 'post_price_plan_expiration_date_normal', true);
				$todayDate = strtotime(date('m/d/Y h:i:s'));
						$expireDate = $post_price_plan_expiration_date;
						if(!empty($post_price_plan_activation_date) && $featuredMeta == 1) {
							if(($todayDate < $expireDate) or $post_price_plan_expiration_date == 0) {
								$featured_post = "1";
							}
						}elseif($featuredMeta == 1){
							$featured_post = "1";
						}
				?>
				<?php if($featured_post == "1" && $current+2 <= $preAdsCount) {
							$current++;							
					?>		
					<div class="large-4 medium-6 columns advItems end">
						<div class="advItem"> 
							<?php 
							if ( has_post_thumbnail()) {
								$imageurl = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'classiera-grid');
								$thumb_id = get_post_thumbnail_id($post->id);
								$alt = get_post_meta($thumb_id, '_wp_attachment_image_alt', true);
								?>
								<div class="advItem-img">
									<img src="<?php echo $imageurl[0]; ?>" alt="<?php if(empty($alt)){echo "Image";}else{ echo $alt; } ; ?>"/>
								</div>
								<?php										
							}else{
								?>
								<div class="advItem-img">
									<img src="<?php echo get_template_directory_uri() . '/images/nothumb/nothumb370x300.png' ?>" alt="No Thumb"/>
								</div>
								<?php
							}
								/*Get Category Extra Fields For Price Icon Background */
								$category = get_the_category();
									if ($category[0]->category_parent == 0) {
										$tag = $category[0]->cat_ID;
										$tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
										if (isset($tag_extra_fields[$tag])) {
											$category_icon_code = $tag_extra_fields[$tag]['category_icon_code'];
											$category_icon_color = $tag_extra_fields[$tag]['category_icon_color'];
										}
									}else{
										$tag = $category[0]->category_parent;
										$tag_extra_fields = get_option(MY_CATEGORY_FIELDS);
										if (isset($tag_extra_fields[$tag])) {
											$category_icon_code = $tag_extra_fields[$tag]['category_icon_code'];
											$category_icon_color = $tag_extra_fields[$tag]['category_icon_color'];
										}
									}
									if(!empty($category_icon_code)) {
										$category_icon = stripslashes($category_icon_code);
									}
									$category_icon_code = "";
								/*Get Category Extra Fields For Price Icon Background */
							$post_price = get_post_meta($post->ID, 'post_price', true);
							if(!empty($post_price)){
							?>
							<span class="price" style="background-color:<?php echo $category_icon_color; ?>"><?php echo $post_price; ?></span>
							<?php }?>
							<a class="hover" href="<?php the_permalink(); ?>"></a>
							<div class="info">
								<a href="<?php the_permalink(); ?>">
								<?php 
									$postCatgory = get_the_category( $post->ID );											
								?>
									<i class="<?php echo $category_icon; ?>" style="background-color:<?php echo $category_icon_color; ?>"></i>
									<?php 
									$theTitle = get_the_title();
									if(is_rtl()){
										$theTitle = get_the_title();
									}else{
										$theTitle = (strlen($theTitle) > 30) ? substr($theTitle,0,30).'...' : $theTitle;
									}
									?>
									<span class="title"><?php echo $theTitle; ?></span>
									<span class="cat"><?php esc_html_e( 'Category', 'classiera' ); ?> &nbsp;:&nbsp;<?php echo $postCatgory[0]->name; ?></span>
								</a>
							</div>
						</div>
					</div>
				<?php }?>
					<?php endwhile; ?>
					<?php wp_reset_postdata(); ?>
				</div>							
				<!-- End Latest Ads -->	
			</div>
		</div>
	</div><!-- END Main Ads Section-->
</section>