var gameDetails;
var currentGameID;

function GameDetails(doc)
{
	var nodes;
	this.StartTime = doc.getElementsByTagName("StartTime")[0].firstChild.nodeValue;
	this.AwayTeam = doc.getElementsByTagName("AwayTeam")[0].firstChild.nodeValue;
	this.AwayTeamAbbrev = doc.getElementsByTagName("AwayTeamAbbrev")[0].firstChild.nodeValue;
	this.HomeTeam = doc.getElementsByTagName("HomeTeam")[0].firstChild.nodeValue;
	this.HomeTeamAbbrev = doc.getElementsByTagName("HomeTeamAbbrev")[0].firstChild.nodeValue;
	this.AwayWins = parseInt(doc.getElementsByTagName("AwayWins")[0].firstChild.nodeValue);
	this.AwayLosses = parseInt(doc.getElementsByTagName("AwayLosses")[0].firstChild.nodeValue);
	this.AwayTies = parseInt(doc.getElementsByTagName("AwayTies")[0].firstChild.nodeValue);
	this.HomeWins = parseInt(doc.getElementsByTagName("HomeWins")[0].firstChild.nodeValue);
	this.HomeLosses = parseInt(doc.getElementsByTagName("HomeLosses")[0].firstChild.nodeValue);
	this.HomeTies = parseInt(doc.getElementsByTagName("HomeTies")[0].firstChild.nodeValue);
	if (currentSportID == 3 || currentSportID == 5)
	{
		this.AwayRank = parseInt(doc.getElementsByTagName("AwayRank")[0].firstChild.nodeValue);
		this.HomeRank = parseInt(doc.getElementsByTagName("HomeRank")[0].firstChild.nodeValue);
	}
	this.AwayScore = parseInt(doc.getElementsByTagName("AwayScore")[0].firstChild.nodeValue);
	this.HomeScore = parseInt(doc.getElementsByTagName("HomeScore")[0].firstChild.nodeValue);
	if (currentSportID == 1)
	{
		this.Period = doc.getElementsByTagName("Inning")[0].firstChild.nodeValue;
		this.Balls = parseInt(doc.getElementsByTagName("Balls")[0].firstChild.nodeValue);
		this.Strikes = parseInt(doc.getElementsByTagName("Strikes")[0].firstChild.nodeValue);
		this.Outs = parseInt(doc.getElementsByTagName("Outs")[0].firstChild.nodeValue);
		nodes = doc.getElementsByTagName("Runners");
		if (nodes.length == 1)
		{
		  if (nodes[0].childNodes.length == 1)
		  {
			  this.Runners = nodes[0].firstChild.nodeValue;
		  }
		  else
		  {
		    this.Runners = "";
		  }
		}
		nodes = doc.getElementsByTagName("AwayPitcher");
		if (nodes.length == 1)
		{
			this.AwayPitcher = nodes[0].firstChild.nodeValue;
		}
		nodes = doc.getElementsByTagName("HomePitcher");
		if (nodes.length == 1)
		{
			this.HomePitcher = nodes[0].firstChild.nodeValue;
		}
		nodes = doc.getElementsByTagName("CurrentBatter");
		if (nodes.length == 1)
		{
			this.CurrentBatter = nodes[0].firstChild.nodeValue;
		}
		nodes = doc.getElementsByTagName("CurrentPitcher");
		if (nodes.length == 1)
		{
			this.CurrentPitcher = nodes[0].firstChild.nodeValue;
		}
	}
	else if (currentSportID == 6)
	{
		this.Period = doc.getElementsByTagName("Period")[0].firstChild.nodeValue;
		this.TimeRemaining = parseInt(doc.getElementsByTagName("TimeRemaining")[0].firstChild.nodeValue);
	}
	else if (currentSportID == 7)
	{
		this.Period = doc.getElementsByTagName("Period")[0].firstChild.nodeValue;
		this.TimeElapsed = parseInt(doc.getElementsByTagName("TimeRemaining")[0].firstChild.nodeValue);
	}
	else
	{
		this.Period = doc.getElementsByTagName("Quarter")[0].firstChild.nodeValue;
		this.TimeRemaining = parseInt(doc.getElementsByTagName("TimeRemaining")[0].firstChild.nodeValue);
	}
	if (currentSportID == 2 || currentSportID == 3)
	{
		this.Down = parseInt(doc.getElementsByTagName("Down")[0].firstChild.nodeValue);
		this.YardsToGo = parseInt(doc.getElementsByTagName("YardsToGo")[0].firstChild.nodeValue);
		nodes = doc.getElementsByTagName("BallSpotField");
		if (nodes.length == 1)
		{
			this.BallSpotField = nodes[0].firstChild.nodeValue;
			this.BallSpotYard = parseInt(doc.getElementsByTagName("BallSpotYard")[0].firstChild.nodeValue);
		}
		nodes = doc.getElementsByTagName("LastPlay");
		if (nodes.length == 1)
		{
			this.LastPlay = nodes[0].firstChild.nodeValue;
		}
	}
	nodes = doc.getElementsByTagName("Possession");
	if (nodes.length == 1)
	{
		this.Possession = nodes[0].firstChild.nodeValue;
	}
	nodes = doc.getElementsByTagName("Favorite");
	if (nodes.length == 1)
	{
		this.Favorite = nodes[0].firstChild.nodeValue;
		this.Line = parseFloat(doc.getElementsByTagName("Line")[0].firstChild.nodeValue);
		this.OverUnder = parseFloat(doc.getElementsByTagName("OverUnder")[0].firstChild.nodeValue);
	}
	var node = doc.getElementsByTagName("PeriodScores")[0];
	if (node.hasChildNodes())
	{
		this.Periods = new Array();
		var j = 0;
		for (var i = 0; i < node.childNodes.length; i++)
		{
			if (node.childNodes[i].nodeType == document.ELEMENT_NODE)
			{
				this.Periods[j] = new PeriodScore(node.childNodes[i]);
				j++;
			}
		}
	}
}

