﻿//---------------------------------------------------------------------------------------------------
function setVal(element, value) {
	if (element.text() != value) {
		element.text(value);
		gAnimations.push(element);
	}
}

//---------------------------------------------------------------------------------------------------
function processHeader(dataNode) {
	var quarter = dataNode.attr("quarter");
	setVal($("#currentQuarter"), quarter > 4 ? lang["overtime"] + " " + (quarter - 4) : lang["quarter"] + " " + quarter);
	setVal($("#currentTime"), dataNode.attr("time"));
	setVal($("#competitionName"), dataNode.attr("competition"));
	if (dataNode.attr("logo") != "") {
		$("#compLogo").attr("src", dataNode.attr("logo"));
		$("#compLogo").load(function() {
			if ($(this).height() > 80) $(this).height(80);
		});
	}
	else {
		$("#compLogo").attr("src", "images/logo.png");
		$("#compLogo").removeAttr("height");
	}
	if (dataNode.attr("round")) {
		setVal($("#compRound"), dataNode.attr("round"));
		$("#compRound").height(15);
	}
	else {
		setVal($("#compRound"), "");
		$("#compRound").height(0);
	}

	processHeaderTeam(dataNode.find("TEAM:eq(0)"), "A");
	processHeaderTeam(dataNode.find("TEAM:eq(1)"), "B");

	// Set global variables for further modules
	gTeamNameA = dataNode.find("TEAM:eq(0)").attr("name");
	gTeamNameB = dataNode.find("TEAM:eq(1)").attr("name");

	// Quarter scores
	var qs = "";
	dataNode.find("QUARTER").each(function() {
		if (qs != "") qs = qs + "  ";
		qs = qs + $(this).attr("scoreA") + "-" + $(this).attr("scoreB");
	});
	setVal($("#quarterScores"), qs);
}

function processHeaderTeam(dataNode, team) {
	setVal($("#teamName" + team), dataNode.attr("name"));
	setVal($("#teamScore" + team), dataNode.attr("pts"));
	if (dataNode.attr("logo") != "") {
		$("#teamLogo" + team).show();
		$("#teamLogo" + team).attr("src", dataNode.attr("logo"));
	}
	else {
		$("#teamLogo" + team).hide();
	}
	setVal($("#teamFouls" + team), dataNode.attr("fouls"));
}

//---------------------------------------------------------------------------------------------------
function processScoreboard(dataNode) {
	if ($("#scrTableA").find("tr").length == 1 || $("#scrTableB").find("tr").length == 1) {
		createScoreboard($("#scrTableA"), dataNode.find("TEAM:eq(0)"), "A");
		createScoreboard($("#scrTableB"), dataNode.find("TEAM:eq(1)"), "B");
	}
	processScoreboardTeam(dataNode.find("TEAM:eq(0)"), "A");
	processScoreboardTeam(dataNode.find("TEAM:eq(1)"), "B");
}

function createScoreboard(root, dataNode, team) {
	$("#scrTable" + team).find("th:eq(0)").html(eval("gTeamName" + team));
	$(root).find("tr:gt(0)").remove();
	for (var index = 0; index <12; index++) {
		var tr = $("#scrTemplate").clone();
		$(tr).attr("id", "scr" + team + "_" + index);
		$(tr).find("td:eq(0)").attr("id", "scr" + team + "Number" + index);
		$(tr).find("td:eq(1)").attr("id", "scr" + team + "Name" + index);
		$(tr).find("td:eq(2)").attr("id", "scr" + team + "PTS" + index);
		$(tr).find("td:eq(3)").attr("id", "scr" + team + "REB" + index);
		$(tr).find("td:eq(4)").attr("id", "scr" + team + "AS" + index);
		$(tr).find("td:eq(5)").attr("id", "scr" + team + "PF" + index);
		root.append(tr);
	}
}

function processScoreboardTeam(dataNode, team) {
	dataNode.children().each(function(index) {
		if ($(this).attr("in")) {
			$("#scr" + team + "Number" + index).parent().addClass("active");
		}
		else {
			$("#scr" + team + "Number" + index).parent().removeClass("active");
		}
		$("#scr" + team + "Number" + index).html($(this).attr("no"));
		$("#scr" + team + "Name" + index).html($(this).attr("name"));
		$("#scr" + team + "Name" + index).unbind("click").click(function(e) {
			displayPlayerInfo(e, team + "." + $(dataNode).find("PLAYER:eq(" + index + ")").attr("no"));
		});
		var fouls = $(this).attr("pf") > 5 ? 5 : $(this).attr("pf");
		$("#scr" + team + "PF" + index).find("img").attr("src", "images/foul" + fouls +".png");
		setVal($("#scr" + team + "REB" + index + " span"), $(this).attr("reb"));
		setVal($("#scr" + team + "AS" + index + " span"), $(this).attr("as"));
		setVal($("#scr" + team + "PTS" + index + " span"), $(this).attr("pts"));
	});
	for (var i = dataNode.children().length; i < 12; i++) {
		$("#scr" + team + "_" + i).find("img").attr("src", "images/foul0.png");
		$("#scr" + team + "_" + i).find("td").not("td:eq(5)").text("");
	}
}

//---------------------------------------------------------------------------------------------------
function processTeamStats(dataNode) {
	processTeamStatsTeam(dataNode.find("TEAM:eq(0)"), "A");
	processTeamStatsTeam(dataNode.find("TEAM:eq(1)"), "B");
}

function processTeamStatsTeam(dataNode, team) {
	setVal($("#tsfg" + team), dataNode.attr("fgm") + "/" + dataNode.attr("fga") + " (" + dataNode.attr("fgp") + "%)");
	setVal($("#ts2p" + team), dataNode.attr("p2m") + "/" + dataNode.attr("p2a") + " (" + dataNode.attr("p2p") + "%)");
	setVal($("#ts3p" + team), dataNode.attr("p3m") + "/" + dataNode.attr("p3a") + " (" + dataNode.attr("p3p") + "%)");
	setVal($("#ts1p" + team), dataNode.attr("p1m") + "/" + dataNode.attr("p1a") + " (" + dataNode.attr("p1p") + "%)");
	setVal($("#tsreb" + team), dataNode.attr("rt") + " (" + dataNode.attr("ro") + "-" + dataNode.attr("rd") + ")");
	setVal($("#tsas" + team), dataNode.attr("as"));
	setVal($("#tsto" + team), dataNode.attr("to"));
	setVal($("#tspf" + team), dataNode.attr("pf"));
	setVal($("#tsst" + team), dataNode.attr("st"));
	setVal($("#tsbs" + team), dataNode.attr("bs"));
}

