


function getInningText(inn, is_top, rating)	{

	if(inn=="100")	inn = "Game End";
	else			inn = (is_top?"Top":"Bottom") + " " + inn;

	return( "(" + inn + ") Rating: " + rating + "<br>Click to view the boxscore at this point in the game");
}

function barMouseOver(event, obj, inn, is_top, rating, bar_index)	{

	defineOver(event, obj, getInningText(inn, is_top, rating));
	
	var bar = findObj('bar_' + bar_index)
	
	if(bar.className.indexOf('graphbar_sel')==-1)	{

		bar.style.backgroundColor='#333333';
	}
}

function barMouseOut(bar_index)	{

	defineOut(); 
	
	var bar = findObj('bar_' + bar_index)
	
	if(bar.className.indexOf('graphbar_sel')==-1)	{

		bar.style.backgroundColor='#a6c0db';
	}
	
}

function printGraphBase()	{

	for(var i=0; i<8; i++)	{
	
		document.write("<td colspan=2 align=center valign=top><div class=graphbase></div></td>");
	}

	document.write("<td align=center><div class=graphbase style='width:10px;'></div></td>");
}


function printGraphLabels()	{

	for(var i=0; i<8; i++)	{
	
		document.write("<td colspan=2 width=28 align=center>" + (i+1) + "</td>");
	}

	document.write("<td colspan=1 width=14 align=center>E</td>");
}

function printGraphBar(gameID, boxpart, part_height, inn, is_top, rating, sel)	{

	document.write("<td width=14 align=center valign=bottom height=45>");

	if(rating>0)	{

		document.write("<div id='bar_" + gameID + "_" + boxpart + "' class='graphbar" + (sel?" graphbar_sel":"") + "' style='height: " + part_height + "px;'>");
		
			document.write("<a href=\"/public/game?gameID=" + gameID + "&mode=box&part=" + boxpart + "\" onmouseover=\"barMouseOver(event,this," + inn + "," + is_top + "," + rating + ",'" + gameID + "_" + boxpart + "');\" onmousemove=\"defineMove(event);\" onmouseout=\"barMouseOut('" + gameID + "_" + boxpart + "');\"><img src=/html/c.gif width=9 height=" + part_height + " border=0></a>");

		document.write("</div>");
	}
			
	document.write("</td>");

}
		
		

///////////////////
		

var text_rating_header = "This is a rating of how interesting this game is (i.e. whether it's worth watching).  We use a variety of factors to determine this rating, including the plays in the game, how close the score is, etc.  For games in progress, the game rating will update at the end of every 1/2 inning.";

var text_inning_header = "We also rate each 1/2 inning, on a 1-5 scale.  This way, if you have limited time, you can fast-forward to the good parts of the game.  You can click on any inning bar to see the boxscore through that 1/2 inning.";

var text_preview = "View the game preview write-up.   This is spoiler-free, it will not divulge any game details.";

var text_ingame = "View the boxscore at the beginning of the game.  You can then walk through the 1/2 innings to follow along with the recorded game.";



var reload_timeout = null;

function setReloadTimeout(time)	{

	if(reload_timeout!=null)	clearTimeout(reload_timeout);

	reload_timeout = setTimeout("reloadMe();",time);  // reload me every 1 min
}
	
function reloadMe()	{

	location.href = location.href+"";
}
	
////////


function showScoreboard(gameID)	{

	xmlconn.request("/public/xml/home_scoreboard/noheaders?gameID=" + gameID);
}

function closeScoreboard(gameID)	{

	displayTBody(findObj("scoreboard_" + gameID),false)

	findObj("open_scoreboard_" + gameID).style.display = "inline";
	findObj("close_scoreboard_" + gameID).style.display = "none";
	
	setReloadTimeout(1000*45);
}



xmlconn.setRespHandler('home_scoreboard', displayScoreboard);

function displayScoreboard(xmldoc) {

	try	{

		var gameID = loadRequiredXMLParam(xmldoc, 'gameID');
	
		var linescore = loadRequiredXMLParam(xmldoc, 'linescore');
	
		findObj("linescore_" + gameID).innerHTML = linescore;


		var game_status = loadOptionalXMLParam(xmldoc, 'game_status');
	
		findObj("game_status_" + gameID).innerHTML = game_status;

		displayTBody(findObj("scoreboard_" + gameID),true)

		findObj("open_scoreboard_" + gameID).style.display = "none";
		findObj("close_scoreboard_" + gameID).style.display = "inline";

		setReloadTimeout(1000*45);

	} catch(e)	{

		displayError(e);
 	}
}