function PeriodScore(node)
{
	this.Period = node.attributes["Period"].value;
	this.AwayScore = parseInt(node.attributes["AwayScore"].value);
	this.HomeScore = parseInt(node.attributes["HomeScore"].value);
	this.Played = node.getAttribute("Played");
}

function setupGameDetails(gameID)
{
	currentGameID = gameID;
	loaded = false;
	clearTimeout(timeoutID);
	getGameDetails();
}

function getGameDetails()
{
	xmlRequest.open("POST", wsUrl + "/GetGameDetails");
	xmlRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	xmlRequest.send("sport=" + currentSportID + "&gameID=" + currentGameID);
}

function loadGameDetails(doc)
{
	gameDetails = new GameDetails(doc);
	if (gameDetails.Period.indexOf("Final") >= 0)
		clearTimeout(timeoutID);
}

function displayGameDetails()
{
	var p, span, br, hr, div;
	var table, tr, th, td;
	var startPeriod = 0;
	var text;
	var divDetails = document.getElementById("gameDetails");
	if (gameDetails.Period == "NA" || gameDetails.Period == "Cancelled" || gameDetails.Period == "Postponed")
	{
	  if (gameDetails.Period == "NA")
		  divDetails.className = "notStarted";
		else
		  divDetails.className = "canceled";
		br = document.createElement("br");
		divDetails.appendChild(br);
		p = document.createElement("p");
		p.align = "center";
		span = document.createElement("span");
		span.className = "team";
		span.innerText = gameDetails.AwayTeam;
		p.appendChild(span);
		if (currentSportID == 1)
		{
			if (gameDetails.AwayPitcher != null)
			{
				span = document.createElement("span");
				span.innerText = " (" + gameDetails.AwayPitcher + ")";
				p.appendChild(span);
			}
		}
		else
		{
			if (gameDetails.AwayWins > 0 || gameDetails.AwayLosses > 0)
			{
				span = document.createElement("span");
				if (currentSportID == 6)
					span.innerText = " (" + gameDetails.AwayWins + "-" + gameDetails.AwayLosses + "-" + gameDetails.AwayTies + ")";
				else
					span.innerText = " (" + gameDetails.AwayWins + "-" + gameDetails.AwayLosses + ")";
				p.appendChild(span);
			}
		}
		br = document.createElement("br");
		p.appendChild(br);
		span = document.createElement("span");
		span.innerText = "vs.";
		p.appendChild(span);
		br = document.createElement("br");
		p.appendChild(br);
		span = document.createElement("span");
		span.className = "team";
		span.innerText = gameDetails.HomeTeam;
		p.appendChild(span);
		if (currentSportID == 1)
		{
			if (gameDetails.HomePitcher != null)
			{
				span = document.createElement("span");
				span.innerText = " (" + gameDetails.HomePitcher + ")";
				p.appendChild(span);
			}
		}
		else
		{
			if (gameDetails.HomeWins > 0 || gameDetails.HomeLosses > 0)
			{
				span = document.createElement("span");
				if (currentSportID == 6)
					span.innerText = " (" + gameDetails.HomeWins + "-" + gameDetails.HomeLosses + "-" + gameDetails.HomeTies + ")";
				else
					span.innerText = " (" + gameDetails.HomeWins + "-" + gameDetails.HomeLosses + ")";
				p.appendChild(span);
			}
		}
		br = document.createElement("br");
		p.appendChild(br);
		br = document.createElement("br");
		p.appendChild(br);
		span = document.createElement("span");
		span.className = "date";
		if (gameDetails.Period == "NA")
		  span.innerText = gameDetails.StartTime;
		else
		  span.innerText = gameDetails.Period;
		p.appendChild(span);
		divDetails.appendChild(p);
		
		if (gameDetails.Period == "NA" && gameDetails.Favorite != null)
		{
			divDetails.style.height = "170px";
			hr = document.createElement("hr");
			divDetails.appendChild(hr);
			table = document.createElement("table");
			table.width = "100%";
			tr = table.insertRow(-1);
			td = tr.insertCell(-1);
			td.width = "60%";
			span = document.createElement("span");
			span.className = "lineLabel";
			span.innerText = "Line: ";
			td.appendChild(span);
			span = document.createElement("span");
			span.className = "line";
			if (gameDetails.Line == 0)
			{
				span.innerText = "EVEN";
			}
			else
			{
				if (currentSportID == 1)
				{
					span.innerText = gameDetails.Favorite + " " + gameDetails.Line;
				}
				else
				{
					span.innerText = gameDetails.Favorite + " by ";
					if (gameDetails.Line > parseInt(gameDetails.Line))
					{
						span.innerHTML += parseInt(gameDetails.Line) + "&frac12;";
					}
					else
					{
						span.innerText += gameDetails.Line;
					}
				}
			}
			td.appendChild(span);
			if (gameDetails.OverUnder > 0)
			{
				td = tr.insertCell(-1);
				span = document.createElement("span");
				span.className = "lineLabel";
				span.innerText = "O/U: ";
				td.appendChild(span);
				span = document.createElement("span");
				span.className = "line";
				if (gameDetails.OverUnder > parseInt(gameDetails.OverUnder))
				{
					span.innerHTML = parseInt(gameDetails.OverUnder) + "&frac12;";
				}
				else
				{
					span.innerText = gameDetails.OverUnder;
				}
				td.appendChild(span);
			}
			divDetails.appendChild(table);
		}
		else
		{
			divDetails.style.height = "130px";
		}
	}
	else
	{
		divDetails.style.height = "140px";
		if (gameDetails.Period.indexOf("Final") >= 0 || gameDetails.Period.indexOf("Suspended") >= 0)
		{
			divDetails.className = "completed";
		}
		else
		{
			divDetails.className = "inProgress";
		}
		br = document.createElement("br");
		divDetails.appendChild(br);
		br = document.createElement("br");
		divDetails.appendChild(br);
		table = document.createElement("table");
		table.className = "lineScore";
		table.cellPadding = "2";
		tr = table.insertRow(-1);
		th = document.createElement("th");
		tr.appendChild(th);
		if (gameDetails.Periods != null)
		{
			if (gameDetails.Periods.length > 10) startPeriod = gameDetails.Periods.length - 10;
			for (var i = startPeriod; i < gameDetails.Periods.length; i++)
			{
				th = document.createElement("th");
				th.innerText = gameDetails.Periods[i].Period;
				tr.appendChild(th);
			}
		}
		th = document.createElement("th");
		th.innerText = "Total";
		tr.appendChild(th);
		
		var trAway = table.insertRow(-1);
		th = document.createElement("th");
		th.align = "left";
		th.innerText = gameDetails.AwayTeam;
		trAway.appendChild(th);
		var trHome = table.insertRow(-1);
		th = document.createElement("th");
		th.align = "left";
		th.innerText = gameDetails.HomeTeam;
		trHome.appendChild(th);
		if (gameDetails.Periods != null)
		{
			var x;
			if (gameDetails.Period.indexOf("Final") == -1 && gameDetails.Period.indexOf("OT") == -1)
			{
				if (currentSportID == 1)
				{
					x = gameDetails.Period.substring(4, gameDetails.Period.length - 2);
				}
				else
				{
					if (gameDetails.Period.indexOf("Half") == 0)
					{	
						if (currentSportID == 5)
							x = 1;
						else
							x = 2;
					}
					else if (gameDetails.Period.indexOf("End") == 0)
					{
						x = gameDetails.Period.substring(4, 5);
					}
					else
					{
						x = gameDetails.Period.substring(0, 1);
					}
				}
			}
			for (var i = startPeriod; i < gameDetails.Periods.length; i++)
			{
				var tdAway = trAway.insertCell(-1);
				var tdHome = trHome.insertCell(-1);
				if (currentSportID == 1)
				{
					if (gameDetails.Periods[i].Played == null || gameDetails.Periods[i].Played == "Y")
					{
						tdAway.innerText = gameDetails.Periods[i].AwayScore;
						tdHome.innerText = gameDetails.Periods[i].HomeScore;
					}
					else if (gameDetails.Periods[i].Played == "A")
					{
						tdAway.innerText = gameDetails.Periods[i].AwayScore;
						if (gameDetails.Period.indexOf("Final") == 0 && i == gameDetails.Periods.length - 1)
							tdHome.innerText = "X";
					}
					if (!isNaN(x) && !isNaN(gameDetails.Periods[i].Period))
					{
						if (parseInt(x) == parseInt(gameDetails.Periods[i].Period))
						{
							if (gameDetails.Period.indexOf("Top") == 0) 
								tdAway.className = "active";
							else if (gameDetails.Period.indexOf("Bot") == 0) 
								tdHome.className = "active";
						}
					}
				}
				else
				{
					if (!isNaN(x) && !isNaN(gameDetails.Periods[i].Period))
					{
						if (parseInt(x) >= parseInt(gameDetails.Periods[i].Period))
						{
							if (currentSportID == 1 && parseInt(x) == parseInt(gameDetails.Periods[i].Period))
							{
								tdAway.innerText = gameDetails.Periods[i].AwayScore;
								if (gameDetails.Period.indexOf("Top") == 0) tdAway.className = "active";
								if (gameDetails.Period.indexOf("Bot") == 0 || gameDetails.Period.indexOf("End") == 0)
								{
									tdHome.innerText = gameDetails.Periods[i].HomeScore;
									if (gameDetails.Period.indexOf("Bot") == 0) tdHome.className = "active";
								}
							}
							else
							{
								tdAway.innerText = gameDetails.Periods[i].AwayScore;
								tdHome.innerText = gameDetails.Periods[i].HomeScore;
							}
						}
					}
					else
					{
						if (gameDetails.Periods[i].Period == "SO")
						{
							tdAway.innerText = "(" + gameDetails.Periods[i].AwayScore + ")";
							tdHome.innerText = "(" + gameDetails.Periods[i].HomeScore + ")";
						}
						else
						{
							tdAway.innerText = gameDetails.Periods[i].AwayScore;
							tdHome.innerText = gameDetails.Periods[i].HomeScore;
						}
					}
				}
			}
		}
		tdAway = trAway.insertCell(-1);
	  tdAway.className = "total";
	  tdAway.innerText = gameDetails.AwayScore;
	  tdHome = trHome.insertCell(-1);
	  tdHome.className = "total";
	  tdHome.innerText = gameDetails.HomeScore;
		if (gameDetails.Period.indexOf("Final") >= 0)
		{
		  if (gameDetails.AwayScore > gameDetails.HomeScore)
		  {
		    trAway.className = "win";
		  }
		  else if (gameDetails.HomeScore > gameDetails.AwayScore)
		  {
		    trHome.className = "win";
		  }
		}
		else
		{
			if (gameDetails.Possession == "A" || gameDetails.Possession == "H")
			{
				var img = new Image();
				img.src = imagePrefix + "FootballIcon.png";
				if (gameDetails.Possession == "A")
				{
					trAway.cells[0].innerText += " ";
					trAway.cells[0].appendChild(img);
				}
				else if (gameDetails.Possession == "H")
				{
					trHome.cells[0].innerText += " ";
					trHome.cells[0].appendChild(img);
				}
			}
		}
		divDetails.appendChild(table);
		
		div = document.createElement("div");
		table = document.createElement("table");
		table.className = "status";
		table.align = "center";
		table.cellSpacing = 5;
		if (gameDetails.Period.indexOf("Final") >= 0 || gameDetails.Period.indexOf("Suspended") >= 0)
		{
		  tr = table.insertRow(-1);
			td = tr.insertCell(-1);
			td.innerText = gameDetails.Period;
		}
		else
		{
			if (currentSportID != 1)
			{
				tr = table.insertRow(-1);
				if (gameDetails.Period.indexOf("Half") == 0)
				{
					td = tr.insertCell(-1);
					td.className = "value";
					td.innerText = "Halftime";
				}
				else
				{
					td = tr.insertCell(-1);
					if (currentSportID == 7)
					{
            td = tr.insertCell(-1);
					  td.innerText = "Elapsed Time:";
					  td = tr.insertCell(-1);
					  td.className = "value";
					  var minutes = Math.floor(gameDetails.TimeElapsed / 60);
					  var seconds = gameDetails.TimeElapsed - minutes * 60;
					  if (seconds < 10) seconds = 0 + "" + seconds;
					  td.innerText = minutes + ":" + seconds;		
					}
					else
					{
					  if (currentSportID == 5 || currentSportID == 6)
					  {
						  td.innerText = "Per:";
					  }
					  else
					  {
						  td.innerText = "Qtr:";
					  }
					  td = tr.insertCell(-1);
					  td.className = "value";
					  if (!isNaN(gameDetails.Period.substring(0, 1)) && gameDetails.Period.indexOf("OT") == -1)
					  {
						  td.innerText = gameDetails.Period.substring(0, 1);
					  }
					  else
					  {
						  td.innerText = gameDetails.Period;
					  }
					  if (gameDetails.Period.indexOf("End") == -1)
					  {
						  td = tr.insertCell(-1);
						  td.innerText = "Time:";
						  td = tr.insertCell(-1);
						  td.className = "value";
						  var minutes = Math.floor(gameDetails.TimeRemaining / 60);
						  var seconds = gameDetails.TimeRemaining - minutes * 60;
						  if (seconds < 10) seconds = 0 + "" + seconds;
						  td.innerText = minutes + ":" + seconds;				
					  }
					}
				}
			}
		}
		div.appendChild(table);
		divDetails.appendChild(div);
		
		if (currentSportID == 1 && gameDetails.Period.indexOf("Final") == -1 && gameDetails.Period.indexOf("Suspended") == -1)
		{
			divDetails.style.height = "180px";
			div = document.createElement("div");
			div.className = "mlbDetail";
			var subDiv = document.createElement("div");
			subDiv.className = "counts";
			table = document.createElement("table");
			tr = table.insertRow(-1);
			td = tr.insertCell(-1);
			td.innerText = "Inning:";
			td = tr.insertCell(-1);
			td.className = "value";
			td.innerText = gameDetails.Period;
			tr = table.insertRow(-1);
			td = tr.insertCell(-1);
			td.innerText = "Balls:";
			td = tr.insertCell(-1);
			var countImages = new Array();
			for (var i = 0; i < 3; i++)
			{
				countImages[i] = new Image();
				td.appendChild(countImages[i]);
			}
			if (gameDetails.Period.indexOf("Top") == 0 || gameDetails.Period.indexOf("Bot") == 0)
			{
				countImages[0].src = imagePrefix + "Circle" + (gameDetails.Balls > 0 ? "On" : "Off") + ".gif";
				countImages[1].src = imagePrefix + "Circle" + (gameDetails.Balls > 1 ? "On" : "Off") + ".gif";
				countImages[2].src = imagePrefix + "Circle" + (gameDetails.Balls > 2 ? "On" : "Off") + ".gif";
			}
			else
			{
				countImages[0].src = imagePrefix + "CircleOff.gif";
				countImages[1].src = imagePrefix + "CircleOff.gif";
				countImages[2].src = imagePrefix + "CircleOff.gif";
			}
			tr = table.insertRow(-1);
			td = tr.insertCell(-1);
			td.innerText = "Strikes:";
			td = tr.insertCell(-1);
			countImages = new Array();
			for (var i = 0; i < 2; i++)
			{
				countImages[i] = new Image();
				td.appendChild(countImages[i]);
			}
			if (gameDetails.Period.indexOf("Top") == 0 || gameDetails.Period.indexOf("Bot") == 0)
			{
				countImages[0].src = imagePrefix + "Circle" + (gameDetails.Strikes > 0 ? "On" : "Off") + ".gif";
				countImages[1].src = imagePrefix + "Circle" + (gameDetails.Strikes > 1 ? "On" : "Off") + ".gif";
			}
			else
			{
				countImages[0].src = imagePrefix + "CircleOff.gif";
				countImages[1].src = imagePrefix + "CircleOff.gif";
			}
			tr = table.insertRow(-1);
			td = tr.insertCell(-1);
			td.innerText = "Outs:";
			td = tr.insertCell(-1);
			countImages = new Array();
			for (var i = 0; i < 2; i++)
			{
				countImages[i] = new Image();
				td.appendChild(countImages[i]);
			}
			if (gameDetails.Period.indexOf("Top") == 0 || gameDetails.Period.indexOf("Bot") == 0)
			{
				countImages[0].src = imagePrefix + "Circle" + (gameDetails.Outs > 0 ? "On" : "Off") + ".gif";
				countImages[1].src = imagePrefix + "Circle" + (gameDetails.Outs > 1 ? "On" : "Off") + ".gif";
			}
			else
			{
				countImages[0].src = imagePrefix + "CircleOff.gif";
				countImages[1].src = imagePrefix + "CircleOff.gif";
			}
			subDiv.appendChild(table);
			div.appendChild(subDiv);
			
			subDiv = document.createElement("div");
			subDiv.className = "players";
			if (gameDetails.Runners != null)
			{
				subDiv2 = document.createElement("div");
				subDiv2.className = "runners";
				if (gameDetails.Runners.indexOf("1") >= 0)
				{
					img = new Image();
					img.src = imagePrefix + "base.gif";
					img.style.position = "absolute";
					img.style.top = "123px";
					img.style.left = "213px";
					subDiv2.appendChild(img);
				}
				if (gameDetails.Runners.indexOf("2") >= 0)
				{
					img = new Image();
					img.src = imagePrefix + "base.gif";
					img.style.position = "absolute";
					img.style.top = "108px";
					img.style.left = "199px";
					subDiv2.appendChild(img);
				}
				if (gameDetails.Runners.indexOf("3") >= 0)
				{
					img = new Image();
					img.src = imagePrefix + "base.gif";
					img.style.position = "absolute";
					img.style.top = "123px";
					img.style.left = "185px";
					subDiv2.appendChild(img);
				}
				subDiv.appendChild(subDiv2);
			}
			if (gameDetails.CurrentBatter != null || gameDetails.CurrentPitcher != null)
			{
				subDiv2 = document.createElement("div");
				subDiv2.className = "bp";
				subDiv2.innerHTML = "Batting: ";
				if (gameDetails.CurrentBatter != null)
					subDiv2.innerHTML += "<b>" + gameDetails.CurrentBatter + "</b>";
				subDiv2.innerHTML += "<br/>Pitching: ";
				if (gameDetails.CurrentPitcher != null)
					subDiv2.innerHTML += "<b>" + gameDetails.CurrentPitcher + "</b>";
				subDiv.appendChild(subDiv2);
			}
			
			div.appendChild(subDiv);
			divDetails.appendChild(div);
		}
		else if ((currentSportID == 2 || currentSportID == 3) && gameDetails.Period.indexOf("Final") == -1)
		{
			divDetails.style.height = "200px";
			div = document.createElement("div");
			div.className = "fbSpot";
			div.align = "center";
			var img = new Image();
			img.src = imagePrefix + "FootballField.gif";
			div.appendChild(img);
			var divTeams = document.createElement("div");
			divTeams.className = "teams";
			span = document.createElement("span");
			span.className = "away";
			if (gameDetails.Possession == "A")
				span.className += " possession";
			span.innerText = gameDetails.AwayTeamAbbrev;
			divTeams.appendChild(span);
			span = document.createElement("span");
			span.className = "home";
			if (gameDetails.Possession == "H")
				span.className += " possession";
			span.innerText = gameDetails.HomeTeamAbbrev;
			divTeams.appendChild(span);
			if (gameDetails.Down > 0)
			{
				span = document.createElement("span");
				switch (gameDetails.Down)
				{
					case 1:
						span.innerText = "1st";
						break;
					case 2:
						span.innerText = "2nd";
						break;
					case 3:
						span.innerText = "3rd";
						break;
					case 4:
						span.innerText = "4th";
						break;
				}
				span.innerText += " and ";
				if (gameDetails.Possession != gameDetails.BallSpotField && gameDetails.YardsToGo == gameDetails.BallSpotYard)
					span.innerText += "Goal";
				else
					span.innerText += gameDetails.YardsToGo;
				span.innerText += ", ";
				switch (gameDetails.BallSpotField)
				{
					case "A":
						span.innerText += gameDetails.AwayTeamAbbrev + " " + gameDetails.BallSpotYard;
						break;
					case "H":
						span.innerText += gameDetails.HomeTeamAbbrev + " " + gameDetails.BallSpotYard;
						break;
					case "N":
						span.innerText += "50 yard line";
						break;
				}
				divTeams.appendChild(span);
			}
			else if (gameDetails.LastPlay != null)
			{
				span = document.createElement("span");
				span.innerText = gameDetails.LastPlay;
				divTeams.appendChild(span);
			}
			div.appendChild(divTeams);
			if (gameDetails.BallSpotField != null && gameDetails.BallSpotYard != null)
			{
				img = new Image();
				img.src = imagePrefix + "FootballIcon.png";
				img.className = "ball";
				img.style.left = Math.round(getFootballSpot()) + "px";
				div.appendChild(img);
			}
			divDetails.appendChild(div);
		}
	}
	
}

function getFootballSpot()
{
	var divDetails = document.getElementById("gameDetails");
	var start = 25;
	switch (gameDetails.BallSpotField)
	{
		case "A":
			return start + gameDetails.BallSpotYard * 2.18;
		case "H":
			return start + (100 - gameDetails.BallSpotYard) * 2.18;
		case "N":
			return start + 50 * 2.18;
	}
}

function clearGameDetails()
{
	removeDetailsNodes();
	loaded = true;
	clearTimeout(timeoutID);
	getScores();
}

function removeDetailsNodes()
{
	var divDetails = document.getElementById("gameDetails");
	while (divDetails.childNodes.length > 3)
	{
		var child = divDetails.childNodes[3];
		removeChildNodes(child);
		divDetails.removeChild(child);
		child = null;
	}
}