//---------------------------------------------------------------------------------------------------
function processOverview(dataNode) {
	// Remove finished games
	$(".ovGame").each(function () {
		var id = $(this).attr("id").substring(3);
		var status = $(this).parent().parent().attr("id").substring(16);
		var dataGame = $(dataNode).find("GAME[ID='" + id + "']");
		if (status != "" && (dataGame.length == 0 || status != dataGame.attr("Status"))) {
			$(this).remove();
		}
	});
	// Add/update games
	var activeCompetitionID = "";
	$(dataNode).find("GAME").each(function () {
		if ($(this).attr("ID") != gameID) {
			var status = $(this).attr("Status");
			var rootContainer = $("#overviewContent_" + status);
			if (rootContainer.find("#ovg" + $(this).attr("ID")).length == 0) {
				var compID = $(this).attr("CompID");
				if (rootContainer.find("#ovc" + compID).length == 0) {
					addOverviewCompetition(rootContainer, $(this), compID);
				}
				addOverviewGame(rootContainer, $(this));
			}
			updateOverviewGame($(this));
		}
		else {
			activeCompetitionID = $(this).attr("CompID");
		}
	});
	// TODO - remove empty competitions
	// Expand at least one competition
	for (var i in [0, 1, 2]) {
		var rootContainer = $("#overviewContent_" + i);
		if (rootContainer.find(".ovTitle2").length == 0) {
			var activeComp = rootContainer.find("#ovc" + activeCompetitionID);
			if (activeComp.length == 0) activeComp = rootContainer.find(".ovTitle:eq(0)").parent();
			switchOverview(activeComp.find(".ovTitle"));
		}
		if (rootContainer.find(".ovGame").length == 0) {
			$("#ovMenu").find("td:eq(" + i + ")").removeClass("active").addClass("disabled");
			if (i == currentOvMode) currentOvMode = -1;
		}
		else {
			if (i == 1 && $("#ovMenu").find("td:eq(1)").is(".disabled")) currentOvMode = -1;
			$("#ovMenu").find("td:eq(" + i + ")").removeClass("disabled");
		}
	}
	if (currentOvMode < 0) { // Initial load, guess which section to open first
		if ($("#overviewContent_1 .ovGame").length > 0) currentOvMode = 1;
		else if ($("#overviewContent_0 .ovGame").length > 0) currentOvMode = 0;
		else currentOvMode = 2;
		tabOverview(currentOvMode);
	}
}

function updateOverviewGame(dataNode) {
	var gameNode = $("#ovg" + dataNode.attr("ID"));
	if (dataNode.attr("LogoA") != "") {
		$(gameNode).find("td.ovBg1:eq(0) img").attr("src", dataNode.attr("LogoA"));
	}
	$(gameNode).find("td.ovBg1:eq(1)").html(dataNode.attr("TeamA"));
	setVal($(gameNode).find("td.ovBig:eq(0)"), dataNode.attr("ScoreA"));
	var quarter = dataNode.attr("Quarter") > 4 ? lang["OT"] + (dataNode.attr("Quarter") - 4) : lang["Q"] + dataNode.attr("Quarter");
	setVal($(gameNode).find("td.ovBg2:eq(1)"), quarter + ", " + dataNode.attr("Time"));
	if (dataNode.attr("LogoB") != "") {
		$(gameNode).find("td.ovBg1:eq(2) img").attr("src", dataNode.attr("LogoB"));
	}
	$(gameNode).find("td.ovBg1:eq(3)").html(dataNode.attr("TeamB"));
	setVal($(gameNode).find("td.ovBig:eq(1)"), dataNode.attr("ScoreB"));
	if ($(dataNode).attr("Status") == 0) {
		var date = new Date(Date.parse("Jan 1, 1970 " + dataNode.attr("StartTime")));
		var text = date.toTimeStr();
		if ($(dataNode).attr("Timezone")) {
			var offset = new Date().getTimezoneOffset() / 60 + parseFloat($(dataNode).attr("Timezone"));
			if (offset != 0) {
				date.addHours(-offset);
				text = date.toTimeStr() + "<br /><small>(" + text + " " + lang['localtime'] + ")</small>";
			}
		}
		else {
			text = text + " " + lang['localtime'];
		}
		$(gameNode).find("td.ovBg3").html(text);
	}
}

function addOverviewCompetition(rootContainer, dataNode, compID) {
	var div = document.createElement("div");
	div.setAttribute("id", "ovc" + compID);
	rootContainer.append(div);
	var title = document.createElement("div");
	title.setAttribute("class", "ovTitle ovTitle1");
	title.appendChild(document.createTextNode(dataNode.attr("Competition")));
	$(div).append(title);
	$(title).click(function(node) {
		return function() {
			switchOverview(node);
		}
	} ($(title)));
}

function addOverviewGame(rootContainer, dataNode) {
	var compDiv = rootContainer.find("#ovc" + dataNode.attr("CompID"));
	var status = dataNode.attr("Status");
	var gameNode = $("#ovTemplate" + status).clone();
	gameNode.attr("id", "ovg" + dataNode.attr("ID"));
	var url = "Game.aspx?acc=" + accountID + "&gameID=" + dataNode.attr("ID") + "&lng=" + currentLanguage;
	if (status != 0) {
		gameNode.find("a").attr("href", url);
		gameNode.find("table").click(function () { // For IE
			window.location = url;
		});
	}
	compDiv.append(gameNode);
	if (compDiv.find(".ovTitle2").length > 0) {
		gameNode.show();
		gameNode.animate({ "height": "69px" });
	}
}

//---------------------------------------------------------------------------------------------------
function processBanner(dataNode) {
	if ($(dataNode).attr("file")) {
		if ($(dataNode).attr("file") != $("#banner > img").attr("src")) {
			$("#banner").animate({ "marginLeft": "-1500" }, "slow", null, function () {
				$("#banner").text("");
				$("#banner").append("<img />");
				$("#banner > img").attr("src", $(dataNode).attr("file"));
				animateBanner(dataNode);
			});
		}
	}
	else if ($(dataNode).text() != "") {
		if ($(dataNode).text() != $("#banner").html()) {
			$("#banner").animate({ "marginLeft": "-1500" }, "slow", null, function () {
				$("#banner").html($(dataNode).text());
				animateBanner(dataNode);
			});
		}
	}
	else {
		$("#banner").hide("slow");
	}
}

function animateBanner(dataNode) {
	$("#banner").animate({ "marginLeft": "0" }, { "duration": "slow" });
	if ($(dataNode).attr("link")) {
		$("#banner").addClass("link");
		$("#banner").unbind("click").click(function () {
			window.open($(dataNode).attr("link"), "_fe");
		});
	}
	else {
		$("#banner").removeClass("link");
		$("#banner").unbind("click");
	}
	$("#banner").show();
}

