<?php
$have_news = false;
$static_file = dirname(__FILE__) . "/../news/all_news_json.json";
if(file_exists($static_file)) {
	$allNews = json_decode(file_get_contents($static_file), true);
	
	if(is_array($allNews) && count($allNews) > 0) {
		$have_news = true;
	}
}

if($have_news) {
	//$optres['js'][] = $path . 'js/jquery.totemticker.js';
	//$optres['css'][] = dirname(__FILE__) . '/css/jquery.simplyscroll.css';
	$optres['js'][] = dirname(__FILE__) . '/js/jquery.simplyscroll.min.js';
	//echo '<pre>', var_export($allNews, true), '</pre>';
	
	?>
	<div class="news-ticker">
		<div class="news-ticker-title">Latest Cyprus News</div>
		<div class="news-ticker-news">
			<ul id="news-ticker" class="news-ticker-list">
				<?php
				foreach ($allNews as $i=>$cn) {
					echo '<li>';
					echo '<a href="', $cn['url'], '" target="_blank" rel="nofollow" class="news-ticker-out">', $cn['title'], '</a><br/><span class="news-ticker-source">', $cn['newspaper'], ' - ', date("F d, Y", intval($cn['timestamp'])), '</span>';
					echo '</li>';
				}
				?>
			</ul>
		</div>
		<div class="news-ticker-buttons">
			<span id="nt-up" class="nt-button">&lt;&lt; Previous</span>
			<span id="nt-stop" class="nt-button">Stop</span>
			<span id="nt-start" class="nt-button">Start</span>
			<span id="nt-down" class="nt-button">Next &gt;&gt;</span>
		</div>
	</div>
	
	<script type="text/javascript">
		$(document).ready(function(){
			
			$("#news-ticker").simplyScroll({
				orientation:'vertical',
				direction:'backwards',
				customClass:'vert'
			});
			
			/*
			$('#news-ticker').totemticker({
				row_height	:	'39px',
				next		:	'#nt-down',
				previous	:	'#nt-up',
				stop		:	'#nt-stop',
				start		:	'#nt-start',
				mousestop	:	true,
				max_items: 5,
				interval: 3000
			});
			*/
		});
	</script>
	<?php
}
?>