<?php get_header(); ?>
<?php $projectLayout = rwmb_meta( 'kk_project_layout', 'type=select', $post->ID );
	  $el_pos = 'left';
	  
	switch( $projectLayout ) {
		case "sidebar_on":	
			$el_pos = 'left';
		break;
		case "sidebar_off":	
			$el_pos = 'none';
		break;
		case "halfs":	
			$el_pos = 'none';
		break;		
	}
?>

<?php $title_type = kktfwp_title_type(); ?>

<?php if ( post_password_required( $post ) ) { 

		get_template_part( 'password-form' );
		
	} else { ?>
	
	<?php if (have_posts()) : ?>
		<?php while (have_posts()) : the_post(); ?>		
			<!-- start content wrapper -->	
			<div <?php post_class('content'); ?> id="post-<?php the_ID() ?>">
				<?php if( $title_type == 'parallax' ) : ?>
	
					<div id="kk-parallax-wrapper" class="kk-parallax-wrapper">
						
						<?php echo kktfwp_parallax(); ?>

						<div id="kk-parallax-title-wrapper" class="kk-parallax-title-wrapper">
							<div id="kk-parallax-title" class="page-title">
								<?php $source = rwmb_meta( 'kk_customTitle', false, kktfwp_postid() );						
								if ( $source ) : ?>						
									<?php echo wp_kses( rwmb_meta( 'kk_customdescription', false, kktfwp_postid()), kktfwp_kses_allowed_args()) ?>						
								<?php else: ?>					
									<?php the_title( '<h1>', '</h1>' ); ?>						
								<?php endif; ?>
							</div>
						</div>	
						
						<a id="kk-down" class="kk-down is-loading" href="#kk-to-me"></a>
					
					</div>	

				<?php endif; ?>
				
				<div class="content-inner-wrapper clearfix">
					<span id="kk-to-me"></span>	
				<?php if( $title_type == 'default' ) { ?>
				
					<div class="post-title">
						<?php the_title ('<h1>', '</h1>'); ?>
					</div>	

					<div class="divider clear"></div>	
					
				<?php } ?>
				
					<div id="<?php echo esc_attr($el_pos) ?>" class="inner-content">				
								
						<?php	$mediaType = rwmb_meta( 'kk_project_type', 'type=select',  $post->ID );
						
							switch( $mediaType ) {
								case "image":														
									
								$attachments = rwmb_meta( 'kk_projimg', 'type=image_advanced' ); ?>
								
								<div class="portfolio-images">	

									<?php foreach ($attachments as $attachment) { 
									
										echo wp_get_attachment_image( $attachment['ID'], 'large', '', array( 'title' => $attachment['caption'], 'data-lazy-load' => 0 ) );
										
									} ?>
								
								</div>
								
								<?php
								break;

								case "slideshow": ?>
								
									<!-- start slider -->		
									<div class="slider-wrapper">	
										
										<div id="kk_post_slider_<?php the_ID(); ?>" class="royalSlider rsDefault kk-slider-ef">
											<?php $attachments = rwmb_meta( 'kk_projimg', 'type=image_advanced' );
												
											foreach ($attachments as $attachment) { 
								
												echo wp_get_attachment_image( $attachment['ID'], 'large', '', array( 'class' => 'rsImg', 'title' => $attachment['caption'], 'data-lazy-load' => 0 ) );
												
											} ?>
										</div>
										
									</div>
									<!-- end slider -->
								<?php break;

								case "video":
									$projectVideo = rwmb_meta( 'kk_projvid', 'type=textarea', $post->ID );
																
									echo '<div class="portfolio-thumb"><div class="embed-container">'. $projectVideo .'</div></div>';									
								
									break;
									
							}
						?>			
					
					<div class="portfolio-content">	
						<div class="portfolio-entry">
							<?php the_content(); ?>
						</div>	
					
					</div>
					
					<!-- start projects nav -->
					<?php kktfwp_project_nav(); ?>
					<!-- end projects nav -->
					
					<?php 
						// If comments are open or we have at least one comment, load up the comment template
						if ( comments_open() || get_comments_number() ) {
							comments_template();
						} 
					?>
				
				</div>
				
				<!-- start widgets -->
				<?php if ($el_pos === 'left') : ?>
					<?php if(is_active_sidebar("kk-portfolio-sidebar")) : ?> 
						<div class="sidebar">
							<?php dynamic_sidebar("kk-portfolio-sidebar")?>		
						</div>
					<?php endif; ?>
				<?php endif; ?>
				<!-- end widgets -->
							
				</div>
				
				<?php get_template_part('extends/footer-area') ?>
				
			</div>
			<!-- end content wrapper -->
		<?php endwhile; ?>
	
	<?php endif; ?>
<?php } ?>
	
<?php get_footer(); ?>