<?php
get_header();
$do_not_duplicate = '';
?>

<?php if (intval(of_get_option('of_qs_nrfea')) > 0 ) { ?>
	<section id="featuredWrapper">
		<div class="featured-slider">
			<?php
			$cycle2_slidefx = array(
				'fade' => 'fade',
				'fadeout' => 'fadeout',
				'scrollHorz' => 'scrollHorz',
				'none' => 'none'
			);
			
			if (of_get_option('of_qs_featimeout') == '0' ) { 
				$timeout = "999999";
			} else { 
				$timeout = of_get_option('of_qs_featimeout');
			}
			?>
			
			<div class="cycle-slideshow" 
				data-cycle-fx="fadeout" 
				data-cycle-timeout="<?php echo $timeout.'000'; ?>"
				data-cycle-slides="> article"
				data-cycle-prev=".btn_prev" 
				data-cycle-next=".btn_next"
				data-cycle-pager=".template-pager"
				data-cycle-manual-fx="<?php echo $cycle2_slidefx[of_get_option('of_qs_sfunc')]; ?>"
				data-cycle-manual-speed="300"
			>
				<?php 
				$count=1;		
				if (of_get_option('of_qs_featype') == 'mrecent') {
					$args = array(
					  'posts_per_page' => of_get_option('of_qs_nrfea'),
					);
				}
				elseif (of_get_option('of_qs_featype') == 'tagbased') {
					$args = array(
					  'posts_per_page' => of_get_option('of_qs_nrfea'),
					  'tag' => of_get_option('of_qs_tagfea')
					);
				}
				elseif (of_get_option('of_qs_featype') == 'cfbased') {
					$args = array(
					  'post_type' => 'any',
					  'posts_per_page' => of_get_option('of_qs_nrfea'),
					  'meta_key' => 'featured', 
					  'meta_value' => 'true'
					);
				}				
				else {
					$args = array(
					  'cat' => of_get_option('of_qs_catfea'), 
					  'posts_per_page' => of_get_option('of_qs_nrfea')
					);
				}			
								
				$gab_query = new WP_Query();$gab_query->query($args); 
				while ($gab_query->have_posts()) : $gab_query->the_post();
				
				if (of_get_option('of_dnd') == 1) {
					$do_not_duplicate[] = $post->ID;
				}
				?>
					<article class="slide_item">
						<div class="slide_media">
							<?php 
							gabfire_media(array(
								'name' => 'qs-featured', 
								'imgtag' => 1,
								'link' => 1,
								'enable_video' => 1, 
								'video_id' => 'mediabar', 
								'enable_thumb' => 1, 
								'catch_image' => 1,
								'resize_type' => 'c', /* c to crop, h to resize only height, w to resize only width */
								'media_width' => '431', 
								'media_height' => '198', 
								'thumb_align' => 'alignnone', 
								'enable_default' => of_get_option('of_qs_enfea1'),
								'default_name' => 'featured.jpg'
								)); 
							?>
						</div>
						
						<div class="slide_text">
						
							<h2 class="entry-title">
								<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'gabfire' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
							</h2>
							
							<p class="slide_meta">
								<?php echo get_the_date('');?> 
								<?php _e('by','gabfire'); ?> <?php the_author_posts_link(); ?> - 
								<?php comments_popup_link(__('No Comment','gabfire'), __('1 Comment','gabfire'), __('% Comments','gabfire'));?>
								<?php edit_post_link(__('Edit','gabfire'),' / ',''); ?>
							</p>
							
							<p><?php echo gabfire_limit_words(get_the_excerpt(),55); ?>&hellip;</p>
							
						</div>
						
					</article><!-- /slide_item -->	
				<?php $count++; endwhile; wp_reset_query(); ?>
			</div>
			
			<div class="nav">
				<div class="btn_prev" id="btn_prev" href="#"><?php _e('Previous','gabfire'); ?></div>
				<div class="btn_next" id="btn_next" href="#"><?php _e('Next','gabfire'); ?></div>
				<div class="template-pager"></div>
			</div><!-- /nav -->					
		</div><!-- Featured Slider -->
	</section>
	
<?php } ?> 

<?php
$numberofposts = of_get_option('of_qs_nr1') + of_get_option('of_qs_nr2') + of_get_option('of_qs_nr3') + of_get_option('of_qs_nr4');