//---------------------------------------------------------------------------------------------------
function processPlaybyplay(dataNode, prefix) {
	if (pbpPaused && prefix == "big_") return;
	var animationEnabled = (dataNode.find("LINE").length <= PBP_LINES);
	var scroller = prefix == "big_" ? bigPbpScroller : pbpScroller;
	var container = $("#" + prefix + "pbpContainer");
	if (dataNode.find("LINE").length > 0) { // Hide lines with higher numbers than existing
		var num = 1 + parseInt(dataNode.find("LINE:eq(0)").attr("num"));
		container.find("#pbpLine0" + num).hide().removeClass("pbpLine");
	}
	$(dataNode.find("LINE").get().reverse()).each(function(i) {
		var num = 0 + $(this).attr("num");
		var lineNode = container.find("#pbpLine" + num);
		if (lineNode.length == 0) {
			lineNode = $("#pbpTemplate").clone();
			$(lineNode).attr("id", "pbpLine" + num);
			// Find where to insert the line
			var found = false;
			container.find(".pbpLine").each(function() {
				var lineNum = 0 + $(this).attr("id").substr(7);
				if (lineNum < num && !found) {
					$(this).before(lineNode);
					found = true;
				}
			});
			if (!found) {
				container.append(lineNode);
			}
		}
		lineNode.removeClass("pbpLine0 pbpLine1 pbpLine2").addClass("pbpLine" + $(this).attr("team"));
		lineNode.find("td:eq(0)").text($(this).attr("time"));
		if ($(this).attr("scoreA")) {
			lineNode.find("td:eq(1)").text($(this).attr("scoreA") + "-" + $(this).attr("scoreB"));
		}
		else {
			lineNode.find("td:eq(1)").text("");
		}
		lineNode.find("td:eq(2)").text($(this).attr("text"));
		if ($(this).attr("deleted") == 1) {
			lineNode.hide();
			lineNode.removeClass("pbpLine");
		}
		else {
			lineNode.addClass("pbpLine");
		}
	});
	var hiddenLines = container.find(".pbpLine:hidden");
	if (hiddenLines.length > 0 && animationEnabled) {
		hiddenLines.slideToggle("slow", function() {
			scroller.reset();
		});
	}
	else if (hiddenLines.length > 0 && !animationEnabled) {
		hiddenLines.show();
		scroller.reset();
	}
}

//---------------------------------------------------------------------------------------------------
function processBigOverview(dataNode) {
	var currentFilter = $("#filterCompetition option:selected").val();
	var currentMode = $("#filterMode option:selected").val();
	$("#filterCompetition").find("option").remove().end().append('<option value="">' + lang['allCompetitions'] + '</option>');
	var prevComp = "";
	var games = new Array();
	if (currentMode == "small" && $("#ovContainer").find(".ovGameBF").length > 0 || currentMode == "big" && $("#ovContainer").find(".ovGameBM").length > 0) {
		$("#ovContainer").text("");
	}
	var compID = $.QueryString["compID"];
	var comp_number = $.QueryString["comp_number"];
	$(dataNode).find("GAME").each(function() {
		if (compID && $(this).attr("CompID") != compID || comp_number && $(this).attr("CompCode") != comp_number) {
			return;
		}
		if ($(this).attr("Competition") != prevComp) {
			prevComp = $(this).attr("Competition");
			if (prevComp == currentFilter) {
				$("#filterCompetition").append('<option selected="selected" value="' + prevComp + '">' + prevComp + '</option>');
			}
			else {
				$("#filterCompetition").append('<option value="' + prevComp + '">' + prevComp + '</option>');
			}
		}
		if (!currentFilter || currentFilter == "" || $(this).attr("Competition") == currentFilter) {
			var gameNode = $("#ovContainer").find("#ovb" + $(this).attr("ID"));
			if (gameNode.length == 0) {
				gameNode = addBigOverviewGame($(this), currentMode);
			}
			updateBigOverviewGame($(this), currentMode, gameNode);
			games.push(gameNode.attr("id"));
		}
	});
	// Remove finished games
	$("#ovContainer > div").each(function() {
		var id = $(this).attr("id");
		if ($.inArray(id, games) == -1) {
			$(this).remove();
		}
	});
}

function addBigOverviewGame(node, mode) {
	var gameNode = (mode == "big") ? $("#bigOverviewTemplateFull").clone() : gameNode = $("#bigOverviewTemplate").clone();
	$(gameNode).attr("id", "ovb" + node.attr("ID"));
	$(gameNode).css("display", "inline");
	var url = "Game.aspx?acc=" + accountID + "&gameID=" + node.attr("ID") + "&lng=" + currentLanguage;
	$(gameNode).find("a").attr("href", url);
	$(gameNode).click(function () { // For IE
		window.location = url;
	});
	$("#ovContainer").append(gameNode);
	return $(gameNode);
}

function updateBigOverviewGame(node, mode, gameNode) {
	if (mode == "big") {
		gameNode.find(".title").text(node.attr("Competition"));
		gameNode.find(".teamname:eq(0)").html(node.attr("TeamA"));
		gameNode.find(".teamname:eq(1)").html(node.attr("TeamB"));
		setVal($(gameNode).find(".ovScore:eq(0)"), node.attr("ScoreA"));
		setVal($(gameNode).find(".ovScore:eq(1)"), node.attr("ScoreB"));
		var quarter = node.attr("Quarter");
		setVal(gameNode.find(".ovTime"), (quarter > 4 ? lang["OT"] + (quarter - 4) : lang["Q"] + quarter) + ", " + node.attr("Time"));
		// Leaders
		var leadNode = node.find("PLAYER:eq(0)");
		if (leadNode.length > 0) {
			gameNode.find(".ovLeader:eq(0)").html("<b>" + leadNode.attr("name") + "</b><br />" + leadNode.attr("pts") + " " + lang["Pts"] + ", " + leadNode.attr("reb") + " " + lang["Reb"] + ", " + leadNode.attr("as") + " " + lang["AS"]);
		}
		else {
			gameNode.find(".ovLeader:eq(0)").text("");
		}
		var leadNode = node.find("PLAYER:eq(1)");
		if (leadNode.length > 0) {
			gameNode.find(".ovLeader:eq(1)").html("<b>" + leadNode.attr("name") + "</b><br />" + leadNode.attr("pts") + " " + lang["Pts"] + ", " + leadNode.attr("reb") + " " + lang["Reb"] + ", " + leadNode.attr("as") + " " + lang["AS"]);
		}
		else {
			gameNode.find(".ovLeader:eq(1)").text("");
		}
		// PBP
		for (i = 0; i < 3; i++) {
			var dataNode = node.find("LINE:eq(" + i + ")");
			var targetNode = gameNode.find(".pbpLine tr:eq(" + i + ")");
			if (dataNode.length > 0) {
				targetNode.find("td:eq(0)").text(dataNode.attr("time"));
				if (node.attr("scoreA")) {
					targetNode.find("td:eq(1)").text(dataNode.attr("scoreA") + "-" + dataNode.attr("scoreB"));
				}
				else {
					targetNode.find("td:eq(1)").text("");
				}
				targetNode.find("td:eq(2)").text(dataNode.attr("text"));
				targetNode.addClass("pbpLine" + dataNode.attr("team"));
			}
			else {
				targetNode.find("td").html("&nbsp;");
			}
		}
	}
	else {
		gameNode.find(".ovTitle").text(node.attr("Competition"));
		if (node.attr("LogoA") != "") {
			gameNode.find("td:eq(0) img").attr("src", node.attr("LogoA"));
		}
		gameNode.find("td:eq(1)").html(node.attr("TeamA"));
		setVal(gameNode.find("td:eq(2)"), node.attr("ScoreA"));
		var quarter = node.attr("Quarter") > 4 ? lang["OT"] + (node.attr("Quarter") - 4) : lang["Q"] + node.attr("Quarter");
		setVal(gameNode.find("td:eq(4)"), quarter + ", " + node.attr("Time"));
		if (node.attr("LogoB") != "") {
			gameNode.find("td:eq(6) img").attr("src", node.attr("LogoB"));
		}
		gameNode.find("td:eq(7)").html(node.attr("TeamB"));
		setVal(gameNode.find("td:eq(8)"), node.attr("ScoreB"));
	}
}

