<?php
/**
 * @package WordPress
 * @subpackage Classic_Theme
 */
?>
<!-- begin sidebar -->
<div id="sidebar">
	<div class="tool-wrap">
		<div id="sidebar-search"><div id="search-wrap" class="clearfix">
			<form method="get" action="<?php bloginfo('url'); ?>">
				<input name="s" type="text" class="search-text" id="s" value="Search"  onblur="if (this.value == '')  {this.value = '<?php echo $searchform_text; ?>';}" onfocus="if (this.value == '<?php echo $searchform_text; ?>') {this.value = '';}" />
				<input type="image" src="<?php bloginfo('stylesheet_directory'); ?>/images/function_bg.gif" id="search-submit" alt="Search" value="" title="search_button" />
			</form>
		</div></div>
		<div class="ad-wrap">
		<div class="socialbox">
			<div class="custom_images">
				<a class="addthis_button_delicious"><img src="<?php bloginfo('template_directory'); ?>/images/socialbookmark/delicious.png" /></a>
				<a class="addthis_button_facebook"><img src="<?php bloginfo('template_directory'); ?>/images/socialbookmark/facebook.png" /></a>
				<a class="addthis_button_digg"><img src="<?php bloginfo('template_directory'); ?>/images/socialbookmark/digg.png" /></a>
				<a class="addthis_button_stumbleupon"><img src="<?php bloginfo('template_directory'); ?>/images/socialbookmark/stumbleupon.png" /></a>
				<a class="addthis_button_twitter"><img src="<?php bloginfo('template_directory'); ?>/images/socialbookmark/twitter.png" /></a>
				<a href="<?php bloginfo('rss2_url'); ?>"><img src="<?php bloginfo('template_directory'); ?>/images/socialbookmark/feed.png" /></a>
				<a href="addthis_button_more"><img src="<?php bloginfo('template_directory'); ?>/images/socialbookmark/more.png" /></a>
			</div>
			<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js?pub=xa-4a65e1d93cd75e94"></script>
			</div>
			<?php if(wpthemes_options('ad125_location1') != '' || wpthemes_options('ad125_location2') != '' || wpthemes_options('ad125_location3') != '' || wpthemes_options('ad125_location4') != '' || wpthemes_options('ad125_location5') != '' || wpthemes_options('ad125_location6') != '' || wpthemes_options('ad125_location7') != '' || wpthemes_options('ad125_location8') != '') { ?>
			<div class="sidebarad-wrap">
				<?php if(wpthemes_options('ad125_location1') != '') { ?>
						<a href="<?php echo wpthemes_options('ad125_url1'); ?>"><img src="<?php echo wpthemes_options('ad125_location1'); ?>" /></a>
				<?php } ?>
				<?php if(wpthemes_options('ad125_location2') != '') { ?>
						<a href="<?php echo wpthemes_options('ad125_url2'); ?>"><img src="<?php echo wpthemes_options('ad125_location2'); ?>" /></a>
				<?php } ?>
				<?php if(wpthemes_options('ad125_location3') != '') { ?>
						<a href="<?php echo wpthemes_options('ad125_url3'); ?>"><img src="<?php echo wpthemes_options('ad125_location3'); ?>" /></a>
				<?php } ?>
				<?php if(wpthemes_options('ad125_location4') != '') { ?>
						<a href="<?php echo wpthemes_options('ad125_url4'); ?>"><img src="<?php echo wpthemes_options('ad125_location4'); ?>" /></a>
				<?php } ?>
				<?php if(wpthemes_options('ad125_location5') != '') { ?>
						<a href="<?php echo wpthemes_options('ad125_url5'); ?>"><img src="<?php echo wpthemes_options('ad125_location5'); ?>" /></a>
				<?php } ?>
				<?php if(wpthemes_options('ad125_location6') != '') { ?>
						<a href="<?php echo wpthemes_options('ad125_url6'); ?>"><img src="<?php echo wpthemes_options('ad125_location6'); ?>" /></a>
				<?php } ?>
				<?php if(wpthemes_options('ad125_location7') != '') { ?>
						<a href="<?php echo wpthemes_options('ad125_url7'); ?>"><img src="<?php echo wpthemes_options('ad125_location7'); ?>" /></a>
				<?php } ?>
				<?php if(wpthemes_options('ad125_location8') != '') { ?>
						<a href="<?php echo wpthemes_options('ad125_url8'); ?>"><img src="<?php echo wpthemes_options('ad125_location8'); ?>" /></a>
				<?php } ?>
			</div>
		<?php } ?>
	</div></div>

	<ul>
	<?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Sidebar') ) : ?>
		<li>
            <h2>Links List</h2>
            <ul class="blogroll">
                <?php wp_list_bookmarks("title_li=&categorize=0"); ?>
            </ul>
        </li>
		<li class="popular-posts sidebar-photo">
			<h2>Most Popular Posts</h2>
				<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY comment_count DESC LIMIT 0 , 3");
				foreach ($result as $topten) { $postid = $topten->ID; $title = $topten->post_title; $commentcount = $topten->comment_count; 
				if ( has_post_thumbnail($postid)) {
				setup_postdata($post);
				if ( version_compare( $wp_version, '2.9', '>=' ) ) {
				$gallery_img = get_the_post_thumbnail($postid,'large', array('class' => 'full thumbnail'));
				$gallery_thumb_img = get_the_post_thumbnail($postid,array(70,40));
				} else {                         
				$gallery_img_src = get_post_meta($postid, 'featured', true);
				$gallery_img = '<img src="$gallery_img_src" class="thumbnail" />';
				}
				} else {
				$gallery_img = '<img src="'.get_bloginfo('template_url').'/images/no_image.gif" class="thumbnail" />';
				}
				if ($commentcount != 0) { ?>
				<div class="entry clearfix">
					<a href="<?php the_permalink() ?>"><?php echo $gallery_img; ?></a>
					<h3 class="posts-title"><a href="<?php echo get_permalink($postid); ?>"><?php echo csubstr($title, 60); ?></a></h3>
					<span class="date"><?php the_time(wpthemes_options('date_format')); ?></span>
				</div>
				<?php } } ?>
		</li>
		<li>
			<h2>Most Commented Posts</h2>
            <ul>
                <?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts WHERE post_status = 'publish' ORDER BY comment_count DESC LIMIT 0 , 5");
                foreach ($result as $topten) { $postid = $topten->ID; $title = $topten->post_title; $commentcount = $topten->comment_count; 
                if ($commentcount != 0) { ?>
                    <li>
                        <a href="<?php echo get_permalink($postid); ?>"><?php echo $title; ?></a>
                    </li>
            <?php } } ?>
            </ul>
        </li>
		<li><h2>Popular Tags</h2>
			<div><?php wp_tag_cloud('largest=16&format=flat&number=60'); ?></div>
		</li>
		<li>
			<h2>From Flickr</h2>
			  <div class="flickr">
				<div class="flickr_badge_wrapper">
			  <script type="text/javascript" src="http://www.flickr.com/badge_code_v2.gne?show_name=1&count=9&display=latest&size=s&layout=v&source=user&user=<?php echo wpthemes_options('flickr_account');?>"></script>
				</div>
			  </div>
		</li>

	<?php endif; ?>
	</ul>
</div>