<?php get_header(); ?>

<?php
$aOptions = SofaShoppr::initOptions( false );
$trimexcerpt = ( strlen( $aOptions[ 'trimexcerpt' ] ) > 0 ) ? stripslashes( $aOptions[ 'trimexcerpt' ] ) : 0;
$layout_build_category = $aOptions[ 'layout_build_category' ];
$entrycurrency = $aOptions[ 'entrycurrency' ];
?>

<?php 
$switch_class = 'class="variantone"';
if( $layout_build_category == 'grid' ) $switch_class = 'class="varianttwo"';
?>

<div id="content" <?php echo $switch_class; ?>>

<?php if( !have_posts() ) : ?>

	<div class="widget">
		<h2 class="widgettitle"><?php _e( "Ups!", "sofa_shoppr" ); ?></h2>
		<div class="textwidget">
			<?php _e( "Unfortunately, no posts found.", "sofa_shoppr" ); ?>
		</div>
	</div>
    
<?php 
endif;

echo '<h1 class="onetwoh1">' . __( "Tagged with:", "sofa_shoppr" ) . ' <i>';
single_tag_title();
echo '</i></h1>';

while( have_posts() ) : the_post(); ?>

	<div class="widget" id="post-<?php the_ID(); ?>">
		<div class="textwidget">
            <?php 
			$required_file_path = '';
			$arrFiles =& get_children( 'post_type=attachment&post_mime_type=image&orderby=menu_order&order=ASC&post_parent=' . $post->ID );
			$arrKeys  = array_keys( $arrFiles );
			if( $arrKeys[ 0 ] ) {
				$medium_array = image_downsize( $arrKeys[ 0 ], 'medium' );
				$required_file_path = $medium_array[ 0 ];
			}
			
			if( $required_file_path != '' && $required_file_path != NULL ) {
				echo '<p><a href="' . get_permalink( $post->ID ) . '" rel="nofollow"><img src="' . $required_file_path . '" class="productimage" alt="' . get_the_title() . '" /></a></p>';
			} else echo '<p style="width: 274px; height: 274px; text-align: center;">' . __( "Product image is missing.", "sofa_shoppr" ) . '</p>';
			
			if( get_post_meta( $post->ID, 'price', true ) ) {
				$price = number_format( get_post_meta( $post->ID, 'price', true ), 2, '.', ',' );
				echo '<p class="producttitle"><a href="' . get_permalink( $post->ID ) . '" title="' . get_the_title() . '">' . get_the_title() . '</a></p>';
				echo '<p class="pricebuy">';
				echo '<span class="money">' . $entrycurrency . ' ' . $price . '</span>';
				echo '<span class="pricetag"><a href="' . get_bloginfo( 'template_directory' ) . '/add_item_screen.php?itemid=' . $post->ID . '" class="nyroModal">' . __( "BUY NOW", "sofa_shoppr" ) . '</a></span>';
				echo '</p>';
			}
			?>
		</div>
	</div>
    
<?php endwhile; ?>

<script language="javascript" type="text/javascript">

<?php if( $layout_build_category == 'grid' ) { ?>

jQuery( document ).ready( function() {
	var count_widgets = 0;
	var target_element = jQuery( '#content .widget' );
	var element_count = target_element.length;
	while( count_widgets < element_count ) {
		if( count_widgets % 3 == 0 ) jQuery( target_element[ count_widgets - 1 ] ).after( '<div class="clearmate">&nbsp;</div>' );
		count_widgets ++;
	}
	/*
	// save this for the future, IE doesn't have a clue about
	jQuery( '#content .widget:nth-child(3n)' ).each( function( e ) {
		jQuery( this ).after( '<div class="clearmate">&nbsp;</div>' );
	} );
	*/
} );

<?php } else { ?>

jQuery( document ).ready( function() {
	var count_widgets = 0;
	var target_element = jQuery( '#content .widget' );
	var element_count = target_element.length;
	while( count_widgets < element_count ) {
		if( count_widgets % 2 == 0 && count_widgets > 0 ) jQuery( target_element[ count_widgets - 1 ] ).after( '<div class="clearmate">&nbsp;</div>' );
		count_widgets ++;
	}
	/*
	jQuery( '#content .widget:nth-child(2n)' ).each( function( e ) {
		jQuery( this ).after( '<div class="clearmate">&nbsp;</div>' );
	} );
	*/
} );

<?php } ?>

</script>

<?php 
if( $wp_query->max_num_pages > 1 ) {
	// paging
	include( 'wp-pagenavi.php' );
	if( function_exists( 'wp_pagenavi' ) ) { wp_pagenavi(); }
}
?>

</div>

<?php if( $layout_build_category == 'gridandsidebar' ) include( TEMPLATEPATH . '/sidebar_search.php' ); ?>

<?php get_footer(); ?>