<?php
/* Template Name: Kernel Gallery */
?>
<?php get_header(); ?>
<?php get_template_part(THEME_INCLUDES.'top'); ?>
	

				<!-- BEGIN .main-column-wrapper -->
				<div class="main-column-wrapper">


					<!-- BEGIN .main-column-left -->
					<div class="main-column-left">


						<!-- BEGIN .post -->
						<div class="post">
							<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
							
							<div class="post-title">
								<b><?php the_title();?></b>
							</div>

							<!-- BEGIN .photo-gallery -->
							<div class="photo-gallery">
								<?php
									$paged = get_query_string_paged();
									$posts_per_page = get_option(THEME_NAME.'_gallery_items');
									if($posts_per_page == "") {
										$posts_per_page = get_option('posts_per_page');
									}
									$my_query = new WP_Query(array('post_type' => 'gallery', 'paged' => $paged, 'posts_per_page' => $posts_per_page)); 
									$counter=1;	
								?>	
								<?php if ( $my_query->have_posts() ) : while ( $my_query->have_posts() ) : $my_query->the_post(); ?>
								<?php if ( $counter == 1 ) { ?><!-- BEGIN .row --><div class="row"> <?php } ?>
								<?php $src = get_post_thumb($post->ID,125,125); ?>
									<!-- BEGIN .index-item -->
									<div class="index-item">
										<a href="<?php the_permalink();?>"><img src="<?php echo $src["src"]; ?>" alt="<?php the_title();?>" width="125" height="125" /></a>
										<a href="<?php the_permalink();?>"><?php the_title();?></a>
									<!-- END .index-item -->
									</div>
								<?php if ($counter == 4) { ?><!-- END .row --></div><?php $counter=0; } ?>	
								<?php $counter++; ?>
								<?php endwhile; ?>
								<?php if($counter <= 4 && $counter != 1) { ?><!-- END .row --></div><?php } ?>		
								<?php else : ?>
									<h2 class="title"><?php printf ( __( 'No galleries were found' , THEME_NAME ));?></h2>
								<?php endif; ?>
										
										
								<!-- BEGIN .pages -->				
								<div class="pages">
									<?php gallery_nav_btns($paged, $my_query->max_num_pages); ?>
								<!-- END .pages -->
								</div>
								
								<?php endwhile; else: ?>
									<p><?php printf ( __('Sorry, no posts matched your criteria.' , THEME_NAME )); ?></p>
								<?php endif; ?>
										
							<!-- END .photo-gallery -->
							</div>

						<!-- END .post -->
						</div>


					<!-- END .main-column-left -->
					</div>

					<?php get_template_part(THEME_INCLUDES."sidebar"); ?>

	<?php get_footer(); ?>