<?php
/*
Template Name: Template Preview
*/



$item = $_GET['item'];

// $url = site_url().'/template/' . $item;
$url = site_url().'/' . $item;

$postid = url_to_postid( $url ); 
$custom_title = strtolower(get_post_meta( $postid, 'jm_custom_title', true ));
$preview_url = site_url().'/demos/' . $custom_title;
$title = get_the_title($postid);

echo $postid;

setPostViews($postid);

?>

<!DOCTYPE HTML>
<html>
    <head>
        <title><?php echo $title; ?> - FREEHTML5.co</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <meta name="description" content="Free HTML5 Templates by FREEHTML5.co" />
        <meta name="keywords" content="templates, site templates, freebies, html5, css, responsive, creative commons" />
        <meta name="apple-mobile-web-app-title" content="WebuildHTML5" />
        <link href='http://fonts.googleapis.com/css?family=Questrial' rel='stylesheet' type='text/css'>
        <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" type="text/css">
        <style>

        body {
        	font-family: arial, sans-serif;
        }
        #demo-main {
		    position:fixed;
		    left:0;
		    top:90px;
		    width:100%;
		    height:calc(100% - 90px);
		    border-top: 1px solid #ccc;
			}
			#demo-main iframe {
		    position:absolute;
		    left:0;
		    top:0;
		    display:block;
		    width:100%;
		    height:100%;
		    border: transparent;
			}

			#demo-header {
				height: 90px;
				z-index:10000;
	    		min-width:1000px;
			}
			#demo-header ul {
				list-style: none;
				padding: 0;
				margin: 20px 0 0 0;
				float: right;
			}

			#demo-header ul li {
				display: inline;
			}
			#demo-header ul a, #demo-header ul span {
				/*color: #b6b6b6;*/
				color: #8a8a8a;
				padding: 10px 15px!important;
				border-radius: 4px;
				border: 1px solid rgba(0,0,0,.2);
				display: block;
				float: left;
				margin: 0 5px 5px 0;
			}
			#demo-header ul li.navprev a, #demo-header ul li.navnext a,
			#demo-header ul li.navprev span, #demo-header ul li.navnext span{
				padding-left: 20px!important;
				padding-right: 20px!important;
			}
			#demo-header ul span {
				background: #e5e5e5;
				border: 1px solid #e5e5e5;
				color: #fff;
			}
			#demo-header ul a:hover {
				color: #F36D65;
				border: 1px solid #F36D65;
			}
			#demo-header ul li.download a {
				background: #7ee383;	
				color: #fff;
				border: 1px solid #75d57a;
			}
			#demo-header ul li.download a:hover {
				background: #F36D65;
				color: #fff;
				border: 1px solid #F36D65;
			}
</style>
<?php wp_head(); ?>
    </head>
    
    <body class="is-demo">

    <?php 



$args = array(
	'p' => $postid, // id of a page, post, or custom type
	'post_type' => 'post'
);


$query = new WP_Query($args);

if( $query->have_posts() ) :
		$query->the_post(); 
	// the_title();

	$download_title = strtolower(str_replace(':', '', get_the_title()));
	$download_title = str_replace(' ', '-', $download_title);
	

?>

       	<header id="demo-header">
       		<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- h5a Top Leaderboard -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-9294834522530836"
     data-ad-slot="4203474109"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script>
					<?php 
          	$prev_post = get_previous_post();
          	$next_post = get_next_post();

          	

			



          ?>
       		<ul>
       			<li><a href="<?php echo site_url().'/demos/'.$custom_title.'/';?>" title="See demo without frame" target="_blank"><i class="fa fa-external-link fa-lg"></i></a></li>
       			<li><a href="<?php echo site_url();?>" title="Back to FREEHTML5.co Homepage"><i class="fa fa-home fa-lg"></i></a></li>
       			<li class="download"><a href="<?php echo site_url() .'/download/?item=' . $download_title; ?>" title="Free Download '<?php the_title();?>'" data-id="<?php echo $postid; ?>" class="template-download countable_link"><i class="fa fa-download fa-lg"></i></a></li>
       			<li>
       				<?php if (!empty( $prev_post )) { ?>

						<?php 

						$prev_title = strtolower(str_replace(':', '', $prev_post->post_title));
						$prev_title = str_replace(' ', '-', $prev_title);
						?>

       					<a href="?item=<?php echo $prev_title; ?>" title="Previous Template '<?php echo $prev_post->post_title; ?>' "><i class="fa fa-arrow-left fa-lg"></i></a>


       				<?php }else {?>
       					<span><i class="fa fa-arrow-left fa-lg"></i></span>
       				<?php }?>
       			</li>
       			<li>
       				<?php if (!empty( $next_post )) { ?>
       					<?php 
       					$next_title = strtolower(str_replace(':', '', $next_post->post_title));
						$next_title = str_replace(' ', '-', $next_title);

       					?>
       					<a href="?item=<?php echo $next_title; ?>" title="Next Template '<?php echo $next_post->post_title; ?>' "><i class="fa fa-arrow-right fa-lg"></i></a>
       				<?php }else {?>
       					<span><i class="fa fa-arrow-right fa-lg"></i></span>
       				<?php }?>
       				</li>
       		</ul>
       	</header>
        <div id="demo-main">
            <iframe id="demo-iframe" src="<?php echo $preview_url; ?>">-</iframe>
        </div>
        
			
        <?php wp_footer(); ?>
       	<!-- Begin Inspectlet Embed Code -->
		<script type="text/javascript" id="inspectletjs">
		window.__insp = window.__insp || [];
		__insp.push(['wid', 369597392]);
		(function() {
		function __ldinsp(){var insp = document.createElement('script'); insp.type = 'text/javascript'; insp.async = true; insp.id = "inspsync"; insp.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://cdn.inspectlet.com/inspectlet.js'; var x = document.getElementsByTagName('script')[0]; x.parentNode.insertBefore(insp, x); }
		if (window.attachEvent) window.attachEvent('onload', __ldinsp);
		else window.addEventListener('load', __ldinsp, false);
		})();
		</script>
		<!-- End Inspectlet Embed Code -->


		<script>
		  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
		  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
		  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
		  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

		  ga('create', 'UA-65003908-1', 'auto');
		  ga('send', 'pageview');

		</script>
       
    </body>

</html>
<?php 	
	// endwhile;
endif;
?>