if (intval($numberofposts) > 0 ) { ?>
	<section id="top_storiesWrapper"<?php if (intval(of_get_option('of_qs_nrfea')) == 0 ) { echo 'class="addspacing"'; } ?>>
		<div id="top_stories">
			
			<h3 class="title">
				<?php echo of_get_option('of_qs_title1'); ?>
			</h3>
			
			<?php 				
			$cat_count = 4; /* foreach loop will be repeated four times */
			$current = 1; /* we will use this var to get the index of current foreach */
			$options = array();

			for ($i=1; $i<=$cat_count;$i++) {
				if(0 < strlen($variable = of_get_option('of_qs_nr'.$i))) {
					$options[$i]['posts_per_page'] = $variable;
				}
				if(0 < strlen($variable = of_get_option('of_qs_cat'.$i))) {
					$options[$i]['cat'] = $variable;
				}
			}
			
			foreach ($options as $id => $option)
			{
				if (0 == $options[$id]['posts_per_page']) {
					continue;
				}

				?>

				<div class="postbox <?php if($current == 4) echo 'lastpostbox'; ?>">
					
					<p class="catname">
						<a href="<?php echo get_category_link($options[$id]['cat']);?>"><?php echo get_cat_name($options[$id]['cat']); ?></a>
					</p>

					<?php
					$catid = $options[$id]['cat'];
					$postnr =  $options[$id]['posts_per_page'];
					?>				
					
					<?php
					$count = 1; 
					$args = array(
					  'post__not_in'=>$do_not_duplicate,
					  'posts_per_page' =>  $postnr,
					  'cat' => $catid
					);	
					
					$gab_query = new WP_Query();$gab_query->query($args); 
					while ($gab_query->have_posts()) : $gab_query->the_post();						
					
					if (of_get_option('of_dnd') == 1) {
						$do_not_duplicate[] = $post->ID;
					}
					?>
						<article>

							<?php 
							gabfire_media(array(
								'name' => 'qs-topstories', 
								'enable_video' => 1, 
								'imgtag' => 1,
								'link' => 1,
								'video_id' => 'top_story1', 
								'enable_thumb' => 1, 
								'catch_image' => 1,
								'resize_type' => 'c', /* c to crop, h to resize only height, w to resize only width */
								'media_width' => '218', 
								'media_height' => '109', 
								'thumb_align' => 'aligncenter', 
								'enable_default' => of_get_option('of_qs_enfea2'),
								'default_name' => 'top_stories.jpg'
								)); 
							?>					
							<h2 class="entry-title">
								<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'gabfire' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
									<?php the_title(); ?>
								</a>
							</h2>
							
							<p class="metadata">
								<?php echo get_the_date('');?> 
								<?php _e('by','gabfire'); ?> <?php the_author_posts_link(); ?> 
								<?php edit_post_link(__('Edit','gabfire'),' - ',''); ?>
							</p>
							
							<p><?php echo gabfire_limit_words(get_the_excerpt(), 13); ?>&hellip;</p> 						
						</article>
						
					<?php $count++; endwhile; wp_reset_query(); ?>
				</div>
				<?php if ($current == 2) { ?><div class="clearfix visible-sm visible-xs"></div><?php } ?>
			<?php
			$current++;
			} ?>
		</div><!-- /top_stories -->
	</section><!-- /top_storiesWrapper -->
<?php } ?>
<section id="body">	
	<div id="main_content">

		<h3 class="title">
			<?php echo of_get_option('of_qs_title2'); ?>
		</h3>

		<?php 
		$count = 1;
		
		if (of_get_option('of_qs_latestnews') == 'mrecent') {
			$args = array(
			  'posts_per_page' => of_get_option('of_qs_nr5'),
			);
		}
		elseif (of_get_option('of_qs_latestnews') == 'tagbased') {
			$args = array(
			  'posts_per_page' => of_get_option('of_qs_nr5'),
			  'tag' => of_get_option('of_qs_tag5')
			);
		}			
		else {
			$args = array(
			  'cat' => of_get_option('of_qs_cat5'), 
			  'posts_per_page' => of_get_option('of_qs_nr5')
			);
		}
		
		$gab_query = new WP_Query();$gab_query->query($args); 
		while ($gab_query->have_posts()) : $gab_query->the_post();
		
		$gab_iframe = get_post_meta($post->ID, 'iframe', TRUE);
		
		if (of_get_option('of_dnd') == 1) {
			$do_not_duplicate[] = $post->ID;
		};
		?>		
		
		<article id="post-<?php the_ID(); ?>" <?php post_class('post'); ?>>
				
				<div class="head">
					<h2 class="entry-title">
						<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'gabfire' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
							<?php the_title(); ?>
						</a>
					</h2>
					
					<p class="metadata-top">
						<i class="fa fa-calendar"></i> <?php echo get_the_date('') ?> 
						<?php _e('by','gabfire'); ?> 
						<?php the_author_posts_link(); ?>
						<span class="postcomment"><i class="fa fa-comment-o"></i> <?php comments_popup_link(__('No Comment','gabfire'), __('1 Comment','gabfire'), __('% Comments','gabfire'));?></span>
					</p>
				</div><!-- /post head -->
				
				<div class="entry">
					<?php
						if($gab_iframe !== '') {	
							$media_width = 538;
							$media_height = 300;
							$media_class = 'aligncenter';
						} else {
							$media_width = 200;
							$media_height = 150;
							$media_class = 'alignleft';							
						}
			
						gabfire_media(array(
							'name' => 'qs-body', 
							'imgtag' => 1,
							'link' => 1,
							'enable_video' => 1,
							'enable_thumb' => 1, 
							'catch_image' => 1,
							'resize_type' => 'c', /* c to crop, h to resize only height, w to resize only width */
							'media_width' => $media_width, 
							'media_height' => $media_height, 
							'thumb_align' => $media_class,
							'enable_default' => of_get_option('of_qs_enfea6'),
							'default_name' => 'latest_news.jpg'
						)); 
					?>
					<p><?php echo gabfire_limit_words(get_the_excerpt(), 55); ?>&hellip;</p> 	
				</div><!-- /entry -->
				
				<div class="metadata-bot">
					<div class="cats">
						<i class="fa fa-folder-open-o"></i> <?php the_category(' &middot; ') ?>
					</div>
					
					<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'gabfire' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark" class="btn btn-default">
						<?php _e('Read More', 'gabfire'); ?> <i class="fa fa-chevron-circle-right"></i>
					</a>
				</div><!-- /metadata -->
										
		</article><!-- /post -->
		
		<?php $count++; endwhile; wp_reset_query(); ?>
	</div><!-- /main_content -->
	
		<aside id="sidebar">
			<?php get_sidebar(); ?> 
		</aside>

</section><!-- /body -->

<?php get_footer(); ?>