//---------------------------------------------------------------------------------------------------
function processScoreDevelopment(dataNode) {
	$("#develContainer").text("");
	$("#devTeamNameA").text(gTeamNameA);
	$("#devTeamNameB").text(gTeamNameB);
	var jg = new jsGraphics("develContainer");
	var dW = $("#develContainer").width();
	var dH = $("#develContainer").height();

	// Minute notches
	var lastMinute = $(dataNode).find("SEC:last").attr("Number") / 60;
	var maxMinutes = Math.ceil(lastMinute * 2 / 10) * 5;
	var minuteInterval = (dW - 30) / maxMinutes;
	var minutesStep = maxMinutes > 10 ? 5 : 1;
	for (i = minutesStep; i <= maxMinutes; i += minutesStep) {
		var notch = document.createElement("div");
		$(notch).addClass("develNotch");
		$(notch).text(i);
		$("#develContainer").append(notch);
		$(notch).css("left", i * minuteInterval);
		$(notch).css("top", dH);
	}

	var maxPoints = Math.max($(dataNode).find("SEC:last").attr("ScoreA"), $(dataNode).find("SEC:last").attr("ScoreB"));
	maxPoints = Math.ceil(maxPoints / 10) * 10;
	var pointInterval = (dH - 30) / maxPoints;
	var pointStep = maxPoints > 50 ? 10 : (maxPoints > 10 ? 5 : 1);
	for (i = pointStep; i <= maxPoints; i += pointStep) {
		var notch = document.createElement("div");
		$(notch).addClass("develNotch");
		$(notch).text(i);
		$("#develContainer").append(notch);
		$(notch).css("right", dW + 5);
		$(notch).css("top", dH - i * pointInterval);
	}

	// Draw graph
	var coordXA = new Array(500);
	var coordYA = new Array(500);
	var coordXB = new Array(500);
	var coordYB = new Array(500);
	$(dataNode).find("SEC").each(function (i) {
		coordXA[i] = Math.round($(this).attr("Number") / 60 * minuteInterval + 2);
		coordYA[i] = dH - Math.round($(this).attr("ScoreA") * pointInterval + 2);
		coordXB[i] = Math.round($(this).attr("Number") / 60 * minuteInterval + 2);
		coordYB[i] = dH - Math.round($(this).attr("ScoreB") * pointInterval + 2);
	});

	// Draw maximum leads
	var maxLeadTimeA = parseInt($(dataNode).find("BiggestLeadTime").attr("ScoreA"));
	var maxLeadTimeB = parseInt($(dataNode).find("BiggestLeadTime").attr("ScoreB"));
	jg.setStroke(Stroke.DOTTED);
	$(dataNode).find("SEC").each(function (i) {
		if (maxLeadTimeA > 0 && maxLeadTimeA <= $(this).attr("Number")) {
			jg.setColor("#ffffff");
			jg.drawLine(coordXA[i], coordYA[i], coordXB[i], coordYB[i]);
			maxLeadTimeA = -1;
		}
		if (maxLeadTimeB > 0 && maxLeadTimeB <= $(this).attr("Number")) {
			jg.setColor("#" + rgb2hex($(".develRect2").css("background-color")));
			jg.drawLine(coordXA[i], coordYA[i], coordXB[i], coordYB[i]);
			maxLeadTimeB = -1;
		}
	});

	jg.setStroke(3);
	jg.setColor("#ffffff");
	jg.drawPolyLine(coordXA, coordYA);
	jg.setColor("#" + rgb2hex($(".develRect2").css("background-color")));
	jg.drawPolyLine(coordXB, coordYB);
	jg.paint();

	// Event handlers
	var moveFn = function (e) {
		var x = e.pageX - $("#develContainer").offset().left;
		var maxSec = $(dataNode).find("SEC:last").attr("Number");
		var second = Math.ceil(x / minuteInterval * 60); // Math.ceil(x * maxSec / (dW - 30));
		var node = [];
		$(dataNode).find("SEC").each(function () {
			if (second >= $(this).attr("Number")) {
				node = $(this);
			}
		});
		if (x > dW - 30 || node.length == 0 || second > maxSec) {
			$("#develMarker").hide();
		}
		else {
			var ms = "" + Math.floor(second / 60);
			if (ms.length < 2) ms = "0" + ms;
			var ss = "" + second % 60;
			if (ss.length < 2) ss = "0" + ss;
			$("#develMin").text(ms + ":" + ss);
			$("#develScore").text(node.attr("ScoreA") + "-" + node.attr("ScoreB"));
			$("#develMarker").css("left", x + 32);
			if (x > dW - 150) {
				$("#develNote").css("margin-left", "-150px");
			}
			else {
				$("#develNote").css("margin-left", "0px");
			}
			$("#develMarker").show();
		}
	};
	$("#develContainer").mousemove(moveFn);
	$("#develMarker").mousemove(moveFn);
	$("#develContainer").mouseleave(function() {
		$("#develMarker").hide();
	});
	$("#develMarker").mouseenter(function() {
		$("#develMarker").show();
	});

	// Extra data
	setVal($("#develTable tr:eq(1) td:eq(1) div"), $(dataNode).find("BiggestLead").attr("ScoreA"));
	setVal($("#develTable tr:eq(1) td:eq(2) div"), $(dataNode).find("BiggestLead").attr("ScoreB"));
	setVal($("#develTable tr:eq(2) td:eq(1) div"), $(dataNode).find("BiggestScoringRun").attr("ScoreA") + "-0");
	setVal($("#develTable tr:eq(2) td:eq(2) div"), "0-" + $(dataNode).find("BiggestLead").attr("ScoreB"));
	setVal($("#develTable tr:eq(3) td:eq(1) div"), $(dataNode).find("LeadChanges").text());
	setVal($("#develTable tr:eq(4) td:eq(1) div"), $(dataNode).find("TimesTied").text());
	setVal($("#develTable tr:eq(5) td:eq(1) div"), $(dataNode).find("TimeLeading").attr("ScoreA"));
	setVal($("#develTable tr:eq(5) td:eq(2) div"), $(dataNode).find("TimeLeading").attr("ScoreB"));
}

