<?php
$layout = get_post_meta($post->ID, '_page_layout', true);
if(empty($layout) || $layout == 'default'){
	$layout=theme_get_option('portfolio','layout');
}
if(empty($layout) || $layout == 'default'){
	$layout=theme_get_option('general','layout');
}
$width = ($layout != 'full')?606:936;
$height = theme_get_option('portfolio', 'fixed_height');
$thumb = (int)$height*1/5;
?>
<?php  get_header(); ?>
<?php  
wp_print_scripts('jquery-gallery');
wp_print_styles('css-gallery');
?>
<script type="text/javascript">
jQuery(document).ready(function(){
	var galleries = jQuery('.ad-gallery').adGallery({
		loader_image:'<?php echo THEME_IMAGES;?>/classic-loader.gif',
		width:<?php echo $width;?>,
		height:<?php echo $height;?>,
	});
	jQuery('.ad-controls').hide();
});

</script>
<?php theme_generator('introduce',$post->ID);?>
<div id="content-area">
	<div class="wrap-center <?php if($layout=='right'):?>right_sidebar<?php endif;?><?php if($layout=='left'):?>left_sidebar<?php endif;?><?php if($layout=='full'):?>full_width<?php endif;?>">
	<div id="content" class="main">
		<?php echo theme_generator('breadcrumbs',$post->ID);?>
<?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
			<article id="post-<?php the_ID(); ?>" class="post">  
<?php  
$image_ids_str = get_post_meta(get_the_id(), '_image_ids', true);
$image_ids = array();
if(!empty($image_ids_str)){
	$image_ids = explode(',',str_replace('image-','',$image_ids_str));
}
?>
				<div id="gallery" class="ad-gallery">
					<div class="ad-image-wrapper"> </div>
					<div class="ad-controls" style="bottom:<?php echo $thumb+7;?>px"></div>

					<div class="ad-nav" style="bottom:1px;">
						<div class="ad-thumbs" style="width:<?php echo $width-30;?>px">

							<ul class="ad-thumb-list">
<?php
foreach($image_ids as $image_id){
	$resize1 = theme_resize($image_id,$width,$height,'form');
	$resize2 = theme_resize($image_id,$thumb,$thumb,'form');
	echo '<li>';
	echo '<a href="'.$resize1['url'].'">';
	echo '<img width="'.$resize2['width'].'" height="'.$resize2['height'].'" data-msg="'.$resize2['msg'].'" src="'.$resize2['url'].'"/>';
	echo '</a>';
	echo '</li>';
}
?>
							</ul>
						</div>

					</div>
				</div>

				<footer>
<?php 
if(theme_get_option('portfolio','single_navigation')):
?>
		<div class="pagenavi">
<?php add_filter('the_title','title_length');?>
			<div class='post-prev'>
<?php previous_post_link('%link','<img src="'.THEME_IMAGES.'/post-prev.png"/>%title');?>
			</div>
			<div class='post-next'>
<?php next_post_link('%link','%title<img src="'.THEME_IMAGES.'/post-next.png">');?>
			</div>
		</div>
<?php endif; ?>
				</footer>
				<div class="clear"></div>
<?php if(theme_get_option('blog','author')){
	theme_generator('author_box');		
}
?>
<?php if(theme_get_option('portfolio','related_recent')):?>
				<div class="related_popular_wrap">
					<div class="one_half">
						<?php echo theme_generator('portfolio_recent_posts');?>
					</div>
					<div class="one_half last">
						<?php echo theme_generator('portfolio_related_posts');?>
					</div>
					<div class="clear"></div>
				</div>
<?php endif;?>
			</article>

<?php if(theme_get_option('portfolio','enable_comment')) comments_template( '', true ); ?>
<?php endwhile; // end of the loop.?>
		</div>
		<?php if($layout != 'full') get_sidebar(); ?>
		<div class="clear"></div>
	</div>
</div>
<?php get_footer(); ?>

