<ul class="relatived-products">
    <?php
    $i=1;
    foreach(get_the_category() as $category){
    $cat = $category->cat_ID;
    }
    query_posts('cat=' . $cat . '&orderby=rand&showposts=5');
    while (have_posts()) : the_post();
    //$output = preg_match('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
    //$imgnum = count($matches);
    $thumb_f = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'full' ); $url_f = $thumb_f['0'];
    ?>
    <?php if ($i % 5 == 0) : ?>
    <li style="margin-right:0;">
    <?php if ( $url_f ) {  ?>
    <a class="same_cat_posts_img" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo '<img alt="'. the_title() .'" src="'.get_bloginfo('template_url').'/timthumb.php?src='.$url_f.'&amp;w=100&amp;h=100&amp;zc=1" />';?>
    <?php the_title(); ?>
    </a>
    <?php } else {  ?>
    <a class="same_cat_posts_img" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img alt="<?php the_title(); ?>" src="<?php bloginfo('template_url'); ?>/timthumb.php?src=/images/default-100.png&amp;w=100&amp;h=100&amp;zc=1" />
    <?php the_title(); ?>
    </a>
    <?php } ?>
    </li>
    <?php $i ++; else : ?>
    <li>
    <?php if ( $url_f ) {  ?>
    <a class="same_cat_posts_img" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php echo '<img src="'.get_bloginfo('template_url').'/timthumb.php?src='.$url_f.'&amp;w=100&amp;h=100&amp;zc=1" />';?>
    <?php the_title(); ?>
    </a>
    <?php } else {  ?>
    <a class="same_cat_posts_img" href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><img alt="<?php the_title(); ?>" src="<?php bloginfo('template_url'); ?>/timthumb.php?src=/images/default-100.png&amp;w=100&amp;h=100&amp;zc=1" />
    <?php the_title(); ?>
    </a>
    <?php } ?>
    </li>
    <?php $i ++; endif; ?>
    <?php endwhile; wp_reset_query(); ?>
    <div class="clear"></div>
    </ul>