<?php $__env->startSection('page_title'); ?>
	OSAA - Live Coverage
<?php $__env->stopSection(); ?>

<?php $__env->startSection('live_alert'); ?>
    
    <?php
        GeneralController::getLiveAlert();
    ?>
    
<?php $__env->stopSection(); ?>

<?php $__env->startSection('jquery_init'); ?>
	$('.button').button();
	$('.button.back').button({icons : {secondary : 'ui-icon-arrowthick-1-e'}});
	$('.button.video').button({icons : {primary : 'ui-icon-play'}});
	$('.button.audio').button({icons : {primary : 'ui-icon-volume-on'}});

	/* Get the live stats variables */
	var live_file_holder = '<?php echo $information['live_file']->holder_path; ?>';
	var live_file = '<?php echo $information['live_file']->file_path; ?>';
	var exists = <?php echo ($information['live_file']->exists) ? 1 : 0; ?>;
	var recheck_rate = <?php echo $information['live_file']->recheck_rate; ?>;	

	/* Does the live stats file exist? */
	if (exists == 1)
	{
		/* Display the live stats file, the frame will auto reload every 30 seconds */
		$('#stats_frame').attr('src', live_file);

		$('#refresh_text').html('The stats frame will automatically refresh twice a minute.');
		
		var stale = <?php echo time() - strtotime($information['live_file']->updated_at); ?>;	
		var hours = Math.floor(stale / 3600);
		var seconds = stale - hours * 3600;
		var minutes = Math.floor(seconds / 60);
		seconds = seconds - minutes * 60;		

		console.log('Stats File Path: ' + live_file);
		console.log('Stats File Status: EXISTS');
		console.log('Stats File Updated At: <?php echo date('Y-m-d H:i:s', strtotime($information['live_file']->updated_at)); ?>');
		console.log('Stats File Stale: ' + hours + 'h ' + minutes + 'm ' + seconds + 's [' + stale + 'sec]');
		console.log('Page Loaded At: <?php echo date('Y-m-d H:i:s', time()); ?>');
	}
	else
	{
		/* Display the holder file */
		$('#stats_frame').attr('src', live_file_holder);

		$('#refresh_text').html('This page will automatically refresh every 30 seconds.');

		console.log('Stats File Path: ' + live_file);
		console.log('Stats File Status: DOES NOT EXIST');
		console.log('Stats File Holder: ' + live_file_holder);		
		console.log('Page Loaded At: <?php echo date('Y-m-d H:i:s', time()); ?>');

		/* Refersh this page every n seconds until the live file exists */
		setInterval(function ()
		{			
			location.reload();
		}, recheck_rate);
	}

	$('.refresh_button')
	.button({'text':false, 'icons' : {'primary' : 'ui-icon-refresh'}})
	.click(function(event)
	{
		event.preventDefault();

		location.reload();
	});

<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_sub_title'); ?>
	Live Championship Site Coverage
<?php $__env->stopSection(); ?>

<?php $__env->startSection('page_functions'); ?>
	<a href="#" class="refresh_button" style="margin-right: 10px; width: 24px; height: 24px;"></a>

	<a href="<?php echo $information['bracket_base_url']; ?>" class="button back" style="font-size: 9pt;">Bracket</a>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('main_content'); ?>	
	
	<h1>
		<?php echo $information['bracket']->event->name; ?>
	</h1>	

	<div style="width: 100%; padding-top: 1em;">

		<div style="width: 230px; height: 542px; float: left; margin-right: 8px;">
			<h2 style="margin-top: 0;">Live Stats From</h2>
			<p>
				<b><?php echo $information['location_name']; ?></b><br /><br />
				<div id="refresh_text"></div>
			</p>

			<?php if (!is_null($information['matchup']) and !Helpers::strIsEmpty($information['matchup']->video_url)): ?>
				
				<br />
				<h2>Video Feed</h2>
				<a href="<?php echo $information['matchup']->video_url; ?>" class="button video" style="font-size: 9pt;" target="_blank">Watch Now</a>
				<br />

			<?php endif; ?>

			<?php if (!is_null($information['matchup']) and !Helpers::strIsEmpty($information['matchup']->audio_url)): ?>
				
				<br />
				<h2>Audio Feed</h2>
				<a href="<?php echo $information['matchup']->audio_url; ?>" class="button audio" style="font-size: 9pt;" target="_blank">Listen Now</a>
				<br />

			<?php endif; ?>

			<?php if (!is_null($information['matchup']) and !Helpers::strIsEmpty($information['matchup']->broadcasters)): ?>
				
				<br />
				<h2>List of Broadcasters</h2>				
				
				<?php foreach (explode(";", $information['matchup']->broadcasters) as $info): ?>
					<?php
                        $matches = array();
                        preg_match('/.*{(.*)}.*/i', $info, $matches);                    
                        $link = (isset($matches[1])) ? $matches[1] : null;

                        $matches = array();
                        preg_match('/.*%(.*)%.*/i', $info, $matches);
                        $note = (isset($matches[1])) ? $matches[1] : null;
               
                        $info = preg_replace('/({.*})|(%.*%)/i', '', $info);                    
                    ?>
                
                    <?php if (Helpers::strIsEmpty($link)): ?>
                        <?php echo $info; ?>
                    <?php else: ?>
                        <?php if (!Helpers::strContains('http://', $link)): ?>
                            <?php $link = 'http://' . $link; ?>
                        <?php endif; ?>                            
                    
                        <a href="<?php echo $link; ?>" target="_blank"><?php echo $info; ?></a>
                    <?php endif; ?>
                                        
                    <?php if (!Helpers::strIsEmpty($note)): ?>
                        <small>[<?php echo $note; ?>]</small>
                    <?php endif; ?>
                
                    <br />

				<?php endforeach; ?>

				<br />

			<?php endif; ?>
		</div>
		
		<iframe id="stats_frame" src="" style="border: none; width: 782px; height: 542px;"></iframe>		
	
	</div>


<?php $__env->stopSection(); ?>

