<?php
/**
 * The loop that displays posts.
 *
 * The loop displays the posts and the post content.  See
 * http://codex.wordpress.org/The_Loop to understand it and
 * http://codex.wordpress.org/Template_Tags to understand
 * the tags used in it.
 */
/*$featured_image_type = theme_get_option('blog', 'featured_image_type');
$display_default = theme_get_option('blog','display_default');
$display_meta = theme_get_option('blog','display_meta');*/

if(is_search()){
	$featured_image_type = theme_get_option('blog', 'search_featured_image_type');
	$display_default = theme_get_option('blog','search_display_default');
	$display_meta = theme_get_option('blog','search_display_meta');
	$layout = theme_get_option('blog','search_layout');
	if($layout == 'default'){
		$layout = theme_get_option('general','layout');
	}
	$display_full = theme_get_option('blog','search_display_full');
}else{
	$featured_image_type = theme_get_option('blog', 'featured_image_type');
	$display_default = theme_get_option('blog','display_default');
	$display_meta = theme_get_option('blog','display_meta');
	$layout = theme_get_option('blog','layout');
	if($layout == 'default'){
		$layout = theme_get_option('general','layout');
	}
	$display_full = theme_get_option('blog','display_full');
}
$desc_length = theme_get_option('blog','excerpt_count');
if(!empty($desc_length)){
	$excerpt_constructor = new Theme_The_Excerpt_Length_Constructor($desc_length);
	add_filter( 'excerpt_length', array($excerpt_constructor,'get_length'));
}
$read_more = theme_get_option('blog','read_more');

$meta_items = theme_get_option('blog','meta_items');
?>
<?php if ( have_posts() ) while ( have_posts() ) : 
		the_post(); 
		$has_image = has_post_thumbnail();
		$has_image = $has_image ? true : $display_default; 
?>
<article id="post-<?php the_ID(); ?>" class="post <?php echo $featured_image_type.'-feature';?>"> 
<?php if($featured_image_type == "none" || !$has_image):?>
			<div class="no-feature">
			<div class="cont-vert">
				<div class="outer-vert">
					<div class="inner-vert">
						<h2 class="post-title-overimage vert-position">
							<a href="<?php echo get_permalink() ?>" rel="bookmark" title="<?php printf( __("Permanent Link to %s", THEME_FRONT_DOMAIN), get_the_title() ); ?>"><?php the_title(); ?></a>
						</h2>
					</div>
				</div>
			</div>
<?php if(in_array('comment',$meta_items)):?>
			<div class="post-comments-overimage">
				<div class="post-comments-bubble">
					<?php comments_popup_link(__('0',THEME_FRONT_DOMAIN), __('1',THEME_FRONT_DOMAIN), __('%',THEME_FRONT_DOMAIN),'',__('X',THEME_FRONT_DOMAIN));?>
				</div>
			</div>
<?php endif;?>
			<div class="clear"></div>
			</div>
<?php if($display_meta && ( count($meta_items)>1 || (count($meta_items)==1 && !in_array('comment',$meta_items)))):?>
	<div class="post-bottoms">
		<div class="post-meta">
			<?php echo theme_generator('post_meta'); ?>
		</div>
	</div>
<?php else:?>
	<div class="divider" style="margin-bottom:20px;padding-top:5px"></div>
<?php endif;?>
	<div class="post-content">
<?php 
	if($display_full):
		global $more;
		$more = 0;
		the_content(wpml_t(THEME_NAME, 'Blog Post Read More Button Text',stripslashes(theme_get_option('blog','read_more_text'))),false);
	else:
		the_excerpt();
		if($read_more){
		$is_button = theme_get_option('blog','read_more_button');
?>
		<a class="read_more_link <?php echo $is_button?'button medium white':'';  ?>" href="<?php the_permalink(); ?>">
		<?php 
			echo '<span class="text" style="">';
			echo wpml_t(THEME_NAME, 'Blog Post Read More Button Text',stripslashes(theme_get_option('blog','read_more_text')));
			echo '</span>';
		?>
		</a>
		<?php }?>
<?php endif; ?>
		<div class="clear"></div>
	</div>
<?php elseif($featured_image_type == "full" && $has_image):?>
	<div class="post-title-slug">
		<?php echo theme_generator('blog_featured_image',$featured_image_type,$layout); ?>
		<div class="post-image-overlay">
			<div class="cont-vert">
				<div class="outer-vert">
					<div class="inner-vert">
						<h2 class="post-title-overimage vert-position">
							<a href="<?php echo get_permalink() ?>" rel="bookmark" title="<?php printf( __("Permanent Link to %s", THEME_FRONT_DOMAIN), get_the_title() ); ?>"><?php the_title(); ?></a>
						</h2>
					</div>
				</div>
			</div>
