<?php
$args = array('showposts' => $wpzoom_featured_posts_posts, 'orderby' => 'date', 'order' => 'DESC');
$featType = $wpzoom_featured_type;
if ($featType == 'Tag') { $args['tag'] = "$wpzoom_featured_slug";  // Breaking tag slug 
}
elseif ($featType == 'Category') { $args['cat'] = "$wpzoom_featured_slug";  // Breaking tag slug 
}
$dateformat = get_option('date_format');
$timeformat = get_option('time_format');
?>

<div id="slider">
	<div id="slides_container">
		<div class="slides_control">
			<?php query_posts($args); if ( have_posts() ) : while (have_posts()) : the_post(); update_post_caches($posts);  
				unset($videocode); 
				$videocode = get_post_meta($post->ID, 'wpzoom_post_embed_code', true);
				$video_hd = get_post_meta($post->ID, 'wpzoom_post_embed_hd', true);
				?>
				
				<div class="slide">
					<?php if (strlen($videocode) > 1) { 
						$videocode = preg_replace("/(width\s*=\s*[\"\'])[0-9]+([\"\'])/i", "$1 640 $2", $videocode);
						$videocode = preg_replace("/(height\s*=\s*[\"\'])[0-9]+([\"\'])/i", "$1 360 $2", $videocode);
						$videocode = str_replace("<embed","<param name='wmode' value='transparent'></param><embed",$videocode);
						$videocode = str_replace("<embed","<embed wmode='transparent' ",$videocode); ?>
					<div class="cover"><?php echo "$videocode"; ?></div>
						<?php }
						elseif (strlen($videocode) < 1) { 
						unset($videocode); $videocode = get_post_meta($post->ID, 'wpzoom_post_embed_self', true); 
						if (strlen($videocode) > 1) { 
						$skin = strtolower(get_post_meta($post->ID, 'wpzoom_post_embed_skin', true));
						
						unset($img); if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) { 
						$thumbURL = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '' );
						$img = $thumbURL[0];  }
						else  {
							if (!$img) { $img = catch_that_image($post->ID);  }
							} 
						?>
						<div class="cover">
							<div id='video_<?php echo the_ID() ; ?>'>Video</div>
							<script type='text/javascript'>
							  jwplayer('video_<?php echo the_ID();  ?>').setup({
								'file': '<?php echo "$videocode"; ?>',
								'skin': '<?php bloginfo('template_directory'); ?>/js/skins/<?php echo "$skin/$skin.zip"; ?>',
								'image' : '<?php echo "$img"; ?>',
								'width': '640',
								'height': '360',
								<?php if (strlen($video_hd) > 1) { ?>'plugins': {
								   'hd-1': {
									   'file': '<?php echo "$video_hd"; ?>'
								   }
								}, <?php } ?>
								'modes': [
									{type: 'flash', src: '<?php bloginfo('template_directory'); ?>/js/player.swf'},
									{type: 'html5'}
								]
							  });
							</script>
						</div>
					<?php } 
					} if (!$videocode) { 
					unset($img); if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) {
						$thumbURL = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '' );
						$img = $thumbURL[0];  }
 						else  {
							if (!$img) { $img = catch_that_image($post->ID);  }
							  }
						if ($img){ $img = wpzoom_wpmu($img); ?>
						<div class="cover">
							<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $img ?>&amp;h=360&amp;w=640&amp;zc=1" alt="<?php the_title(); ?>" width="640" height="360" /></a>
						</div>
						<?php }
						} ?>
					
						
					<h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
				</div>
 				<?php endwhile; endif; wp_reset_query(); ?>
				
				<?php if ($wpzoom_slideshow_popular == 'Show') { ?>
 				<?php $loop = new WP_Query( array( 'caller_get_posts' => true, 'showposts' => $wpzoom_featured_posts_posts, 'meta_key' => 'Views', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) ); 	
				if ( $loop->have_posts() ) :  while ( $loop->have_posts() ) : $loop->the_post();  
				unset($videocode); 
 				$videocode = get_post_meta($post->ID, 'wpzoom_post_embed_code', true);
				$video_hd = get_post_meta($post->ID, 'wpzoom_post_embed_hd', true);
				?>
				
				<div class="slide">
					<?php if (strlen($videocode) > 1) { 
						$videocode = preg_replace("/(width\s*=\s*[\"\'])[0-9]+([\"\'])/i", "$1 640 $2", $videocode);
						$videocode = preg_replace("/(height\s*=\s*[\"\'])[0-9]+([\"\'])/i", "$1 360 $2", $videocode);
						$videocode = str_replace("<embed","<param name='wmode' value='transparent'></param><embed",$videocode);
						$videocode = str_replace("<embed","<embed wmode='transparent' ",$videocode); ?>
						<div class="cover"><?php echo "$videocode"; ?></div>
						<?php }
						elseif (strlen($videocode) < 1) { 
						unset($videocode); $videocode = get_post_meta($post->ID, 'wpzoom_post_embed_self', true); 
						if (strlen($videocode) > 1) { 
						$skin = strtolower(get_post_meta($post->ID, 'wpzoom_post_embed_skin', true));
						
						unset($img); if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) { 
						$thumbURL = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '' );
						$img = $thumbURL[0];  }
 						else  {
							if (!$img) { $img = catch_that_image($post->ID);  }
							} 
 						?>
						<div class="cover">
							<div id='video_pop_<?php echo the_ID() ; ?>'>Video</div>
							<script type='text/javascript'>
							  jwplayer('video_pop_<?php echo the_ID();  ?>').setup({
								'file': '<?php echo "$videocode"; ?>',
								'skin': '<?php bloginfo('template_directory'); ?>/js/skins/<?php echo "$skin/$skin.zip"; ?>',
								'image' : '<?php echo "$img"; ?>',
								'width': '640',
								'height': '360',
								<?php if (strlen($video_hd) > 1) { ?>'plugins': {
								   'hd-1': {
									   'file': '<?php echo "$video_hd"; ?>'
								   }
								}, <?php } ?>
								'modes': [
									{type: 'flash', src: '<?php bloginfo('template_directory'); ?>/js/player.swf'},
									{type: 'html5'}
								]
							  });
							</script>
						</div>
					<?php } 
					} if (!$videocode) { 
					unset($img); if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) {
						$thumbURL = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '' );
						$img = $thumbURL[0];  }
 						else  {
							if (!$img) { $img = catch_that_image($post->ID);  }
							} 
						if ($img){ $img = wpzoom_wpmu($img); ?>
						<div class="cover">
							<a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title(); ?>"><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $img ?>&amp;h=360&amp;w=640&amp;zc=1" alt="<?php the_title(); ?>" width="640" height="360" /></a>
						</div>
						<?php }  
						} ?>
					
					<h2><a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
				</div>
				
				<?php endwhile; endif; ?>
				<?php } ?>
	  
		</div><!-- /.slides_control -->
 	</div><!-- /.slides_container -->
 
	<div id="video-tabs">
		<ul class="nav">
			<li><a href="#featured"><span><?php echo "$wpzoom_featured_tf";?></span></a></li>
			<?php if ($wpzoom_slideshow_popular == 'Show') { ?><li><a href="#popular"><span><?php echo "$wpzoom_featured_tp";?></span></a></li><?php } ?>
		</ul>
		
		<div class="vtab">
			<div class="scrollbar"><div class="track"><div class="thumb"><div class="end"></div></div></div></div>
			<div class="viewport">
 
				<div id="featPostsSmall" class="overview">
					
					<?php query_posts($args); if ( have_posts() ) : ?>
					<ul id="featured" class="pagination">
						<?php while (have_posts()) : the_post(); update_post_caches($posts); ?>

						<li class="fadei">
							<a href="#" rel="nofollow" class="clearfix">
								<?php unset($img); if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) {
									$thumbURL = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '' );
									$img = $thumbURL[0];  }
 									else  {
										if (!$img)  {  $img = catch_that_image($post->ID);   }  
									}
									if ($img){ $img = wpzoom_wpmu($img); ?><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $img ?>&amp;h=44&amp;w=60&amp;zc=1" alt="<?php the_title(); ?>" width="60" height="44" /><?php } ?>
								<div class="info">
									<?php the_title(); ?>
									<span><?php the_time("$dateformat "); ?></span>
 								</div>
							</a>
						</li>
 					   
					   <?php endwhile; ?>
					</ul><!-- /#featured -->
					<?php endif;  ?>
					
					
					<?php wp_reset_query();  ?>
					
					<?php if ($wpzoom_slideshow_popular == 'Show') { ?>
						<?php $loop = new WP_Query( array( 'caller_get_posts' => true, 'showposts' => $wpzoom_featured_posts_posts,  'meta_key' => 'Views', 'orderby' => 'meta_value_num', 'order' => 'DESC' ) ); ?>
						<ul id="popular" class="pagination">	
							<?php if ( $loop->have_posts() ) : ?>
							<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
							<li class="fadei">
								<a href="#" rel="nofollow" class="clearfix">
									<?php unset($img); if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail() ) {
										$thumbURL = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), '' );
										$img = $thumbURL[0];  }
										else  {
											if (!$img)  {  $img = catch_that_image($post->ID);   }  
										}
										if ($img){ $img = wpzoom_wpmu($img); ?><img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $img ?>&amp;h=44&amp;w=60&amp;zc=1" alt="<?php the_title(); ?>" width="60" height="44" /><?php } ?>
									<div class="info">
										<?php the_title(); ?>
										<span><?php _e('Views:', 'wpzoom'); ?> <?php printf( get_post_meta( get_the_ID(), 'Views', true ) );  ?></span>
									</div>
								</a>
							</li>
							<?php endwhile; ?>
						</ul><!-- /#popular -->
						<?php endif; ?>
					<?php } ?>
					
				</div><!-- /#featPostsSmall -->
			</div><!-- /.viewport -->
		</div><!-- /.vtab -->
		
	</div><!-- /#video-tabs -->
	<br class="clear" />
	
</div><!-- /#slider --> 
<br class="clear" />