//---------------------------------------------------------------------------------------------------
function processStatsComparison(dataNode, parentElement) {
	if (parentElement.find(".scCell:visible").length == 0) {
		createStatsComparison(parentElement);
	}
	processStatsComparisonCategory(parentElement, dataNode, "fgp", "ball");
	processStatsComparisonCategory(parentElement, dataNode, "p1p", "ball");
	processStatsComparisonCategory(parentElement, dataNode, "rt", "bar");
	processStatsComparisonCategory(parentElement, dataNode, "fastb", "bar");
	processStatsComparisonCategory(parentElement, dataNode, "ptsto", "bar");
	processStatsComparisonCategory(parentElement, dataNode, "secpts", "bar");
	processStatsComparisonCategory(parentElement, dataNode, "p2p", "ball");
	processStatsComparisonCategory(parentElement, dataNode, "p3p", "ball");
	processStatsComparisonCategory(parentElement, dataNode, "to", "bar");
	processStatsComparisonCategory(parentElement, dataNode, "as", "bar");
	processStatsComparisonCategory(parentElement, dataNode, "pf", "bar");
	processStatsComparisonCategory(parentElement, dataNode, "st", "bar");
	processStatsComparisonCategory(parentElement, dataNode, "bs", "bar");
	processStatsComparisonCategory(parentElement, dataNode, "bench", "bar");
	processStatsComparisonCategory(parentElement, dataNode, "paint", "bar");
	scScroller.reset();
}

function processStatsComparisonCategory(parentElement, dataNode, category, type) {
	if (dataNode.children().length == 2 && dataNode.children().attr("name")) {
		var node1 = dataNode.find("TEAM:eq(0)");
		var node2 = dataNode.find("TEAM:eq(1)");
		parentElement.find("#scTn" + category + "_A").text(node1.attr("name"));
		parentElement.find("#scTn" + category + "_B").text(node2.attr("name"));
		if (type == "ball") {
			var prefix = category.substr(0, 2);
			parentElement.find("#sc" + category + "_A").html("<b>" + node1.attr(prefix + "p") + "%</b><br/>" + node1.attr(prefix + "m") + "/" + node1.attr(prefix + "a"));
			parentElement.find("#sc" + category + "_B").html("<b>" + node2.attr(prefix + "p") + "%</b><br/>" + node2.attr(prefix + "m") + "/" + node2.attr(prefix + "a"));
			parentElement.find("#scDiv" + category + "_A").animate({ "height": (0.8 * (100 - Math.round(node1.attr(category).replace(',', '.')))) + "px" }, { "duration": "slow" });
			parentElement.find("#scDiv" + category + "_B").animate({ "height": (0.8 * (100 - Math.round(node2.attr(category).replace(',', '.')))) + "px" }, { "duration": "slow" });
		}
		else if (type == "bar") {
			if (category == "rt") { // special handling for rebounds
				parentElement.find("#sc" + category + "_A").text(node1.attr("rt") + " (" + node1.attr("ro") + "-" + node1.attr("rd") + ")");
				parentElement.find("#sc" + category + "_B").text(node2.attr("rt") + " (" + node2.attr("ro") + "-" + node2.attr("rd") + ")");
			}
			else {
				parentElement.find("#sc" + category + "_A").text(node1.attr(category));
				parentElement.find("#sc" + category + "_B").text(node2.attr(category));
			}
			var maxVal = Math.max(node1.attr(category), node2.attr(category)) + 1;
			parentElement.find("#scDiv" + category + "_A").animate({ "height": (node1.attr(category) / maxVal * 90) + "%" }, { "duration": "slow" });
			parentElement.find("#scDiv" + category + "_B").animate({ "height": (node2.attr(category) / maxVal * 90) + "%" }, { "duration": "slow" });
		}
	}
}

function createStatsComparison(parentElement) {
	parentElement.append(createStatsNode("fgp", lang["L.FG"], "scTemplateBall"));
	parentElement.append(createStatsNode("p1p", lang["L.FT"], "scTemplateBall"));
	parentElement.append(createStatsNode("rt", lang["L.Reb"], "scTemplateBar"));
	parentElement.append(createStatsNode("fastb", lang["L.FastBreak"], "scTemplateBar"));
	parentElement.append(createStatsNode("ptsto", lang["L.FromTO"], "scTemplateBar"));
	parentElement.append(createStatsNode("secpts", lang["L.SecondChance"], "scTemplateBar"));
	parentElement.append(createStatsNode("p2p", "2 " + lang["S.Pts"] + " " + lang["L.FG"], "scTemplateBall"));
	parentElement.append(createStatsNode("p3p", "3 " + lang["S.Pts"] + " " + lang["L.FG"], "scTemplateBall"));
	parentElement.append(createStatsNode("to", lang["L.TO"], "scTemplateBar"));
	parentElement.append(createStatsNode("as", lang["L.AS"], "scTemplateBar"));
	parentElement.append(createStatsNode("pf", lang["L.PF"], "scTemplateBar"));
	parentElement.append(createStatsNode("st", lang["L.ST"], "scTemplateBar"));
	parentElement.append(createStatsNode("bs", lang["L.BS"], "scTemplateBar"));
	parentElement.append(createStatsNode("bench", lang["L.Bench"], "scTemplateBar"));
	parentElement.append(createStatsNode("paint", lang["L.Paint"], "scTemplateBar"));
}

function createStatsNode(id, title, template) {
	var node = $("#" + template).clone();
	$(node).attr("id", "sc" + id);
	$(node).find("th:eq(0)").attr("id", "scTn" + id + "_A");
	$(node).find("th:eq(1)").attr("id", "scTn" + id + "_B");
	$(node).find(".title > span").text(title);
	$(node).find(".bar1").attr("id", "scDiv" + id + "_A");
	$(node).find(".bar2").attr("id", "scDiv" + id + "_B");
	$(node).find(".bar1 > div").attr("id", "sc" + id + "_A");
	$(node).find(".bar2 > div").attr("id", "sc" + id + "_B");
	$(node).find(".ball1 > .shadow").attr("id", "scDiv" + id + "_A");
	$(node).find(".ball2 > .shadow").attr("id", "scDiv" + id + "_B");
	$(node).find(".ball1 > div:eq(1)").attr("id", "sc" + id + "_A");
	$(node).find(".ball2 > div:eq(1)").attr("id", "sc" + id + "_B");
	$(node).find(".scPfeil:eq(0)").click(function() { scrollStats(-1); });
	$(node).find(".scPfeil:eq(1)").click(function() { scrollStats(1); });
	$(node).css("display", "inline-block");
	return $(node);
}

