function widget($args, $instance)
    {
        $cache = wp_cache_get('theme_widget_related_posts', 'widget');
        if (!is_array($cache)) {
            $cache = array();
        }
        if (isset($cache[$args['widget_id']])) {
            echo $cache[$args['widget_id']];
            return;
        }
        ob_start();
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? __('Related Posts', 'adelante') : $instance['title'], $instance, $this->id_base);
        if (!($number = (int) $instance['number'])) {
            $number = 10;
        } else {
            if ($number < 1) {
                $number = 1;
            } else {
                if ($number > 15) {
                    $number = 15;
                }
            }
        }
        if (!($desc_length = (int) $instance['desc_length'])) {
            $desc_length = 80;
        } else {
            if ($desc_length < 1) {
                $desc_length = 1;
            }
        }
        $disable_thumbnail = $instance['disable_thumbnail'] ? '1' : '0';
        $display_extra_type = $instance['display_extra_type'] ? $instance['display_extra_type'] : 'time';
        global $post;
        $tags = wp_get_post_tags($post->ID);
        $tagIDs = array();
        if ($tags) {
            $tagcount = count($tags);
            for ($i = 0; $i < $tagcount; $i++) {
                $tagIDs[$i] = $tags[$i]->term_id;
            }
            $query = array('tag__in' => $tagIDs, 'post__not_in' => array($post->ID), 'showposts' => $number, 'nopaging' => 0, 'post_status' => 'publish', 'caller_get_posts' => 1);
            if (!empty($instance['cat'])) {
                $query['cat'] = implode(',', $instance['cat']);
            }
            $r = new WP_Query($query);
            if ($r->have_posts()) {
                ?>
		<?php 
                echo $before_widget;
                ?>
		<?php 
                if ($title) {
                    echo $before_title . $title . $after_title;
                }
                ?>
		<ul class="posts_list">
<?php 
                while ($r->have_posts()) {
                    $r->the_post();
                    ?>
			<li>
<?php 
                    if (!$disable_thumbnail) {
                        ?>
            <figure class="widget-related-img">
                <a class="thumbnail" href="<?php 
                        echo get_permalink();
                        ?>
" title="<?php 
                        the_title();
                        ?>
">
                    <?php 
                        if (has_post_thumbnail()) {
                            ?>
                    
                        <?php 
                            $thumb = get_post_thumbnail_id($r->post->ID);
                            $image = wp_get_attachment_image_src($thumb, 'full');
                            ?>
                        <img src="<?php 
                            echo adelante_image_resize(65, 65, "http://" . $_SERVER['SERVER_NAME'] . $image[0]);
                            ?>
" alt="<?php 
                            the_title();
                            ?>
" title="<?php 
                            the_title();
                            ?>
" />        
                    <?php 
                        } else {
                            ?>
                        <img src="<?php 
                            echo adelante_image_resize(65, 65, ADELANTE_BASE_URI . "/img/empty_thumb.png");
                            ?>
" alt="<?php 
                            the_title();
                            ?>
" title="<?php 
                            the_title();
                            ?>
" />
                    <?php 
                        }
                        ?>
                   
                </a>
                <?php 
                        adelante_image_border(null, 3, 0.1);
                        ?>
             </figure>
<?php 
                    }
                    //disable_thumbnail
                    ?>
				<div class="post_extra_info">
					<a href="<?php 
                    the_permalink();
                    ?>
" rel="bookmark" title="<?php 
                    echo esc_attr(get_the_title() ? get_the_title() : get_the_ID());
                    ?>
"><?php 
                    if (get_the_title()) {
                        the_title();
                    } else {
                        the_ID();
                    }
                    ?>
</a>
<?php 
                    if ($display_extra_type == 'time') {
                        ?>
					<time datetime="<?php 
                        the_time('Y-m-d');
                        ?>
"><?php 
                        echo get_the_date();
                        ?>
</time>
<?php 
                    } else {
                        ?>
					<p><?php 
                        echo wp_html_excerpt(get_the_excerpt(), $desc_length);
                        ?>
...</p>
<?php 
                    }
                    //end display extra type
                    ?>
				</div>
				<div class="clearboth"></div>
			</li>
<?php 
                }
                ?>
		</ul>
		<?php 
                echo $after_widget;
                // Reset the global $the_post as this query will have stomped on it
                wp_reset_query();
            }
            $cache[$args['widget_id']] = ob_get_flush();
            wp_cache_set('theme_widget_related_posts', $cache, 'widget');
        }
    }
    function widget($args, $instance)
    {
        extract($args);
        $title = apply_filters('widget_title', empty($instance['title']) ? 'Photos on Picasa' : $instance['title'], $instance, $this->id_base);
        $username = $instance['username'];
        $columns = $instance['columns'];
        $items = $instance['items'];
        $width = $instance['width'];
        if (!empty($username)) {
            echo $before_widget;
            if ($title) {
                echo $before_title . $title . $after_title;
            }
            if (file_exists(ABSPATH . WPINC . '/rss.php')) {
                require_once ABSPATH . WPINC . '/rss.php';
            } else {
                require_once ABSPATH . WPINC . '/rss-functions.php';
            }
            $output = "<div class=picasa_wrap align=center>";
            $rss = fetch_rss("http://picasaweb.google.com/data/feed/base/user/{$username}?kind=album&alt=rss&hl=en_US&access=public&max-results={$items}");
            if (is_array($rss->items)) {
                $i = 0;
                $album = rand(0, sizeof($rss->items) - 1);
                foreach ($rss->items as $item) {
                    $title = $item['title'];
                    $title = str_replace("'", "", $title);
                    $title = str_replace('"', "", $title);
                    $link = $item['link'];
                    preg_match('/.*src="(.*?)".*/', $item['description'], $sub);
                    $path = $sub[1];
                    $path = str_replace("s160-", "s{$width}-", $path);
                    if ($i == $album) {
                        $rss2 = fetch_rss(str_replace("entry", "feed", $item['guid']) . "&kind=photo");
                        if (!$rss2) {
                            continue;
                        }
                        $j = 0;
                        foreach ($rss2->items as $item2) {
                            $title = $item2['title'];
                            $title = str_replace("'", "", $title);
                            $title = str_replace('"', "", $title);
                            preg_match('/.*src="(.*?)".*/', $item2['description'], $sub);
                            $path = $sub[1];
                            $path = str_replace("s288", "s{$width}-c", $path);
                            $array[$j++] = "<figure class='picasa-widget-img'><a href=" . $item2['link'] . " target=_blank>" . adelante_image_border("<img src=" . $path . " alt='{$title}' title='{$title}'>", 3, 0.1) . "</a></figure>";
                        }
                        srand((double) microtime() * 1000000);
                        shuffle($array);
                        for ($k = 0; $k < $items; $k++) {
                            $output .= $array[$k];
                            if ($items != 1) {
                                if (($k + 1) % $columns == 0) {
                                    $output .= "<div class=\"clearboth\"></div>";
                                } else {
                                    $output .= "";
                                }
                            } else {
                                $output .= "<div class=\"clearboth\"></div>";
                            }
                        }
                    }
                    $i++;
                }
            }
            echo "{$output}</div>" . $after_widget;
            ?>
		    <div class="clearboth"></div>
		<?php 
        }
    }
