<?php
/**
 * @package Greyzed
 */

get_header(); ?>
<div id="container">
<?php get_sidebar(); ?>
	<div id="content" role="main">
	<div class="column">

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

		<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
			<div class="posttitle">
				<h2 class="pagetitle">
					<?php if ( $post->post_parent ) { ?>
						<a href="<?php echo esc_url( get_permalink( $post->post_parent ) ); ?>" rev="attachment"><?php echo esc_html( get_the_title($post->post_parent) ); ?></a> &raquo; <?php } ?>
					<?php the_title(); ?></h2>

				<small>
					<?php
					if ( is_multi_author() ) {
						printf( __( 'Posted: %1$s by <strong>%2$s</strong>', 'greyzed' ),
							esc_html( get_the_date( get_option( 'date_format' ) ) ),
							esc_html( get_the_author() )
						);
					} else {
						printf( __( 'Posted: %1$s', 'greyzed' ),
							esc_html( get_the_date( get_option( 'date_format' ) ) )
						);
					}
					?>
					<span class="meta-sep">|</span>
					<?php $metadata = wp_get_attachment_metadata();
					printf( __( 'Full size is %s pixels', 'greyzed'),
						sprintf( '<a href="%1$s" title="%2$s">%3$s &times; %4$s</a>',
							esc_url( wp_get_attachment_url() ),
							esc_attr( __('Link to full-size image', 'greyzed') ),
							esc_html( $metadata['width'] ),
							esc_html( $metadata['height'] )
						)
					); ?>
					<?php edit_post_link( 'Edit this entry.', ' <span class="meta-sep">|</span> ', '' ); ?>
					<br/>
				</small>
			</div>
			<?php if ( ( comments_open() ) && ( ! post_password_required() ) ) : ?>
				<div class="postcomments"><?php comments_popup_link( '0', '1', '%' ); ?></div>
			<?php endif; ?>
			<div class="entry">
<?php
$next_attachment_url = wp_get_attachment_url();
if ( $post->post_parent ) {
	$attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) );
	foreach ( $attachments as $k => $attachment ) {
		if ( $attachment->ID == $post->ID )
			break;
	}
	$k++;
	if ( isset( $attachments[ $k ] ) )
		$next_attachment_url = get_attachment_link( $attachments[ $k ]->ID );
	else
		$next_attachment_url = get_permalink( $post->post_parent );
}
?>
				<p class="attachment">
					<a href="<?php echo esc_url( $next_attachment_url ); ?>">
						<?php echo wp_get_attachment_image( $post->ID, array( 648, 9999 ) ); ?>
					</a>
				</p>

				<div class="caption">
					<?php if ( !empty($post->post_excerpt) ) the_excerpt(); // this is the "caption" ?>
				</div>

				<?php the_content('<p class="serif">Read the rest of this entry &raquo;</p>'); ?>

				<?php if ( $post->post_parent ) { ?>
					<div class="navigation">
						<div class="alignleft leftnav"><?php previous_image_link( false, __( 'Previous image', 'greyzed' ) ) ?></div>
						<div class="alignright rightnav"><?php next_image_link( false, __( 'Next image', 'greyzed' ) ) ?></div>
					</div>
				<?php } ?>

				<br class="clear" />

				<p class="postmetadata alt">
					<small>
						<?php if ( comments_open() && pings_open() ) {
							// Both Comments and Pings are open ?>
							<?php printf( __( 'You can <a href="#respond">leave a response</a>, or <a href="%s" rel="trackback">trackback</a> from your own site.', 'greyzed' ), trackback_url( false ) ); ?>

						<?php } elseif ( ! comments_open() && pings_open() ) {
							// Only Pings are Open ?>
							<?php printf( __( 'Responses are currently closed, but you can <a href="%s" rel="trackback">trackback</a> from your own site.', 'greyzed' ), trackback_url( false ) ); ?>

						<?php } elseif ( comments_open() && ! pings_open() ) {
							// Comments are open, Pings are not ?>
							<?php _e( 'You can skip to the end and leave a response. Pinging is currently not allowed.', 'greyzed' ); ?>

						<?php } elseif ( ! comments_open() && !pings_open() ) {
							// Neither Comments, nor Pings are open ?>
							<?php _e( 'Both comments and pings are currently closed.', 'greyzed' ); ?>

						<?php } ?>
					</small>
				</p>
			</div>
		</div>

	<?php comments_template(); ?>

	<?php endwhile; else: ?>

		<p><?php _e( 'Sorry, no images matched your criteria.', 'greyzed' ); ?></p>

	<?php endif; ?>

	</div>
</div>

<?php get_footer(); ?>