<?php
/*
Template Name: Homepage
*/
?>

<?php get_header(); ?>

				<div id="theme-url" class="hidden" data-id="<?php echo get_template_directory_uri(); ?>/includes/gallery-overlay.php"></div>

                <!--BEGIN #primary .hfeed--> 
                <div id="primary" class="hfeed">
                	
                    <!--BEGIN #gallery-terms--> 
                	<div id="gallery-terms">
                    
                    	<ul>
                        	<li><a href="#" class="all current">All</a><span>/</span></li>
                            <?php wp_list_categories(array('title_li' => '', 'taxonomy' => 'photo-type', 'walker' => new Gallery_Walker())); ?>
                        </ul>
                    
                    <!--END #gallery-terms-->
                    </div>
                
                	<!--BEGIN #gallery-wrap--> 
					<div id="gallery-wrap" class="clearfix">
                
						<?php
						
						//Grab the thumbnail size option
						$thumb_size = get_option('tz_thumbnail_size');
						//Grab the thumbnail orderby option
						$order_by = get_option('tz_gallery_order');
						//Grab the thumbnail orderby option
						$qty = get_option('tz_gallery_qty');
						
						if($qty == '')
							$qty = -1;
						
						//Set ASC for title
						if($order_by == 'title') {
							$order = 'ASC';
						} else {
							$order = 'DESC';
						}
						
						//Give each size a name
						if($thumb_size == 'large' || $thumb_size == '') {
							$thumb_size = 'large-grid';
						} else if($thumb_size == 'medium') {
							$thumb_size = 'medium-grid';
						} else if($thumb_size == 'small') {
							$thumb_size = 'small-grid';
						}
						
						//Query the database
                        query_posts( array (
                            'post_type' => 'photo',
                            'posts_per_page' => $qty,
							'orderby' => get_option('tz_gallery_order'),
							'order' => $order
                            )
                        );
                        ?>
                        
                     	<ul class="<?php echo $thumb_size; ?>">
                        
                    	<?php 
							if (have_posts()) : while (have_posts()) : the_post(); 
							$terms = get_the_terms( get_the_ID(), 'photo-type' );
							
							if($thumb_size == 'large-grid' || $thumb_size == '') {
								$image = get_post_meta(get_the_ID(), 'tz_upload_image_large', TRUE);
							} else if($thumb_size == 'medium-grid') {
								$image = get_post_meta(get_the_ID(), 'tz_upload_image_medium', TRUE);
							} else if($thumb_size == 'small-grid') {
								$image = get_post_meta(get_the_ID(), 'tz_upload_image', TRUE);
							}
						?>
                        
                             <li id="photo-<?php the_ID(); ?>" class="<?php foreach ($terms as $term) { echo 'term-'.$term->term_id.' '; } ?>visible">
								<?php
								if($image != '') : ?>
                                	<a href="<?php the_permalink(); ?>"><img src="<?php echo $image; ?>" alt="<?php the_title(); ?>" /></a>
								<?php
								else:
									if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) : ?>
									<a href="<?php the_permalink(); ?>"><?php the_post_thumbnail($thumb_size); ?></a>
									<?php endif; ?>
                                <?php endif; ?> 
                             </li>
                                              
                    	<?php endwhile; endif; ?>
                        
                    	</ul>
                    
                    <!--END #gallery-wrap--> 
                    </div>
                
                <div id="content-slider"></div>
                
            <!--END #primary .hfeed-->
            </div>
            
            
<?php get_footer(); ?>