<div class="contest_viewer_container">
	
	<div class="team_names">
		<div class="left">
			<?php echo $information['contest']->away_team_name; ?>
			<?php if (!is_null($information['away_team']) and !Helpers::strEqual($information['away_team']->level, 'V')): ?>
				[<?php echo $information['away_team']->level; ?>]
			<?php endif; ?>
		</div>

		<div class="designations">
			<div class="away">Away</div>
			<div class="home">Home</div>

			 <?php
		          // Is this contest flagged as not rankable?
		          if (!is_null($information['contest']->flags))
		          {
		              // Decode the flags from the contest, should be a JSON string
		              $flags = json_decode($information['contest']->flags);

		              // Was the object decoded, and it's a valid object, and it has an 'is_rankable' property
		              if (!is_null($flags) and
		                  is_object($flags) and
		                  property_exists($flags, 'is_rankable'))
		              {
		                  // If the property is false, then the contest is not rankable
		                  if (!$flags->is_rankable)
		                  {
		                      $flagged = true;
		                  }
		              }
		          }
		          else
		          {
		              $flagged = false;
		          }
		      ?>

		      <?php if ($flagged): ?>

		          <div style="margin: 0 auto; width: 30px; text-align: center;">
		              <img src="<?php echo asset('/images/icons/not_rankable_16px.png'); ?>" alt="" title="This contest is not rankable." style="" />
		          </div>

		      <?php endif; ?>

		</div>


		<div class="right">
			<?php echo $information['contest']->home_team_name; ?>			
			<?php if (!is_null($information['home_team']) and !Helpers::strEqual($information['home_team']->level, 'V')): ?>
				[<?php echo $information['home_team']->level; ?>]
			<?php endif; ?>
		</div>

	</div>

	<div class="away_team_info">		
		<div class="team_logo float_left" style="margin:5px 10px 5px 0;">			
			<?php
				$image_url = null;
				if (!is_null($information['away_ap']))
				{
					$school = school::find($information['away_ap']->host_school);

					if (!is_null($school))
					{
						$image_url = ImagesController::getImageURL($school->short_name, 'logo', '128x128');
					}
				}
			?>
			<?php if (!is_null($image_url)): ?>
				<img src="<?php echo $image_url; ?>" alt="" title="" style="width:128px; height:128px;" />
			<?php else: ?>
				<img src="http://www.osaa.org/images/no_logo.png" alt="" title="No School Logo Available" class="tooltip" style="width:128px; height:128px;">
			<?php endif; ?>
		</div>
		
		<br class="clear" />

		<div class="league">
			<?php if (!is_null($information['away_ap'])): ?>
				<?php echo preg_replace('/\ \(.*\)/', '', $information['away_ap']->league); ?> <?php echo Helpers::getLeagueName($information['away_ap']->league); ?>
			<?php else: ?>
				<br />
			<?php endif; ?>
		</div>
	
		<div class="colors">
			<?php if (!is_null($information['away_ap'])): ?>
				<?php echo $information['away_ap']->getColorsList(); ?>
			<?php else: ?>
				<br />
			<?php endif; ?>
		</div>	

		<?php if (!is_null($information['away_ap'])): ?>
			<a href="<?php echo url('/teams/' . $information['away_ap']->id . '#tabs-V'); ?>" class="button" style="font-size:8pt;">Team Page</a>
			<a href="<?php echo url('/teams/' . $information['contest']->away_team . '/roster/2'); ?>" class="button" style="font-size:8pt;" target="_blank">Program Roster</a>
		<?php else: ?>
			<br />
		<?php endif; ?>
	</div>

	<div class="info">
		<div class="scores" style="position: relative;">
			<?php if (!Helpers::strIsEmpty($information['contest']->overtime_notes)): ?>
				<div style="position: absolute; width: 100%; font-size: 10pt; color: #7d7b7d;">
					<?php echo $information['contest']->overtime_notes; ?>
				</div>


			<?php endif; ?>


			<div class="away_score">
				<?php if ($information['is_scored']): ?>
					<?php echo $information['contest']->away_team_score; ?>
				<?php endif; ?>
			</div>
			<div class="home_score">
				<?php if ($information['is_scored']): ?>
					<?php echo $information['contest']->home_team_score; ?>
				<?php endif; ?>
			</div>

			<?php if ($information['contest']->is_forfeit): ?>
				<div class="forfeit">
					FORFEIT
				</div>
			<?php endif; ?>
		</div>
		
		<div class="date">
			<?php /*  date('n/j/y g:ia T', strtotime($information['event']->start_at))  */ ?>
			<?php echo Helpers::formatDateTime('%CONTEST_VIEWER%', strtotime($information['event']->start_at), $information['event']->time_zone); ?>
		</div>
		
		<?php if (!is_null($information['contest']->tournament)): ?>
			<div class="tournament">
				<?php echo $information['contest']->tournament; ?>
			</div>
		<?php endif; ?>
		
		<div class="location">
			<?php echo $information['contest']->location_name; ?>
		</div>		
		
		<div class="type">
			<?php echo Helpers::getContestTypeName($information['contest']->contest_type); ?><?php if ($information['contest']->is_endowment): ?>, Endowment<?php endif; ?>

			<?php if (Helpers::strEqual($information['contest']->activity, array('FBL', 'BBX', 'GBX', 'BBL', 'SBL'))): ?>
				Game
			<?php elseif (Helpers::strEqual($information['contest']->activity, array('VBL', 'BSC', 'GSC'))): ?>
				Match
			<?php else: ?>
				Contest
			<?php endif; ?>
		</div>						
		
		<?php if ($information['is_scored']): ?>

			<br />

			<div class="sub_scores">								

				<?php /*  FBL  */ ?>
				<?php if (Helpers::strEqual($information['contest']->activity, array('FBL'))): ?>
					<table>
						<thead>
							<tr class="period_name">
								<th></th>
								<?php if ($information['sub_scores'] > 0): ?>
									<th colspan="4">Quarter</th>	
								<?php endif; ?>
								<?php if ($information['sub_scores'] > 4): ?>
									<th colspan="<?php echo $information['sub_scores'] - 4; ?>">OT</th>
								<?php endif; ?>						
								<th></th>
							</tr>
							<tr class="head">
								<th></th>							
								<?php if ($information['sub_scores'] > 0): ?>
									<th>1</th>
									<th>2</th>
									<th>3</th>
									<th>4</th>
								<?php endif; ?>
								<?php if ($information['sub_scores'] > 4): ?>
									<?php for ($i = 1; $i <= $information['sub_scores'] - 4; $i++): ?>
										<th><?php echo $i; ?></td>
									<?php endfor; ?>
								<?php endif; ?>	
								<th class="final">Final</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td class="team"><?php echo $information['winner']['name']; ?></td>
								<?php for ($i = 1; $i <= $information['sub_scores']; $i++): ?>
									<td><?php echo Helpers::getPeriodScore($information['winner']['sub_scores'], $i); ?></td>
								<?php endfor; ?>
								<td class="final"><?php echo $information['winner']['score']; ?></td>
							</tr>
							<tr>
								<td class="team"><?php echo $information['loser']['name']; ?></td>
								<?php for ($i = 1; $i <= $information['sub_scores']; $i++): ?>
									<td><?php echo Helpers::getPeriodScore($information['loser']['sub_scores'], $i); ?></td>
								<?php endfor; ?>
								<td class="final"><?php echo $information['loser']['score']; ?></td>
							</tr>
						</tbody>
					</table>
				<?php endif; ?>

				<?php /*  VBL  */ ?>
				<?php if (Helpers::strEqual($information['contest']->activity, array('VBL'))): ?>
					<?php
						if ($information['sub_scores'] <= 3)
						{
							$information['sub_scores'] = 3;
						}
						else
						{
							$information['sub_scores'] = 5;
						}
					?>

					<table>
						<thead>
							<tr class="period_name">
								<th></th>								
								<th colspan="<?php echo $information['sub_scores']; ?>">Set</th>									
								<th></th>
							</tr>
							<tr class="head">
								<th></th>							
								<?php for ($i = 1; $i <= $information['sub_scores']; $i++): ?>
									<th><?php echo $i; ?></th>									
								<?php endfor; ?>									
								<th class="final">Final</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td class="team"><?php echo $information['winner']['name']; ?></td>								
								
								<?php for ($i = 1; $i <= $information['sub_scores']; $i++): ?>
									<td>
										<?php if (is_null(Helpers::getPeriodScore($information['winner']['sub_scores'], $i))): ?>
											- -
										<?php else: ?>
											<?php echo Helpers::getPeriodScore($information['winner']['sub_scores'], $i); ?>
										<?php endif; ?>
									</td>
								<?php endfor; ?>
								
								<td class="final"><?php echo $information['winner']['score']; ?></td>
							</tr>

							<tr>
								<td class="team"><?php echo $information['loser']['name']; ?></td>								
								
								<?php for ($i = 1; $i <= $information['sub_scores']; $i++): ?>
									<td>
										<?php if (is_null(Helpers::getPeriodScore($information['loser']['sub_scores'], $i))): ?>
											- -
										<?php else: ?>
											<?php echo Helpers::getPeriodScore($information['loser']['sub_scores'], $i); ?>
										<?php endif; ?>
									</td>
								<?php endfor; ?>
								
								<td class="final"><?php echo $information['loser']['score']; ?></td>
							</tr>
							
						</tbody>
					</table>
				<?php endif; ?>

				<?php /*  BSC, GSC  */ ?>
				<?php if (Helpers::strEqual($information['contest']->activity, array('BSC', 'GSC'))): ?>
					<table>
						<thead>
							<tr class="period_name">
								<th></th>
								<?php if ($information['sub_scores'] > 0): ?>
									<th colspan="2">Half</th>	
								<?php endif; ?>
								<?php if ($information['sub_scores'] > 2): ?>
									<th colspan="2">OT</th>			
									<?php if ($information['sub_scores'] > 4): ?>						
										<th>Kicks</th>
									<?php endif; ?>
								<?php endif; ?>						
								<th></th>
							</tr>
							<tr class="head">
								<th></th>							
								<?php if ($information['sub_scores'] > 0): ?>
									<th>1</th>
									<th>2</th>									
								<?php endif; ?>
								<?php if ($information['sub_scores'] > 2): ?>
									<th>1</th>
									<th>2</th>
									<?php if ($information['sub_scores'] > 4): ?>
										<th>Kicks</th>
									<?php endif; ?>
								<?php endif; ?>	
								<th class="final">Final</th>
							</tr>
						</thead>
						<tbody>
							<tr>
								<td class="team"><?php echo $information['winner']['name']; ?></td>
								<?php for ($i = 1; $i <= $information['sub_scores']; $i++): ?>
									<td><?php echo Helpers::getPeriodScore($information['winner']['sub_scores'], $i); ?></td>
								<?php endfor; ?>
								<td class="final"><?php echo $information['winner']['score']; ?></td>
							</tr>
							<tr>
								<td class="team"><?php echo $information['loser']['name']; ?></td>
								<?php for ($i = 1; $i <= $information['sub_scores']; $i++): ?>
									<td><?php echo Helpers::getPeriodScore($information['loser']['sub_scores'], $i); ?></td>
								<?php endfor; ?>
								<td class="final"><?php echo $information['loser']['score']; ?></td>
							</tr>
						</tbody>
					</table>
				<?php endif; ?>

			</div>		

		<?php else: ?>

			<?php if ($information['contest']->contest_type == 'PO' and
				 (!is_null($information['matchup']->broadcasters) or !is_null($information['matchup']->audio_url) or !is_null($information['matchup']->video_url))): ?>

				<div style="width: 400px; height: 100px; overflow-x: hidden; overflow-y: auto; text-align: center; font-size: 9pt;">
					<div style="color: #990000; font-weight: bold; margin-top: 0.5em;">Broadcast Coverage</div>

					<?php if (!Helpers::strIsEmpty($information['matchup']->audio_url)): ?>
                        <a href="<?php echo url('/radio-network'); ?>">OSAA Radio Network</a>
                        <?php if (!Helpers::strIsEmpty($information['matchup']->video_url) || (!is_null($information['matchup']) and !Helpers::strIsEmpty($information['matchup']->broadcasters))): ?>
                            <br />
                        <?php endif; ?>
                    <?php endif; ?>

                    <?php if (!is_null($information['matchup']->video_url)): ?>
                        <a href="http://www.nfhsnetwork.com/channels/oregon" target="_blank">NFHS Network</a>
                        <small>[Video LIVE]</small>
                        <?php if (!is_null($information['matchup']->broadcasters) and !Helpers::strIsEmpty($information['matchup']->broadcasters)): ?>
                            <br />
                        <?php endif; ?>
                    <?php endif; ?>

					<?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 (!preg_match('/^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; ?>
				</div>

			<?php endif; ?>


		<?php endif; ?>
	
	</div>

	<div class="home_team_info">		
		<div class="team_logo float_right" style="margin:5px 0 5px 10px;">		
			<?php
				$image_url = null;
				if (!is_null($information['home_ap']))
				{
					$school = school::find($information['home_ap']->host_school);

					if (!is_null($school))
					{
						$image_url = ImagesController::getImageURL($school->short_name, 'logo', '128x128');
					}
				}
			?>
			<?php if (!is_null($image_url)): ?>
				<img src="<?php echo $image_url; ?>" alt="" title="" style="width:128px; height:128px;" />
			<?php else: ?>
				<img src="http://www.osaa.org/images/no_logo.png" alt="" title="No School Logo Available" class="tooltip" style="width:128px; height:128px;">
			<?php endif; ?>
		</div>	
		
		<br class="clear" />

		<div class="league">
			<?php if (!is_null($information['home_ap'])): ?>
				<?php echo preg_replace('/\ \(.*\)/', '', $information['home_ap']->league); ?> <?php echo Helpers::getLeagueName($information['home_ap']->league); ?>
			<?php else: ?>
				<br />
			<?php endif; ?>
		</div>		

		<div class="colors">
			<?php if (!is_null($information['home_ap'])): ?>
				<?php echo $information['home_ap']->getColorsList(); ?>
			<?php else: ?>
				<br />
			<?php endif; ?>
		</div>

		<?php if (!is_null($information['home_ap'])): ?>
			<a href="<?php echo url('/teams/' . $information['contest']->home_team . '/roster/2'); ?>" class="button" style="font-size:8pt;" target="_blank">Program Roster</a>
			<a href="<?php echo url('/teams/' . $information['home_ap']->id . '#tabs-V'); ?>" class="button" style="font-size:8pt;">Team Page</a>		
		<?php else: ?>
			<br />
		<?php endif; ?>
	</div>

	<?php if (!Helpers::strIsEmpty($information['contest']->comments)): ?>
		<div class="contest_notes ui-corner-all">

			<?php echo $information['contest']->comments; ?>

		</div>
	<?php endif; ?>

</div>