//---------------------------------------------------------------------------------------------------
function processBoxscore(dataNode) {
	$("#btnTeamA").text(gTeamNameA);
	$("#btnTeamB").text(gTeamNameB);
	if ($("#bxTableA").find("tr").length - 2 != dataNode.find("TEAM:eq(0)").children().length || $("#bxTableB").find("tr").length - 2 != dataNode.find("TEAM:eq(1)").children().length) {
		createBoxscore($("#bxTableA"), dataNode.find("TEAM:eq(0)"), "A");
		createBoxscore($("#bxTableB"), dataNode.find("TEAM:eq(1)"), "B");
	}
	processBoxscoreTeam(dataNode.find("TEAM:eq(0)"), "A");
	processBoxscoreTeam(dataNode.find("TEAM:eq(1)"), "B");
	processBoxscoreComparison(dataNode.find("TEAM:eq(0)"), "A");
	processBoxscoreComparison(dataNode.find("TEAM:eq(1)"), "B");
}

function createBoxscore(root, dataNode, team) {
	$(root).find("tr.bxrow1").remove();
	$(root).find("tr.bxrow2").remove();
	dataNode.find("PLAYER").each(function(index) {
		var tr = $("#bxTemplate").clone();
		$(tr).find("td:eq(0)").attr("id", "bxno" + team + index);
		$(tr).find("td:eq(1)").attr("id", "bxname" + team + index);
		$(tr).find("td:eq(2)").attr("id", "bxmin" + team + index);
		$(tr).find("td:eq(3)").attr("id", "bxfgma" + team + index);
		$(tr).find("td:eq(4)").attr("id", "bxfgp" + team + index);
		$(tr).find("td:eq(5)").attr("id", "bxp2ma" + team + index);
		$(tr).find("td:eq(6)").attr("id", "bxp2p" + team + index);
		$(tr).find("td:eq(7)").attr("id", "bxp3ma" + team + index);
		$(tr).find("td:eq(8)").attr("id", "bxp3p" + team + index);
		$(tr).find("td:eq(9)").attr("id", "bxp1ma" + team + index);
		$(tr).find("td:eq(10)").attr("id", "bxp1p" + team + index);
		$(tr).find("td:eq(11)").attr("id", "bxro" + team + index);
		$(tr).find("td:eq(12)").attr("id", "bxrd" + team + index);
		$(tr).find("td:eq(13)").attr("id", "bxrt" + team + index);
		$(tr).find("td:eq(14)").attr("id", "bxas" + team + index);
		$(tr).find("td:eq(15)").attr("id", "bxto" + team + index);
		$(tr).find("td:eq(16)").attr("id", "bxst" + team + index);
		$(tr).find("td:eq(17)").attr("id", "bxbs" + team + index);
		$(tr).find("td:eq(18)").attr("id", "bxpf" + team + index);
		$(tr).find("td:eq(19)").attr("id", "bxrf" + team + index);
		$(tr).find("td:eq(20)").attr("id", "bxind" + team + index);
		$(tr).find("td:eq(21)").attr("id", "bxpts" + team + index);
		root.find("tr:eq(" + (index+1) + ")").after(tr);
	});
}

function processBoxscoreTeam(dataNode, team) {
	$(dataNode).find("PLAYER").each(function(i) {
		$("#bxno" + team + i).text($(this).attr("no"));
		if ($(this).attr("in") == 1) {
			$("#bxname" + team + i).parent().addClass("active");
		}
		else {
			$("#bxname" + team + i).parent().removeClass("active");
		}
		$("#bxname" + team + i).html($(this).attr("name"));
		$("#bxname" + team + i).unbind("click").click(function(e) {
			displayPlayerInfo(e, team + "." + $(dataNode).find("PLAYER:eq(" + i + ")").attr("no"));
		});
		$("#bxmin" + team + i).text($(this).attr("min"));
		$("#bxfgma" + team + i).text($(this).attr("fgm") + '/' + $(this).attr("fga"));
		$("#bxfgp" + team + i).text($(this).attr("fgp"));  //+ "%";
		$("#bxp2ma" + team + i).text($(this).attr("p2m") + '/' + $(this).attr("p2a"));
		$("#bxp2p" + team + i).text($(this).attr("p2p"));  //+ "%";
		$("#bxp3ma" + team + i).text($(this).attr("p3m") + '/' + $(this).attr("p3a"));
		$("#bxp3p" + team + i).text($(this).attr("p3p"));  //+ "%";
		$("#bxp1ma" + team + i).text($(this).attr("p1m") + '/' + $(this).attr("p1a"));
		$("#bxp1p" + team + i).text($(this).attr("p1p"));  //+ "%";
		$("#bxro" + team + i).text($(this).attr("ro"));
		$("#bxrd" + team + i).text($(this).attr("rd"));
		$("#bxrt" + team + i).text($(this).attr("rt"));
		$("#bxas" + team + i).text($(this).attr("as"));
		$("#bxpf" + team + i).text($(this).attr("pf"));
		$("#bxrf" + team + i).text($(this).attr("rf"));
		$("#bxto" + team + i).text($(this).attr("to"));
		$("#bxst" + team + i).text($(this).attr("st"));
		$("#bxbs" + team + i).text($(this).attr("bs"));
		if ($(this).attr("ind")) {
			var ind = $(this).attr("ind");
			if (ind > 0) ind = "+" + ind;
			$("#bxind" + team + i).text(ind);
		}
		$("#bxpts" + team + i).text($(this).attr("pts"));
	});
	 
	var node = dataNode.find("TEAMACTIONS");
	$("#bxro" + team + "ta").text(node.attr("ro"));
	$("#bxrd" + team + "ta").text(node.attr("rd"));
	$("#bxrt" + team + "ta").text(node.attr("rt"));
	$("#bxpf" + team + "ta").text(node.attr("pf"));
	$("#bxrf" + team + "ta").text(node.attr("rf"));
	$("#bxto" + team + "ta").text(node.attr("to"));
	$("#bxst" + team + "ta").text(node.attr("st"));

	var node = dataNode.find("TOTAL");
	$("#bxfgma" + team + "to").text(node.attr("fgm") + '/' + node.attr("fga"));
	$("#bxfgp" + team + "to").text(node.attr("fgp"));  //+ "%";
	$("#bxp2ma" + team + "to").text(node.attr("p2m") + '/' + node.attr("p2a"));
	$("#bxp2p" + team + "to").text(node.attr("p2p"));  //+ "%";
	$("#bxp3ma" + team + "to").text(node.attr("p3m") + '/' + node.attr("p3a"));
	$("#bxp3p" + team + "to").text(node.attr("p3p"));  //+ "%";
	$("#bxp1ma" + team + "to").text(node.attr("p1m") + '/' + node.attr("p1a"));
	$("#bxp1p" + team + "to").text(node.attr("p1p"));  //+ "%";
	$("#bxro" + team + "to").text(node.attr("ro"));
	$("#bxrd" + team + "to").text(node.attr("rd"));
	$("#bxrt" + team + "to").text(node.attr("rt"));
	$("#bxas" + team + "to").text(node.attr("as"));
	$("#bxpf" + team + "to").text(node.attr("pf"));
	$("#bxrf" + team + "to").text(node.attr("rf"));
	$("#bxto" + team + "to").text(node.attr("to"));
	$("#bxst" + team + "to").text(node.attr("st"));
	$("#bxbs" + team + "to").text(node.attr("bs"));
	$("#bxpts" + team + "to").text(node.attr("pts"));
}

