﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
	<xsl:import href="LeftSideBar.xslt"/>
	<xsl:output method="xml" indent="yes"/>

	<xsl:template match="/">
		<xsl:variable name="TournamentItemID" select="normalize-space(AjaxRequest/Params/ItemID)"></xsl:variable>
		<xsl:variable name="HostName" select="normalize-space(AjaxRequest/HostName)"></xsl:variable>
		<xsl:variable name="WinnerTeam" select="AjaxRequest/TeamMatches/Winner/WinnerTeam"></xsl:variable>
		<xsl:variable name="TimerCount" select="AjaxRequest/TeamMatches/Match[WinnerTeamID = 0]/TimerCount"></xsl:variable>

		<table class="tableMaster" style="height:670px;">
			<tr>
				<td width="20%">
					<div id="divTournamentGamesDisplay" class="margin10">
						<xsl:call-template name="TournamentLeftSideBar">
							<xsl:with-param name="TeamsXml" select="AjaxRequest/Tournament"></xsl:with-param>
							<xsl:with-param name="ItemID" select="$TournamentItemID"></xsl:with-param>
							<xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
						</xsl:call-template>
					</div>
				</td>
				<td class="verticallyMiddle">
					<table align="center">
						<tr>
							<td class="textCenter">
								<xsl:choose>
									<xsl:when test="$WinnerTeam">
										&#xa0;
									</xsl:when>
									<xsl:otherwise>
										<div class="TournamentWinnerRound1Header marginBottom15">
											<span >Click On The Team That Won</span>
										</div>
										<div class="TournamentWinnerRound1Header2" align="center">
											<span>Round </span>
											<xsl:value-of select="AjaxRequest/TeamMatches/Match/Round"/>
										</div>
									</xsl:otherwise>
								</xsl:choose>
							</td>
						</tr>
						<tr>
							<td>
								<div align="center">
									<xsl:choose>
										<xsl:when test="$WinnerTeam">
											&#xa0;
										</xsl:when>
										<xsl:otherwise>
											<div style="width:200px;" class="marginTop20">
												<div class="marginBottom10 padding10" style="border:2px solid #9BBB59;">
													<span id="spanTournamentTimerDisplay" class="labelGoalTopicsTextCount">Time Left...</span>
													<div id="divRoundTimeCount" style="font-size:25px;height:30px;">

													</div>
												</div>
											</div>
											<div style="width:250px;" class="marginTop20">
												<xsl:choose>
													<xsl:when test="$TimerCount">
														<div class="onMouseOver greenButton" id="startDiv" style="line-height:30px;width:100px;float:left;"
													 onclick="startTournamentRoundCounter('', 'divRoundTimeCount', '{$TimerCount}', '{$TournamentItemID}');">
															Start
														</div>
													</xsl:when>
													<xsl:otherwise>
														<div class="onMouseOver greenButton" id="startDiv" style="line-height:30px;width:100px;float:left;"
													 onclick="tournament_updateRoundTime('{$TournamentItemID}');">
															Start
														</div>
													</xsl:otherwise>
												</xsl:choose>
												<div id="disabledStartDiv" class="divNoteGradient whiteTextLarge" style="line-height:33px;width:100px;float:left;display:none;">
													Start
												</div>
												<div id="resetDiv" class="onMouseOver greenButton" style="line-height:30px;width:100px;float:right;display:none;"
													 onclick="tournament_updateRoundTime('{$TournamentItemID}');">
													Reset
												</div>
												<div id="disabledResetDiv" class="divNoteGradient whiteTextLarge" style="line-height:33px;width:100px;float:right;">
													Reset
												</div>
											</div>
										</xsl:otherwise>
									</xsl:choose>
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div style="width:780px;margin-top:15px;" align="center">
									<xsl:variable name="TeamsCount" select="count(AjaxRequest/TeamMatches/Match)"></xsl:variable>

									<xsl:for-each select="AjaxRequest/TeamMatches/Match">
										<xsl:variable name="divStyle">
											<xsl:choose>
												<xsl:when test="$TeamsCount = 1">
													<xsl:text></xsl:text>
												</xsl:when>
												<xsl:when test="position() mod 2 = 0">
													<xsl:text>float:right;</xsl:text>
												</xsl:when>
												<xsl:otherwise>
													<xsl:text>float:left;</xsl:text>
												</xsl:otherwise>
											</xsl:choose>
										</xsl:variable>

										<xsl:choose>
											<xsl:when test="WinnerTeamID = 0 and Team2 != -1">
												<div id="divGame_{position()}" style="{$divStyle}width:380px;height:170px;border:5px solid black;" align="center"
													 onmouseover="this.style.border= '5px solid red';" onmouseout="this.style.border='5px solid black';">
													<xsl:call-template name="TeamVSTeam">
														<xsl:with-param name="Team1Name" select="TeamName1"></xsl:with-param>
														<xsl:with-param name="Team2Name" select="TeamName2"></xsl:with-param>
														<xsl:with-param name="TeamID1" select="Team1"></xsl:with-param>
														<xsl:with-param name="TeamID2" select="Team2"></xsl:with-param>
														<xsl:with-param name="Round" select="Round"></xsl:with-param>
														<xsl:with-param name="TournamentItemID" select="$TournamentItemID"></xsl:with-param>
														<xsl:with-param name="WinnerTeamID" select="WinnerTeamID"></xsl:with-param>
													</xsl:call-template>
												</div>
											</xsl:when>
											<xsl:otherwise>
												<div id="divGame_{position()}" style="{$divStyle}width:380px;height:170px;border:5px solid black;" align="center">
													<xsl:call-template name="TeamVSTeam">
														<xsl:with-param name="Team1Name" select="TeamName1"></xsl:with-param>
														<xsl:with-param name="Team2Name" select="TeamName2"></xsl:with-param>
														<xsl:with-param name="TeamID1" select="Team1"></xsl:with-param>
														<xsl:with-param name="TeamID2" select="Team2"></xsl:with-param>
														<xsl:with-param name="Round" select="Round"></xsl:with-param>
														<xsl:with-param name="TournamentItemID" select="$TournamentItemID"></xsl:with-param>
														<xsl:with-param name="WinnerTeamID" select="WinnerTeamID"></xsl:with-param>
													</xsl:call-template>
												</div>
											</xsl:otherwise>
										</xsl:choose>
									</xsl:for-each>
								</div>
							</td>
						</tr>
						<tr>
							<td>
								<div align="center">
									<xsl:choose>
										<xsl:when test="$WinnerTeam">
											<div align="center" class="TournamentButtonGray marginBottom20 marginTop20 onMouseOver" style="width:200px;line-height:40px;"
												 onclick="getTournamentBracket('{$TournamentItemID}', '', 'divTournamentAdminContent');">
												<span>Return to Bracket</span>
											</div>
										</xsl:when>
										<xsl:otherwise>
											<div align="center" class="TournamentButtonGray marginBottom20 marginTop20 onMouseOver" style="width:200px;line-height:40px;"
										   onclick="startRound('{$TournamentItemID}', 'divTournamentBracketsContainer');">
												<span>Next Bracket</span>
											</div>
										</xsl:otherwise>
									</xsl:choose>
								</div>
							</td>
						</tr>
						<tr>
							<td>

							</td>
						</tr>
					</table>
				</td>
			</tr>
		</table>
	</xsl:template>

	<xsl:template name="TeamVSTeam">
		<xsl:param name="Team1Name" select="'N/A'"></xsl:param>
		<xsl:param name="Team2Name" select="'N/A'"></xsl:param>
		<xsl:param name="TeamID1" select="'N/A'"></xsl:param>
		<xsl:param name="TeamID2" select="'N/A'"></xsl:param>
		<xsl:param name="Round" select="'N/A'"></xsl:param>
		<xsl:param name="TournamentItemID" select="'N/A'"></xsl:param>
		<xsl:param name="WinnerTeamID" select="'N/A'"></xsl:param>

		<xsl:variable name="classTeam">
			<xsl:choose>
				<xsl:when test="$WinnerTeamID = 0 and $TeamID2 !=-1">
					<xsl:text>onMouseOver TournamentWinnerRound1BoxTeamName</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>TournamentSelectedWinnerRound1Box</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="classVS">
			<xsl:choose>
				<xsl:when test="$WinnerTeamID = 0 and $TeamID2 !=-1">
					<xsl:text>TournamentWinnerRound1BoxVS</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text>TournamentSelectedWinnerRound1Box</xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:variable name="textStrikeTeam1">
			<xsl:choose>
				<xsl:when test="$TeamID2 = $WinnerTeamID and $WinnerTeamID!=0">
					<xsl:text>text-decoration:line-through;</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text></xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
		<xsl:variable name="textStrikeTeam2">
			<xsl:choose>
				<xsl:when test="$TeamID1 = $WinnerTeamID and $WinnerTeamID!=0">
					<xsl:text>text-decoration:line-through;</xsl:text>
				</xsl:when>
				<xsl:otherwise>
					<xsl:text></xsl:text>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<div class="marginTop5 userWizardLabel">
			<xsl:value-of select="position()"/>
		</div>
		<div id="divTeam_{$TeamID1}" class="{$classTeam}" style="{$textStrikeTeam1}width:350px;overflow:hidden;" title="{$Team1Name}"
			 onClick="if({$WinnerTeamID} == 0 &#38; {$TeamID2} != -1)load_TournamentWinnerPopUp('{$TournamentItemID}','{$Round}','{$TeamID1}', '{$TeamID2}');">
			<xsl:value-of select="$Team1Name"/>
		</div>
		<div id="divVS_{$TeamID1}" class="{$classVS}">VS.</div>
		<div id="divTeam_{$TeamID2}" class="{$classTeam}" style="{$textStrikeTeam2}width:350px;overflow:hidden;" title="{$Team2Name}"
			 onClick="if({$WinnerTeamID} == 0 &#38; {$TeamID2} != -1)load_TournamentWinnerPopUp('{$TournamentItemID}','{$Round}','{$TeamID2}', '{$TeamID1}');">
			<xsl:value-of select="$Team2Name"/>
		</div>

	</xsl:template>
</xsl:stylesheet>