<?php if(in_array('comment',$meta_items)):?>
			<div class="post-comments-overimage">
				<div class="post-comments-bubble">
					<?php comments_popup_link(__('0',THEME_FRONT_DOMAIN), __('1',THEME_FRONT_DOMAIN), __('%',THEME_FRONT_DOMAIN),'',__('X',THEME_FRONT_DOMAIN));?>
				</div>
			</div>
<?php endif;?>
			<div class="clear"></div>
		</div>
	</div>
	<div class="post-content">
<?php 
	if($display_full):
		global $more;
		$more = 0;
		the_content(wpml_t(THEME_NAME, 'Blog Post Read More Button Text',stripslashes(theme_get_option('blog','read_more_text'))),false);
	else:
		the_excerpt();
		if($read_more){
		$is_button = theme_get_option('blog','read_more_button');
?>
		<a class="read_more_link <?php echo $is_button?'button medium white':'';  ?>" href="<?php the_permalink(); ?>">
			<?php

				echo '<span class="text" style="">';
				echo wpml_t(THEME_NAME, 'Blog Post Read More Button Text',stripslashes(theme_get_option('blog','read_more_text')));
				echo '</span>';

			?>
		</a>
		<?php }?>
<?php endif; ?>
		<div class="clear"></div>
	</div>
<?php if($display_meta && ( count($meta_items)>1 || (count($meta_items)==1 && !in_array('comment',$meta_items)))):?>
	<div class="post-bottoms">
		<div class="post-meta">
		<?php echo theme_generator('post_meta');// edit_post_link( __( 'Edit', THEME_FRONT_DOMAIN ), '<span class="sep">|</span> <span class="edit-link">', '</span>' ); ?>
		</div>
	</div>
<?php endif;?>
<?php elseif(($featured_image_type == "left"||$featured_image_type=='right') && $has_image):?>
	<div class="post-title-slug">
		<?php echo theme_generator('blog_featured_image',$featured_image_type,$layout); ?>
	</div>
	<div class="no-feature <?php echo in_array('comment',$meta_items)?'comment':'';?>">
	<div class="title-wrap">
		<h2 class="post-title-overimage vert-position">
			<a href="<?php echo get_permalink() ?>" rel="bookmark" title="<?php printf( __("Permanent Link to %s", THEME_FRONT_DOMAIN), get_the_title() ); ?>"><?php the_title(); ?></a>
		</h2>	
	</div>	
<?php if(in_array('comment',$meta_items)):?>
			<div class="post-comments-overimage">
				<div class="post-comments-bubble">
					<?php comments_popup_link(__('0',THEME_FRONT_DOMAIN), __('1',THEME_FRONT_DOMAIN), __('%',THEME_FRONT_DOMAIN),'',__('X',THEME_FRONT_DOMAIN));?>
				</div>
			</div>
<?php endif;?>
	<div class="clear"></div>
	</div>
<?php 
	if($display_full):
		global $more;
		$more = 0;
		the_content(wpml_t(THEME_NAME, 'Blog Post Read More Button Text',stripslashes(theme_get_option('blog','read_more_text'))),false);
	else:
		the_excerpt();
		if($read_more){
		$is_button = theme_get_option('blog','read_more_button');

?>
		<a class="read_more_link <?php echo $is_button?'button medium white':'';  ?>" href="<?php the_permalink(); ?>">
			<?php

				echo '<span class="text" style="">';
				echo wpml_t(THEME_NAME, 'Blog Post Read More Button Text',stripslashes(theme_get_option('blog','read_more_text')));
				echo '</span>';

			?>
		</a>
	<?php } ?>
	<?php endif;?>
	<div class="clear"></div>
	<?php if($display_meta && ( count($meta_items)>1 || (count($meta_items)==1 && !in_array('comment',$meta_items)))):?>
	<div class="post-bottoms">
		<div class="post-meta">
		<?php echo theme_generator('post_meta');?>
		</div>
	</div>
	<?php endif; ?>
<?php endif;?>
</article>
<?php endwhile;wp_reset_postdata();?>
<?php
	if(!empty($desc_length)){
		remove_filter( 'excerpt_length', array($excerpt_constructor,'get_length'));
	}
?>

