<?php
if(wpthemes_options('top_gallery_posts') != '') {
?>
<div class="feature-slider"><div class="feature-slider-top"><div class="feature-slider-bottom">
<script type="text/javascript" src="<?php bloginfo('template_directory'); ?>/gallery/jquery.nivo.slider.pack.js"></script>
<script type="text/javascript">
	var $jQ = jQuery.noConflict();
    $jQ(window).load(function() {
		$jQ('#slider').nivoSlider({
			effect: 'random', // Specify sets like: 'sliceDown, sliceDownLeft, sliceUp, sliceUpLeft, sliceUpDown, sliceUpDownLeft, fold, fade, random, slideInRight, slideInLeft, boxRandom, boxRain, boxRainReverse, boxRainGrow, boxRainGrowReverse'
			slices: 15, // For slice animations
			boxCols: 8, // For box animations
			boxRows: 4, // For box animations
			animSpeed: 500, // Slide transition speed
			pauseTime: 3000, // How long each slide will show
			startSlide: 0, // Set starting Slide (0 index)
			directionNav: true, // Next & Prev navigation
			directionNavHide: true, // Only show on hover
			controlNav: false, // 1,2,3... navigation
			controlNavThumbs: false, // Use thumbnails for Control Nav
			controlNavThumbsFromRel: false, // Use image rel for thumbs
			controlNavThumbsSearch: '.jpg', // Replace this with...
			controlNavThumbsReplace: '_thumb.jpg', // ...this in thumb Image src
			keyboardNav: true, // Use left & right arrows
			pauseOnHover: true, // Stop animation while hovering
			manualAdvance: false, // Force manual transitions
			captionOpacity: 0.8, // Universal caption opacity
			prevText: 'Prev', // Prev directionNav text
			nextText: 'Next', // Next directionNav text
			beforeChange: function(){}, // Triggers before a slide transition
			afterChange: function(){}, // Triggers after a slide transition
			slideshowEnd: function(){}, // Triggers after all slides have been shown
			lastSlide: function(){}, // Triggers when last slide is shown
			afterLoad: function(){} // Triggers when slider has loaded
		});
	});
</script>
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/gallery/themes/default/default.css" type="text/css" media="screen" />
<link rel="stylesheet" href="<?php bloginfo('template_directory'); ?>/gallery/nivo-slider.css" type="text/css" media="screen" />

<div id="gallery" class="ad-gallery">
<?php if(wpthemes_options('top_gallery_category') == '0' || wpthemes_options('top_gallery_category') == '' ) { ?>
	<?php  
	global $post, $wp_version;
	$postslist = query_posts("showposts=4");
	$num = 1;
	foreach ($postslist as $post) :       
	setup_postdata($post);  
		$gallery_data['src' . $num] = $gallery_img_src[0];
		$gallery_data['src_thumb' . $num] = $gallery_img_thumb_src[0];
		$gallery_data['title' . $num] = get_the_title();
		$gallery_data['permalink' . $num] = get_permalink();
		$gallery_data['category' . $num] = get_the_category();
		$gallery_data['content' . $num] = wpthemes_post_content(145, 1, "(more)", 0);
	$num++;
	endforeach; ?>
        <div class="slider-wrapper theme-default">
            <div class="ribbon"></div>
            <div id="slider" class="nivo-slider">

			<?php $num=1; while($num <= 4) { ?>
                <img src="<?php bloginfo('template_directory'); ?>/gallery/images/<?php echo $num; ?>.jpg" title="#htmlcaption<?php echo $num; ?>" <?php if ($num>1) echo 'style="display:none"'; ?> />
			<?php $num++; } ?>
            </div>
			<?php $num=1; while($num <= 4) { ?>
            <div id="htmlcaption<?php echo $num; ?>" class="nivo-html-caption">
				<h3><a href="<?php echo $gallery_data['permalink' . $num]; ?>"><?php echo $gallery_data['title' . $num]; ?></a></h3>
				<span class="slider-date"><?php the_time(wpthemes_options('date_format')); ?></span>
                <?php echo $gallery_data['content' . $num]; ?>
            </div>
			<?php $num++; } ?>
        </div>
<?php } else { 
	global $post, $wp_version, $num_sum, $gallery_data;
	$num = 1;
	$num_sum = wpthemes_options('featured_num');
	$gallery_category = wpthemes_options('top_gallery_category');
	$top_gallery_posts = query_posts("showposts=$num_sum&cat=$gallery_category");
	foreach($top_gallery_posts as $post) {
		if ( has_post_thumbnail($thumbnail->ID)) {
			setup_postdata($post);
			if ( version_compare( $wp_version, '2.9', '>=' ) ) {
				$gallery_img = get_the_post_thumbnail($post->ID,'large', array('class' => 'full'));
				$gallery_thumb_img = get_the_post_thumbnail($post->ID,'thumbnail');
				$gallery_img_src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'large');
				$gallery_img_thumb_src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail');
			} else {                         
				$gallery_img_src = get_post_meta($post->ID, 'featured', true);
				$gallery_img_thumb_src = get_post_meta($post->ID, 'featured', true);
				$gallery_img = '<img src="$gallery_img_src" class="full" />';
				$gallery_thumb_img = '<img src="$gallery_img_src" class="post_thumbnail" />';
			}
		}
		$gallery_data['src' . $num] = $gallery_img_src[0];
		$gallery_data['src_thumb' . $num] = $gallery_img_thumb_src[0];
		$gallery_data['title' . $num] = get_the_title();
		$gallery_data['permalink' . $num] = get_permalink();
		$gallery_data['category' . $num] = get_the_category();
		$gallery_data['content' . $num] = wpthemes_post_content(145, 1, "(more)", 0);
		$num++;
	} ?>
		<div class="slider-wrapper theme-default">
            <div class="ribbon"></div>
            <div id="slider" class="nivo-slider">
			<?php $num=1; while($num <= $num_sum) { ?>
                <img src="<?php echo $gallery_data['src' . $num]; ?>" title="#htmlcaption<?php echo $num; ?>" <?php if ($num>1) echo 'style="display:none"'; ?> />
			<?php $num++; } ?>
			
            </div>
			<?php $num=1; while($num <= $num_sum) { ?>
            <div id="htmlcaption<?php echo $num; ?>" class="nivo-html-caption">
                <?php echo $gallery_data['content' . $num]; ?>
            </div>
			<?php $num++; } ?>
        </div>
<?php } ?>
</div></div></div></div>
	
<?php } ?>
<?php wp_reset_query();?>