<?php get_header(); ?>

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

<?php if( $layout_build == 'widgets' ) { ?>

<div id="content" class="variantone">

<?php if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar( 'Home Page' ) ) : ?>

<div class="widget">
    <h2 class="widgettitle">Widget reserved area!</h2>
        <div class="textwidget">
        You opted for Widgets home page layout. It means that you can add as many Widgets as you like in this area. All of them will be arranged in grid-like form. So far no Widgets found. If you like to add some, refer to Admin section of your site and select Appearance > Widgets. Look up for 'Home Page' named panel (left hand sidebar), expand it and drag-drop available widgets from left.
        </div>
</div>

<script language="javascript" type="text/javascript">
// add clear after each third widget block
	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 ++;
	}
</script>

<?php endif; ?>

</div>

<?php 
} else if( $layout_build == 'grid' || $layout_build == 'gridandsidebar' ) { 
	$switch_class = 'class="variantone"';
	if( $layout_build == 'grid' ) $switch_class = 'class="varianttwo"';
	$temp_store_query = $wp_query;
	$wp_query = NULL;
	$wp_query = new WP_Query( 'paged=' . $paged );
?>

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

<?php if ( !function_exists( 'dynamic_sidebar' ) || !dynamic_sidebar( 'Home Page' ) ) : ?>
<?php endif; ?>

<?php if( !$wp_query->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; ?>
<?php
$count_postz = 0; 
while( $wp_query->have_posts() ) : $wp_query->the_post(); 

	$the_cat_name_array = get_the_category($post->ID); 
	$the_cat_name = $the_cat_name_array[0]->name; 

		if ($the_cat_name == 'News') {
			
		}else{
?>
<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" class="prodimglink"><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></p>';
				}
			
			
			?>
		</div>
	</div>
 <?php } ?>
<?php endwhile; ?>

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

<?php if( $layout_build == '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 if( $layout_build == 'gridandsidebar' ) { ?>

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(); }
	$wp_query = NULL; 
	$wp_query = $temp_store_query;
}
?>

</div>

<?php } ?>

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

<?php get_footer(); ?>