function adelante_posts_slider($width = 960)
{
    global $post;
    $i = 1;
    $height = get_option('adelante_slider_height');
    // Check what post types to include in slider
    $post_types = adelante_get_post_types(false, false);
    foreach ($post_types as $post_type) {
        $inc = get_option('adelante_slider_' . $post_type);
        if ($inc == 'checked') {
            $types[] = $post_type;
        }
    }
    adelante_buffer_start();
    // Start outputting
    echo '<ul>';
    $args = array('post_type' => $types);
    $ppp = get_option('adelante_slider_post_count');
    if ($ppp > 0) {
        $args['posts_per_page'] = $ppp;
    }
    query_posts($args);
    if (have_posts()) {
        while (have_posts()) {
            the_post();
            $thumbnail = wp_get_attachment_image_src(get_post_thumbnail_id(), 'large');
            ?>
            <li id="slide-<?php 
            echo $i++;
            ?>
" class="slide clearboth">
                <div class="thumb clearfix">
                    <a href="<?php 
            the_permalink();
            ?>
">
                        <?php 
            if (!empty($thumbnail[0])) {
                ?>
                            <figure class="gallery-item aligncenter"><img class="featured_image post" src="<?php 
                echo adelante_image_resize($height - 21, $width - 410, $thumbnail[0]);
                ?>
" alt="<?php 
                the_title();
                ?>
" /><?php 
                adelante_image_border(null, 10, 0.05);
                ?>
</figure>
                        <?php 
            } else {
                ?>
                            <figure class="gallery-item aligncenter"><img class="featured_image post" src="<?php 
                echo adelante_image_resize($height - 21, $width - 410, get_template_directory_uri() . "/img/placeholder.png");
                ?>
" alt="placeholder" /></figure>
                        <?php 
            }
            ?>
                    </a>
                    <div class="postsnip">
                        <h2><a href="<?php 
            the_permalink();
            ?>
"><?php 
            echo $post->post_title;
            ?>
</a></h2>
                        <?php 
            the_excerpt();
            ?>
                        <p></p><div class="clearboth"></div>
                        <a class="adelante-button white" href="<?php 
            the_permalink();
            ?>
" title="<?php 
            the_title();
            ?>
">Read More...</a>
                    </div>
                </div>
               
            </li>            
        <?php 
        }
    } else {
        $output .= '<figure class="gallery-item aligncenter"><a href="' . site_url() . '/wp-admin/post-new.php?post_type=slider"><img class="post" src="' . adelante_image_resize($height - 21, $width - 410, get_template_directory_uri() . "/img/placeholder.png") . '" alt="placeholder" title="Please add items to your slider by clicking on this slide" /></a></figure>';
    }
    echo '</ul>';
    wp_reset_query();
    $output = ob_get_contents();
    adelante_buffer_end();
    return $output;
}