function switchBoxscore(team1, team2) {
	$("#btnTeam" + team1).addClass("active");
	$("#btnTeam" + team2).removeClass("active");
	$("#bxTeam" + team1).show();
	$("#bxTeam" + team2).hide();
}

function processBoxscoreComparison(dataNode, team) {
	var node = dataNode.find("TOTAL");
	var element = $("#bxComparison" + team);
	element.find("th:eq(0)").text(eval("gTeamName" + team));
	element.find("th:eq(1)").text(node.attr("fgm") + '/' + node.attr("fga"));
	element.find("th:eq(2)").text(node.attr("fgp"));
	element.find("th:eq(3)").text(node.attr("p2m") + '/' + node.attr("p2a"));
	element.find("th:eq(4)").text(node.attr("p2p"));
	element.find("th:eq(5)").text(node.attr("p3m") + '/' + node.attr("p3a"));
	element.find("th:eq(6)").text(node.attr("p3p"));
	element.find("th:eq(7)").text(node.attr("p1m") + '/' + node.attr("p1a"));
	element.find("th:eq(8)").text(node.attr("p1p"));
	element.find("th:eq(9)").text(node.attr("ro"));
	element.find("th:eq(10)").text(node.attr("rd"));
	element.find("th:eq(11)").text(node.attr("rt"));
	element.find("th:eq(12)").text(node.attr("as"));
	element.find("th:eq(13)").text(node.attr("to"));
	element.find("th:eq(14)").text(node.attr("st"));
	element.find("th:eq(15)").text(node.attr("bs"));
	element.find("th:eq(16)").text(node.attr("pf"));
	element.find("th:eq(17)").text(node.attr("rf"));
	element.find("th:eq(18)").text(node.attr("pts"));
}

//---------------------------------------------------------------------------------------------------
function processShotChart(dataNode) {
	if ($("#schQuarters").children().length != $(dataNode).attr("Quarters")) {
		createShotChart(dataNode);
	}
	drawShotChart(dataNode);
}

function cloneCheckbox(template, newId, text, no) {
	var node = $("#"+template).clone();
	$(node).attr("id", newId);
	node.find("#schTplCheckbox").attr("id", newId + "Checkbox");
	node.find("#schTplLabel").text(text);
	node.find("#schTplLabel").attr("for", newId + "Checkbox");
	node.find("#schTplLabel").attr("id", newId + "Label");
	if (no) {
		node.find("#schTplNumber").text(no + ".");
	}
	return node;
}

function createShotChart(dataNode) {
	var fnDrawShotChart = function() {
		drawShotChart(dataNode);
	};
	// Teams
	var fnTeamClick = function(letter) {
		if ($("#schTeam" + letter).is(":checked")) {
			$("#schPlayers" + letter).find(":checkbox").attr("checked", "checked");
		}
		else {
			$("#schPlayers" + letter).find(":checkbox").removeAttr("checked");
		}
		drawShotChart(dataNode);
	};
	$("#schTeamNameA").text(gTeamNameA);
	$("#schTeamNameB").text(gTeamNameB);
	$("#schTeamA").click(function() { fnTeamClick("A") });
	$("#schTeamB").click(function() { fnTeamClick("B") });

	// Quarters
	$("#schQuarters").text("");
	for (i = 1; i <= $(dataNode).attr("Quarters"); i++) {
		var qtext = (i > 4) ? "OT " + (i - 4) : lang["quarter"] + " " + i;
		var node = cloneCheckbox("schQuarterTemplate", "schQuarter" + i, qtext);
		$(node).click(fnDrawShotChart);
		$("#schQuarters").append(node);
	}

	// Players
	$("#schPlayersA").text("")
	$(dataNode).find("TEAM:eq(0)").find("P").each(function(i) {
		var div = document.createElement("div");
		var node = cloneCheckbox("schTemplateA", "schPlayerA" + $(this).attr("Nr"), $(this).attr("N"), $(this).attr("Nr"));
		$(node).click(fnDrawShotChart);
		$(div).append(node);
		$(div).addClass(i % 2 == 0 ? "row1" : "row2");
		$("#schPlayersA").append(div);
	});

	$("#schPlayersB").text("")
	$(dataNode).find("TEAM:eq(1)").find("P").each(function(i) {
		var div = document.createElement("div");
		var node = cloneCheckbox("schTemplateB", "schPlayerB" + $(this).attr("Nr"), $(this).attr("N"), $(this).attr("Nr"));
		$(node).click(fnDrawShotChart);
		$(div).append(node);
		$(div).addClass(i % 2 == 0 ? "row1" : "row2");
		$("#schPlayersB").append(div);
	});
	$("#shotChartContainer").mousemove(function() {
		$("#shotChartNote").hide();
		$("#dPlayerInfo").hide();
	});
	$("#shotChartNote").mousemove(function(e) { e.stopPropagation() });
}

