<?php get_header(); ?>

<div id="main">
	<div id="tv-mode">
	<?php
	//video wrapper and share buttons
	$id_post = (isset($_POST['id']));
	if ($id_post == ''){
		global $wp_query;
		$postID = $wp_query->post->ID;}
		else {
			$postID = $_POST['id'];
		}
		$permalink = get_permalink( $postID );
		$video_embed = wp_oembed_get(get_post_meta($postID, "trendingnews_video_link", true), array('width'=>968, 'autoplay' => '1') );
		$pinimage = wp_get_attachment_image_src( get_post_thumbnail_id( $postID ), 'slider-img' );
		$category = get_the_category($postID);
		$the_title = get_the_title($postID);
		$tn_subtitle = get_post_meta($postID, 'tn_sub_title', true);
		?>
        <div id="post-page-title" class="tv-format-title">
            <h1>
              <?php echo $the_title; ?>
            </h1>
        </div><!--tv-format-title-->
        <div id="post-page-subtitle" class="tv-format-subtitle">
                   <?php if(empty($the_subtitle)) { echo excerpt(30); }  else { echo $the_subtitle;} ?>
        </div><!--tv-format-subtitle-->
		<div class="tv-video-wrapper">
        	<div class="tv-page-video-wrapper">
				<?php echo $video_embed; ?>
            </div><!--tv-page-video-wrapper-->
				<div class="share-tv">
					<div class="share-tv-title">
						<?php echo get_option('tn_share_this_video'); ?>
					</div>
				<ul>
					<li>
						<a href="http://www.facebook.com/sharer.php?u=<?php echo $permalink; ?>" target="blank" class="fb-share-icon" title="Share this post on Facebook"></a>
					</li>
				
					<li>
						<a href="https://twitter.com/intent/tweet?original_referer=<?php echo $permalink; ?>&amp;&tw_p=tweetbutton&url=<?php echo $permalink; ?>" target="_blank"  class="twitter-share-icon" title="Share this post on Twitter"></a>
					</li>
				
					<li>
						<a href="https://plusone.google.com/_/+1/confirm?hl=en-US&amp;url=<?php echo $permalink; ?>" target="_blank" class="google-share-icon" title="Share this post on Google Plus"></a>
					</li>

					<li>
						<a href="http://pinterest.com/pin/create/bookmarklet/?media=<?php $pinimg = wp_get_attachment_image_src( get_post_thumbnail_id( $postID), 'post-thumb' ); echo $pinimg[0]; ?>&url=<?php echo $permalink; ?>&is_video=false&description=<?php echo $the_title; ?>" target="_blank" class="pinterest-share-icon" title="Share this post on Pinterest"></a>
					</li>	
					<li>
						<a href="http://www.stumbleupon.com/submit?url=<?php echo $permalink; ?>&title=<?php echo $the_title; ?>" target="_blank" class="stumble-share-icon" title="Share this post on Stumbleupon"></a>
					</li>		
					<li>
						<a href="http://www.reddit.com/submit?url=<?php echo $permalink; ?>&title=<?php echo $the_title; ?>" target="_blank" class="reddit-share-icon" title="Share this post on Reddit"></a>
					</li>		
				</ul>
				<span class="category-tv-icon"><a href="<?php echo get_category_link($category[0]->term_id )?>"><?php echo $category[0]->cat_name;?></a></span>
				</div></div>
	
		<div class="tv-page-widget home-widget">
			<h3>
				<span class="widget-title"><?php echo get_option('tn_tv_carousel_title'); ?></span>
                <div class="tv-navigation">
                  <a href="#" class="tv-prev" ></a>
                  <a href="#" class="tv-next"></a>
                </div><!--carousel-navigation-->
			</h3>
			<div class="tv-carousel">
				<ul class="slides">
					<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
					<li>
						<div class="carousel-image">
							<?php if (  (function_exists('has_post_thumbnail')) && (has_post_thumbnail())  ) { ?>
							<a class="ajax" href="<?php the_ID(); ?>" title="<?php the_title(); ?>">
							<?php the_post_thumbnail('carousel-thumb'); ?>
							</a>
							<?php } ?>
							<div class="carousel-text">
                            	<div class="carousel-category"><?php $category = get_the_category(); if($category[0]){echo '<a href="'.get_category_link($category[0]->term_id ).'">'.$category[0]->cat_name.'</a>';} ?>
                				</div><!--carousel-category-->
								<div class="carousel-title">
									<a class="ajax" href="<?php the_ID() ?>">
									<?php $tit = the_title('','',FALSE); echo substr($tit, 0, 40); if (strlen($tit) > 40) echo " ..."; ?>
									</a>
								</div><!--carousel-title-->
							</div><!--carousel-text-->
						</div><!--carousel-image-->
					</li>
					<?php endwhile; endif; ?>
				</ul>
			</div><!--tv-carousel-->
		</div><!--tv-page-widget-->
	</div><!--tv-mode-->
</div><!--main-->
<?php get_footer(); ?>
