<div id="sidebar">

  <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar() ) : ?>

    <?php /* Menu for subpages of current page (copied from K2 theme) */
    global $notfound;
    if (is_page() and ($notfound != '1')) {
        $current_page = $post->ID;
        while($current_page) {
            $page_query = $wpdb->get_row("SELECT ID, post_title, post_status, post_parent FROM $wpdb->posts WHERE ID = '$current_page'");
            $current_page = $page_query->post_parent;
        }
        $parent_id = $page_query->ID;
        $parent_title = $page_query->post_title;

        // if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_status != 'attachment'")) {
        if ($wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = '$parent_id' AND post_type != 'attachment'")) {
    ?>
    <?php } } ?>

  <?php endif; ?>

 <ul class="idTabs"> 
  <li><a href="#recent-comments" class="tab" title="Recent comments"><img src="<?php bloginfo('template_directory'); ?>/images/recent-comments-icon.png" alt="Recent comments" /></a></li> 
  <li><a href="#categories" class="tab" title="Categories"><img src="<?php bloginfo('template_directory'); ?>/images/categories-icon.png" alt="Categories" /></a></li>
  <li><a href="#archives" class="tab" title="Archives"><img src="<?php bloginfo('template_directory'); ?>/images/archives-icon.png" alt="Archives" /></a></li>
  <li><a href="#links" class="tab" title="Links"><img src="<?php bloginfo('template_directory'); ?>/images/links-icon.png" alt="Links" /></a></li> 
</ul> 
<div id="recent-comments">
	<div class="tabs-header"></div>
    <div class="tabs-content">
		<?php include (TEMPLATEPATH . '/simple_recent_comments.php'); /* recent comments plugin by: www.g-loaded.eu */?>
        <?php if (function_exists('src_simple_recent_comments')) { src_simple_recent_comments(6, 60, ''); } ?>
    </div>
    <div class="tabs-bottom"></div>
</div>
<div id="categories">
	<div class="tabs-header"></div>
    <div class="tabs-content">
        <ul class="list-cat">
            <?php wp_list_cats('sort_column=name&optioncount=1&hierarchical=0'); ?>
        </ul>
    </div>
    <div class="tabs-bottom"></div>
</div>
<div id="archives">
	<div class="tabs-header"></div>
    <div class="tabs-content">
        <ul class="list-archives">
            <?php wp_get_archives('type=monthly'); ?>
        </ul>
    </div>
    <div class="tabs-bottom"></div>
</div> 
<div id="links">
	<div class="tabs-header"></div>
    <div class="tabs-content">
        <ul class="list-blogroll">
            <?php get_links('-1', '<li>', '</li>', '<br />', FALSE, 'id', FALSE, FALSE, -1, FALSE); ?>
        </ul>
    </div>
    <div class="tabs-bottom"></div>
</div>

<?php // Get RSS Feed(s)


include_once(ABSPATH . WPINC . '/feed.php');
include_once(TEMPLATEPATH . '/scripts/flickr.php');

$rss = fetch_feed('http://api.flickr.com/services/feeds/groups_pool.gne?id=12044148@N00&lang=en-us&format=rss_200');
$thumb = 'square';
$full = 'medium';

// Figure out how many total items there are, but limit it to 5. 
$maxitems = $rss->get_item_quantity(6); 

// Build an array of all the items, starting with element 0 (first element).
$rss_items = $rss->get_items(0, $maxitems); 
?>
<div id="flickr">
	<div class="tabs-header"></div>
    <div class="tabs-content">
    <h3>Flickr photos</h3>
<?php if ($maxitems == 0) echo '<li>No items.</li>';
else

// Loop through each feed item and display each item as a hyperlink.
foreach ( $rss_items as $item ):
  $url = flickr::find_photo($item->get_description());
  $title = flickr::cleanup($item->get_title());
  $full_url = flickr::photo($url, $full);
  $thumb_url = flickr::photo($url, $thumb);
?>

    <a href="<?php echo $item->get_permalink(); ?>" class="flickr-thumb" title="<?php echo $item->get_title(); ?>"><img src="<?php echo $thumb_url; ?>" alt="<?php echo $item->get_title(); ?>" /></a> 
    <?php endforeach; ?>
    </div>
    <div class="tabs-bottom"></div>
</div>

</div>
<!--/sidebar -->