function drawShotChart(dataNode) {
	// Filter settings
	var fQuarters = new Array();
	var fPlayersA = new Array();
	var fPlayersB = new Array();
	for (i = 1; i <= $(dataNode).attr("Quarters"); i++) {
		fQuarters[i] = $("#schQuarter" + i + "Checkbox").attr("checked");
	}
	$(dataNode).find("TEAM:eq(0)").find("P").each(function() {
		fPlayersA[$(this).attr("Nr")] = $("#schPlayerA" + $(this).attr("Nr") + "Checkbox").attr("checked");
	});
	$(dataNode).find("TEAM:eq(1)").find("P").each(function() {
		fPlayersB[$(this).attr("Nr")] = $("#schPlayerB" + $(this).attr("Nr") + "Checkbox").attr("checked");
	});

	// Draw dots
	$("#shotChartContainer").find(".schDot").remove();
	var dW = $("#shotChartContainer").width();
	var dH = $("#shotChartContainer").height();
	var ratio = dH / 1500;
	$(dataNode).find("S").each(function(index) {
		if (fQuarters[$(this).attr("quarter")]) {
			var fPlayers = $(this).attr("team") == 0 ? fPlayersA : fPlayersB;
			if (fPlayers[$(this).attr("player")]) {
				var img = document.createElement("div");
				$(img).addClass("schDot");
				$(img).addClass($(this).attr("m") == "0" ? "g" : "r");
				var py = $(this).attr("team") == "0" ? dH - parseInt($(this).attr("x")) * ratio : parseInt($(this).attr("x")) * ratio;
				var px = $(this).attr("team") == "0" ? parseInt($(this).attr("y")) * ratio : dW - parseInt($(this).attr("y")) * ratio;
				$(img).css("left", px - 3);
				$(img).css("top", py - 3);
				$(img).attr("alt", index);
				$("#shotChartContainer").append(img);

				$(img).hover(function() {
					var snode = $(dataNode).find("S:eq(" + $(this).attr("alt") + ")");
					var pnode = $(dataNode).find("TEAM:eq(" + snode.attr("team") + ")").find("P[Nr=" + snode.attr("player") + "]");
					$("#schTitle").text(pnode.attr("Nr") + ". " + pnode.attr("N"));
					var qtext = (snode.attr("quarter") > 4) ?  lang["overtime"]+ " " + (snode.attr("quarter") - 4) :  lang["quarter"] + " " + snode.attr("quarter");
					$("#schTime").text(qtext + ", " + snode.attr("t"));
					$("#shotChartNote").css("left", px - 1);
					$("#shotChartNote").css("top", py - 1);
					$("#shotChartNote").show("fast");
					$("#shotChartNote").click(function(e) {
						$("#shotChartNote").hide();
						var team = snode.attr("team") == "0" ? "A" : "B";
						var maxPosX = $("#main_layout").width() - $("#dPlayerInfo").width() - 10;
						e.pageX = $(img).offset().left > maxPosX ? maxPosX : $(img).offset().left;
						e.pageY = $(img).offset().top;
						displayPlayerInfo(e, team + "." + snode.attr("player"));
					});
				});
				$(img).mousemove(function(e) { e.stopPropagation() });
			}
		}
	});
}

//---------------------------------------------------------------------------------------------------
function processTicker(dataNode) {
	var text = ""
	if ($(dataNode).attr("text")) text = $(dataNode).attr("text");
	if ($("#tickerText").is(':animated') || text == $("#tickerText").text()) {
		return;
	}
	else {
		$("#tickerText").css("margin-left", $("#dTicker").width() + "px");
		$("#tickerText").text(text);
		$("#tickerText").show();
		$("#tickerText").animate({ "marginLeft": 0 - $("#tickerText").width() }, 15000, "linear");
	}
}

//-------------------------------------------------------------
function displayPlayerInfo(e, player) {
	$("#dPlayerInfo").css("left", e.pageX);
	$("#dPlayerInfo").css("top", e.pageY);
	$("#piProgress").show();
	$("#piData").hide();
	$("#dPlayerInfo").show();
	$("#piPhoto").attr("src", "images/pixel.gif");
	$.ajax({
		url: "PlayerInfo.ashx?acc=" + accountID + "&gameID=" + gameID + "&player=" + player + "&lng=" + currentLanguage,
		type: "GET",
		dataType: "xml",
		timeout: REQUEST_TIMEOUT,
		error: function(xhr, txtStatus, thrownError) {
			$("#statusMsg").text("Error loading XML document: " + txtStatus);
			$("#dPlayerInfo").hide();
		},
		success: function(xml) {
			if ($(xml).find("GAME").length == 0) {
				$("#dPlayerInfo").hide();
				return;
			}
			var playerNode = $(xml).find("PLAYER");
			$("#piName").text(playerNode.attr("firstName") + " " + playerNode.attr("lastName"));
			if (playerNode.attr("photo")) {
				$("#piPhoto").attr("src", playerNode.attr("photo"));
				$("#piPhoto").load(function() {
					if ($(this).height() > 85) $(this).height(85);
				});
			}
			else {
				$("#piPhoto").attr("src", "images/pixel.gif");
				$("#piPhoto").removeAttr("height");
			}
			$("#piAge").text(playerNode.attr("age"));
			$("#piPosition").text(playerNode.attr("position"));
			$("#piHeight").text(playerNode.attr("height"));
			$("#piNationality").text(playerNode.attr("nationality"));

			var gameNode = $(xml).find("GAME");
			$("#piGame2P").html(gameNode.attr("p2m") + "/" + gameNode.attr("p2a") + "<br />" + gameNode.attr("p2p") + "%");
			$("#piGame3P").html(gameNode.attr("p3m") + "/" + gameNode.attr("p3a") + "<br />" + gameNode.attr("p3p") + "%");
			$("#piGameFT").html(gameNode.attr("p1m") + "/" + gameNode.attr("p1a") + "<br />" + gameNode.attr("p1p") + "%");
			$("#piGameREB").html(gameNode.attr("rt") + "<br />(" + gameNode.attr("ro") + "/" + gameNode.attr("rd") + ")");
			$("#piGameAS").html(gameNode.attr("as"));
			$("#piGameTO").html(gameNode.attr("to"));
			$("#piGamePTS").html(gameNode.attr("pts"));

			var compNode = $(xml).find("COMPETITION");
			if (compNode.length > 0) {
				$("#piComp2P").html(compNode.attr("p2m") + "/" + compNode.attr("p2a") + "<br />" + compNode.attr("p2p") + "%");
				$("#piComp3P").html(compNode.attr("p3m") + "/" + compNode.attr("p3a") + "<br />" + compNode.attr("p3p") + "%");
				$("#piCompFT").html(compNode.attr("p1m") + "/" + compNode.attr("p1a") + "<br />" + compNode.attr("p1p") + "%");
				$("#piCompREB").html(compNode.attr("rt") + "<br />(" + compNode.attr("ro") + "/" + compNode.attr("rd") + ")");
				$("#piCompAS").html(compNode.attr("as"));
				$("#piCompTO").html(compNode.attr("to"));
				$("#piCompPTS").html(compNode.attr("pts"));
			}
			else {
				$("#piComp2P").text("-");
				$("#piComp3P").text("-");
				$("#piCompFT").text("-");
				$("#piCompREB").text("-");
				$("#piCompAS").text("-");
				$("#piCompTO").text("-");
				$("#piCompPTS").text("-");
			}

			$("#piProgress").fadeOut("slow", function() { $("#piData").fadeIn() });
		}
	});
}
