<?php get_header(); ?>
<div id="mainbody">
    <?php if ( is_search() ) {  ?>
    <div class="mainsearch">Search Status: "<?php echo $s; ?>"</div>
    <?php } else { ?>
    <div class="featured">
    <?php include (TEMPLATEPATH . '/gallery.php'); ?>
    </div>
    <?php $my_query = new WP_Query('showposts=1'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>
    <div class="maincontent">
    
    <div class="mainleft">
        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
        <img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php getImage('1'); ?>&h=170&w=150" />
        </a>
    </div>
    <div class="mainright">
        <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
        <div class="submain"><?php the_author() ?> | <?php the_category(' / '); ?> | <?php the_time('F, d Y') ?> | <?php comments_popup_link('No Comment', '1 Comment', '% Comments'); ?></div>
        <?php the_excerpt(); ?>
        <div class="more"><a href="<?php the_permalink() ?>"><img src="<?php bloginfo('template_directory'); echo '/images/read-more.png'; ?>" /></a></div>
    </div>
    <div class="clear"></div>
    </div>
    <div class="clear"></div>
    <?php endwhile; ?>
    <div class="maincenter">
        <div class="mainpopular">
            <img src="<?php bloginfo('template_directory'); echo '/images/popular-post.png'; ?>" class="title" />
            <ul>
                <?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
                foreach ($result as $post) {
                setup_postdata($post);
                $postid = $post->ID;
                $title = $post->post_title;
                $commentcount = $post->comment_count;
    
                if ($commentcount != 0) { ?>
                <li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>">
                <?php echo $title ?></a></li>
                <?php } } ?>
            </ul>
        </div>
        <div class="clear"></div>
    </div>
    <div class="clear"></div>
    <?php } if (have_posts()) : while (have_posts()) : the_post(); if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
    <div class="maincontent">
    <div class="mainleft">
        <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
        <img src="<?php bloginfo('template_directory'); ?>/timthumb.php?src=<?php getImage('1'); ?>&h=170&w=150" />
        </a>
    </div>
    <div class="mainright">
        <h1><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h1>
        <div class="submain"><?php the_author() ?> | <?php the_category(' / '); ?> | <?php the_time('F, d Y') ?> | <?php comments_popup_link('No Comment', '1 Comment', '% Comments'); ?></div>
        <?php the_excerpt(); ?>
        <div class="more"><a href="<?php the_permalink() ?>"><img src="<?php bloginfo('template_directory'); echo '/images/read-more.png'; ?>" /></a></div>
    </div>
    <div class="clear"></div>
    </div>
    <?php endwhile; include (TEMPLATEPATH . '/paginate.php'); else : include (TEMPLATEPATH . '/404.php'); endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>