\n');
}
function handleCasterMessage(nodeName, message)
{
var nodeParts = nodeName.split('-');
var tempGame = null;
//debug("got a message: " + nodeName + " " + message);
if (nodeParts.length == 1)
{
// these are regular messages
if (nodeName == 'gameList')
{
updateGameList(message);
}
} else if (nodeParts.length >= 2)
{
var group = nodeParts[0];
var type = nodeParts[1];
tempGame = getGameById(group);
if (mlbRTprocessCB[type] != null)
{
mlbRTprocessCB[type](tempGame, group, type, message);
} else {
setGameValue(tempGame, group, type, message);
}
if ( tempGame != null && mlbRTdisplayCB[type] != null && tempGame.isDisplayed == true)
{
//debug ("displaying callback" + tempGame.slotNum + " " + group + " " + type);
mlbRTdisplayCB[type](tempGame, group, type, message);
} else {
//debug ("displaying " + tempGame.slotNum + " " + group + " " + type);
displayGameValue(tempGame, group, type, message);
}
// set the start game one time
if (setStartGame == true && group == startGameId) {
gameFocusChanged(tempGame.slotNum);
setStartGame = false;
}
}
}
// ---------- SCOREBOARD UI ----------
function displayGame(theGame)
{
// debug("theGame: " + theGame.gameId + ', ');
// debug("isSelected: " + theGame.isSelected + ', ');
// debug("isDisplayed: " + theGame.isDisplayed + ', ');
// debug("theGame: " + theGame.isSelected + ', ');
if (theGame.isDisplayed)
{
//displayInningList(theGame, null, null, null);
displayStatus(theGame, null, null, null);
displayInning(theGame, null, null, null);
displayTeamBar(theGame, null, "awayBar", null);
displayTeamBar(theGame, null, "homeBar", null);
displayBaseMap(theGame, null, null, null);
displayLastPlay(theGame, null, null, null);
displayPitcher(theGame, null, null, null);
displayPitcherStats(theGame, null, null, null);
displayBatter(theGame, null, null, null);
displayBatterStats(theGame, null, null, null);
displayInningList(theGame, null, null, null);
displayOnDeck(theGame, null, null, null);
displayWinningPitcher(theGame, null, null, null);
displayLosingPitcher(theGame, null, null, null);
displaySavePitcher(theGame, null, null, null);
displayStartingPitcher(theGame, null, 'aStartingPitcher', null);
displayStartingPitcher(theGame, null, 'hStartingPitcher', null);
displayGameValue(theGame, null, "aR", null);
displayGameValue(theGame, null, "hR", null);
displayGameValue(theGame, null, "aH", null);
displayGameValue(theGame, null, "hH", null);
displayGameValue(theGame, null, "aE", null);
displayGameValue(theGame, null, "hE", null);
//displayGameValue(theGame, null, "lastPlay", null);
displayGameValue(theGame, null, "balls", null);
displayGameValue(theGame, null, "strikes", null);
displayGameValue(theGame, null, "outs", null);
if (theGame.isSelected)
{
populateFeaturedSummary(theGame);
displayFeaturedGameCaption(theGame);
}
}
}
function shiftGamesLeft(amount)
{
clearTimeout(gameSwitchTimerId);
if (amount < 0)
{
amount = 1;
}
var arrPos = firstSlot + amount;
if (arrPos >= allGameIds.length)
{
arrPos = 0;
}
//debug("selectedSlot: " + selectedSlot + "firstPos: " + firstSlot + " amount: " + amount + " arrPos: " + arrPos + " selectedArrayIndex: " + selectedArrayIndex);
performGameShift(arrPos);
}
function shiftGamesRight(amount)
{
clearTimeout(gameSwitchTimerId);
if (amount < 0)
{
amount = 1;
}
var arrPos = firstSlot - amount;
if (arrPos == null || arrPos < 0)
{
arrPos = allGameIds.length-1;
}
//debug("selectedSlot: " + selectedSlot + "firstPos: " + firstSlot + " amount: " + amount + " arrPos: " + arrPos + " selectedArrayIndex: " + selectedArrayIndex);
performGameShift(arrPos);
}
function performGameShift(startPos)
{
var arrayIndex = startPos;
var firstNewSeen = false;
//debug("perform game shift called");
for (var k=0; k
" +
"2B: " + (theGame.basemapNames[1] == 0 ? " " : theGame.basemapNames[1]) + "
" +
"3B: " + (theGame.basemapNames[2] == 0 ? " " : theGame.basemapNames[2]), false);
} else {
setValue(detailNames, "1B:
2B:
:3B: ", false);
}
}
}
}
}
}
function displayStatus(theGame, group, type, message)
{
if (theGame != null && theGame.isDisplayed == true)
{
if (theGame.status != null)
{
//debug("theGame.status: " + theGame.status);
switch(parseInt(theGame.status,10))
{
case 1:
// PREGAME
theGame.titleBarBackground = imgURLBase + 'gameBar_pre.gif';
theGame.titleBarColor = "#FFFFFF";
theGame.gameState = 1;
setInGameView(theGame, 1);
//debug("theGame.status:1,5,6");
break;
case 2:
case 7:
// IN PROGRESS (delayed will still show in progress color)
theGame.gameState = 2;
if (theGame.isSelected == true)
{
theGame.titleBarBackground = imgURLBase + 'gameBar_active.gif';
theGame.titleBarColor = "#FFFFFF";
setInGameView(theGame, 2);
} else {
theGame.titleBarBackground = imgURLBase + 'gameBar_inactive.gif';
theGame.titleBarColor = "#B5AAAA";
}
//debug("theGame.status:2,7");
break;
case 3:
theGame.gameState = 3;
theGame.titleBarBackground = imgURLBase + 'gameBar_post.gif';
theGame.titleBarColor = "#FFFFFF";
setInGameView(theGame, 3);
//debug("theGame.status:3,4");
break;
case 4:
case 5:
case 6:
theGame.titleBarBackground = imgURLBase + 'gameBar_pre.gif';
theGame.titleBarColor = "#FFFFFF";
theGame.gameState = 4;
setInGameView(theGame, 4);
break;
default:
// invalid status
theGame.gameState = 1;
theGame.titleBarBackground = imgURLBase + 'gameBar_pre.gif';
theGame.titleBarColor = "#FFFFFF";
setInGameView(theGame, 1);
//debug("theGame.status:default");
}
}
var tempElement = getElement('game' + theGame.slotNum + '_titleBar');
if (theGame.titleBarColor != null)
tempElement.style.color = theGame.titleBarColor;
if (theGame.titleBarBackground != null)
tempElement.style.backgroundImage = 'url(' + theGame.titleBarBackground + ')';
}
}
function displayInning(theGame, group, type, message )
{
if (theGame != null && theGame.isDisplayed == true && theGame.inningHalf != null && theGame.inningTitle != null)
{
//debug("in displayInning");
var actStr = '';
var tempElement = getElement('game' + theGame.slotNum + '_inningFlag');
//debug("displayInning: " + theGame.slotNum);
var tempInningTitle = '';
// this might flicker if I do this directly, so using a temp var
if (theGame.inningHalf == "End" || theGame.inningHalf == "Mid")
tempInningTitle = theGame.inningHalf + ' ' ;
if (theGame.isSelected == true)
{
actStr = "active";
} else {
actStr = "inactive";
}
if (tempElement != null)
{
displayInningFlag(tempElement, theGame.inningHalf, 'game_', actStr, theGame.isSelected);
}
var tempTextElement = getElement('game' + theGame.slotNum + '_inning');
if (tempTextElement != null && theGame.inningTitle != null)
{
setValue(tempTextElement, tempInningTitle + theGame.inningTitle, false);
}
if (theGame.isSelected)
{
tempElement = getElement('detail_inningFlag');
tempTextElement = getElement('detail_inning');
if (tempElement != null)
{
displayInningFlag(tempElement, theGame.inningHalf, 'detail_', null, theGame.isSelected);
}
if (tempTextElement != null && theGame.inningTitle != null)
{
setValue(tempTextElement, tempInningTitle + theGame.inningTitle, false);
}
}
}
}
function displayInningFlag(theElement, inningHalf, prefix, postfix, isSelected)
{
if (theElement != null && inningHalf != null)
{
var imURL = 'https://assets.espn.com/i/mlb/caster/popup/' + prefix;
if (postfix != null)
{
imURL = imURL + postfix;
}
/*var huh = "Mid";
debug("look!: " + huh.charCodeAt(0) + " " + inningHalf.charCodeAt(0));
*/
//debug ("bah: " + theElement.id + " kkkkk_" + inningHalf + "_kkkk");
if (inningHalf == "Top")
{
//debug("Top!");
theElement.src = imURL + 'InningTop.gif';
theElement.style.visibility = 'inherit';
} else if (inningHalf == "Mid")
{
//debug("Mid!");
theElement.style.visibility = 'hidden';
} else if (inningHalf == "Bot")
{
//debug("Bot!");
theElement.src = imURL + 'InningBottom.gif';
theElement.style.visibility = 'inherit';
} else if (inningHalf == "End")
{
//debug("End!");
theElement.style.visibility = 'hidden';
} else
{
//debug("Fell Through :-( " + inningHalf);
theElement.style.visibility = 'hidden';
}
//debug ("kkkkk_" + theElement.src + "_kkkk");
}
}
function displayTeamBar(theGame, group, type, message )
{
if (theGame != null && theGame.isDisplayed == true)
{
var tempElement = getElement('game' + theGame.slotNum + '_' + type);
setValue(tempElement, theGame[type] == null ? '' : theGame[type].shortName, false);
if (theGame.isSelected)
{
tempElement = getElement('detail_' + type);
setValue(tempElement, theGame[type] == null ? '' : theGame[type].shortName, false);
}
}
}
function displayScore(theGame, group, type, message)
{
if (theGame != null)
{
// can use standard processing for the boring fields
displayGameValue(theGame, group, type, message);
if (theGame.isSelected)
{
displayFeaturedGameCaption(theGame);
}
}
}
function displayPitcher(theGame, group, type, message)
{
if (theGame != null && theGame.isSelected)
{
var tempElem;
if (theGame.currentPitcher != null)
{
var playerInfo = theGame.currentPitcher.split(",");
if (playerInfo.length > 2)
{
setPlayerLink('pitcherName', playerInfo[0], '#' + playerInfo[2] + ' ' + playerInfo[1]);
if (tempElem = getElement('pitcherHeadShot'))
{
//debug("playerInfo: " + playerInfo[0]);
var imgURL = hsURLBase + playerInfo[0] + '.jpg';
setValue(tempElem, imgURL, false);
}
}
} else {
setPlayerLink('pitcherName', null, ' ');
if (tempElem = getElement('pitcherHeadShot'))
{
//debug("playerInfo: " + playerInfo[0]);
var imgURL = hsURLBase + '0000.jpg';
setValue(tempElem, imgURL, false);
}
}
}
}
function displayBatter(theGame, group, type, message)
{
if (theGame != null && theGame.isSelected)
{
if (theGame.currentBatter != null)
{
var playerInfo = theGame.currentBatter.split(',');
if (playerInfo.length > 2)
{
var tempElem;
setPlayerLink('batterName', playerInfo[0], '#' + playerInfo[2] + ' ' + playerInfo[1]);
if (tempElem = getElement('batterHeadShot'))
{
var imgURL = hsURLBase + playerInfo[0] + '.jpg';
setValue(tempElem, imgURL, false);
}
}
} else {
setPlayerLink('batterName', null, ' ');
if (tempElem = getElement('batterHeadShot'))
{
//debug("playerInfo: " + playerInfo[0]);
var imgURL = hsURLBase + '0000.jpg';
setValue(tempElem, imgURL, false);
}
}
}
}
function displayPitcherStats(theGame, group, type, message)
{
if (theGame != null && theGame.isSelected)
{
if (theGame.currentPitcherStats != null)
{
var playerStats = theGame.currentPitcherStats.split(',');
var tempElem;
if (playerStats.length >= 8)
{
var oneLineStr = playerStats[1] + ' ' + playerStats[4] + ' ' + playerStats[5];
if (tempElem = getElement('pitcherLine1'))
setValue(tempElem, oneLineStr, false);
oneLineStr = playerStats[2] + ' ' + playerStats[3];
if (tempElem = getElement('pitcherLine2'))
setValue(tempElem, oneLineStr, false);
oneLineStr = playerStats[6] + ' ' + playerStats[7];
if (tempElem = getElement('pitcherLine3'))
setValue(tempElem, oneLineStr, false);
}
} else {
if (tempElem = getElement('pitcherLine1'))
setValue(tempElem, ' ', false);
if (tempElem = getElement('pitcherLine2'))
setValue(tempElem, ' ', false);
if (tempElem = getElement('pitcherLine3'))
setValue(tempElem, ' ', false);
}
}
}
function displayBatterStats(theGame, group, type, message)
{
if (theGame != null && theGame.isSelected)
{
if (theGame.currentBatterStats != null)
{
var playerStats = theGame.currentBatterStats.split(',');
var tempElem;
if (playerStats.length >= 10)
{
var oneLineStr = playerStats[1] + ' ' + (playerStats[3] == '0 HR' ? '' : playerStats[3]) + ' ' + playerStats[5];
if (tempElem = getElement('batterLine1'))
setValue(tempElem, oneLineStr, false);
oneLineStr = playerStats[2] + ' ' + playerStats[4] + ' ' + playerStats[6] ;
if (tempElem = getElement('batterLine2'))
setValue(tempElem, oneLineStr, false);
oneLineStr = playerStats[7] + ' ' + playerStats[8] + ' ' + playerStats[9];
if (tempElem = getElement('batterLine3'))
setValue(tempElem, oneLineStr, false);
}
} else {
if (tempElem = getElement('batterLine1'))
setValue(tempElem, ' ', false);
if (tempElem = getElement('batterLine2'))
setValue(tempElem, ' ', false);
if (tempElem = getElement('batterLine3'))
setValue(tempElem, ' ', false);
}
}
}
function displayLastPlay(theGame, group, type, message)
{
if (theGame != null && theGame.isSelected)
{
var tElem = getElement('detail_lastPlay');
if (tElem != null)
setValue(tElem, theGame.lastPlay == null ? ' ' : theGame.lastPlay, false);
}
}
function displayFeaturedGameCaption(theGame)
{
if (theGame != null && theGame.isSelected)
{
if (theGame.awayBar != null && theGame.homeBar != null &&
theGame.aR != null && theGame.hR != null)
{
var tempElement = getElement('featuredGameCaption');
var tempBox = getElement('featuredGameCaptionBox');
var outMessage;
if (tempElement != null)
{
switch (parseInt(theGame.status, 10))
{
case 1:
setValue(tempElement, theGame.awayBar.longName + ' (' + theGame.aRec + ')
at ' +
theGame.homeBar.longName + ' (' + theGame.hRec + ')
' + theGame.inningTitle +
'
', false);
tempBox.style.height = '75px';
tempBox.style.width = '348px';
break;
case 2:
case 7:
tempBox.style.height = '23px';
tempBox.style.width = '348px';
setValue(tempElement, theGame.awayBar.longName + ' ' + theGame.aR + ', ' +
theGame.homeBar.longName + ' ' + theGame.hR, false);
break;
case 3:
case 4:
tempBox.style.height = '23px';
tempBox.style.width = '500px';
setValue(tempElement, theGame.awayBar.longName + ' ' + theGame.aR + ', ' +
theGame.homeBar.longName + ' ' + theGame.hR +
' - FINAL', false);
break;
case 5:
tempBox.style.height = '50px';
tempBox.style.width = '500px';
setValue(tempElement, theGame.awayBar.longName + ' at ' + theGame.homeBar.longName +
' - CANCELLED', false);
break;
case 6:
tempBox.style.height = '50px';
tempBox.style.width = '348px';
setValue(tempElement, theGame.awayBar.longName + ' at ' + theGame.homeBar.longName +
' - POSTPONED', false);
break;
}
}
}
}
}
function displayOnDeck(theGame, group, type, message)
{
if (theGame != null && theGame.onDeck != null && theGame.isSelected)
{
var parts = theGame.onDeck.split(',');
if (parts.length >= 3)
{
setPlayerLink('detail_onDeck', parts[0], '#' + parts[2] + ' ' + parts[1]);
}
}
}
function displayWinningPitcher(theGame, group, type, message)
{
if (theGame != null && theGame.isSelected && theGame.win != null)
{
var parts = theGame.win.split(',');
if (parts.length >= 3)
setPlayerLink('detail_win', parts[0], parts[2]);
}
}
function displayLosingPitcher(theGame, group, type, message)
{
if (theGame != null && theGame.isSelected && theGame.loss != null)
{
var parts = theGame.loss.split(',');
if (parts.length >= 3)
setPlayerLink('detail_loss', parts[0], parts[2]);
}
}
function displaySavePitcher(theGame, group, type, message)
{
if (theGame != null && theGame.isSelected && theGame.save != null)
{
var parts = theGame.save.split(',');
if (parts.length >= 3)
setPlayerLink('detail_save', parts[0], parts[2]);
}
}
function displayStartingPitcher(theGame, group, type, message)
{
if (theGame != null && theGame.isSelected && theGame[type] != null && (theGame.status == 1 ||
theGame.status == 5 || theGame.status == 6))
{
var parts = theGame[type].split(',');
if (parts.length >= 10)
{
var tempElem;
if (type == 'aStartingPitcher')
{
if (tempElem = getElement('pitcherHeadShot'))
{
var imgURL = hsURLBase + parts[0] + '.jpg';
setValue(tempElem, imgURL, false);
}
setPlayerLink('pitcherName', parts[0], '#' + parts[1] + ' ' + parts[2]);
tempElem = getElement('pitcherLine1');
setValue(tempElem, parts[3] + ' ' + parts[4]);
tempElem = getElement('pitcherLine2');
setValue(tempElem, parts[5] + ' ' + parts[6]);
tempElem = getElement('pitcherLine3');
setValue(tempElem, parts[7] + ' ' + parts[8] + ' ' + parts[9]);
} else {
if (tempElem = getElement('batterHeadShot'))
{
var imgURL = hsURLBase + parts[0] + '.jpg';
setValue(tempElem, imgURL, false);
}
setPlayerLink('batterName', parts[0], '#' + parts[1] + ' ' + parts[2]);
tempElem = getElement('batterLine1');
setValue(tempElem, parts[3] + ' ' + parts[4]);
tempElem = getElement('batterLine2');
setValue(tempElem, parts[5] + ' ' + parts[6]);
tempElem = getElement('batterLine3');
setValue(tempElem, parts[7] + ' ' + parts[8] + ' ' + parts[9]);
}
}
}
}
// ---------- UTILITY UI FUNCTIONS -----------
function loadDefaultHS(elementId)
{
if (tempElem = getElement(elementId))
{
var imgURL = hsURLBase + '0000.gif';
setValue(tempElem, imgURL, false);
}
}
function populateFeaturedSummary(theGame)
{
if (theGame != null && theGame.isSelected)
{
if (theGame.t != null)
{
displayInningList(theGame, null, null, null);
} else {
var i = 10;
do
{
setValue(getElement('a' + i), ' ', false);
setValue(getElement('h' + i), ' ', false);
} while (--i);
}
var i = 1;
var tStr = '';
do
{
tStr = 'a' + i;
setValue(getElement('detail_' + tStr), theGame[tStr] == null ? ' ' : theGame[tStr], false);
tStr = 'h' + i;
setValue(getElement('detail_' + tStr), theGame[tStr] == null ? ' ' : theGame[tStr], false);
} while (++i < 11);
//displayGame(theGame);
//displayBaseMap(theGame, null, null, null);
//displayInning(theGame, null, null, null);
}
}
function setValue(element, value, doBorderFlash)
{
if (element == null)
return;
if (element.nodeName == "IMG" || element.nodeName == 'img')
{
element.src = value;
} else {
var cName = getRelevantClassName(element);
if (cName != null)
{
var aFrom = fromColorMap[cName];
var aTo = toColorMap[cName];
if (aFrom && aTo)
{
fade(aFrom[0], aFrom[1], aFrom[2], aTo[0], aTo[1], aTo[2], 26,element.id);
}
}
if (doBorderFlash == true)
{
element.style.border = "solid black 1px";
//if (casterTimeoutID != null && lastElementName == nodeName)
//{
//clearTimeout(casterTimeoutID);
//}
casterTimeoutID = setTimeout("clearBorder('" + element.id + "');", 3000);
lastElementName = element.id;
}
//debug ("got to innerHTML stuff");
element.innerHTML = value;
}
}
function setPlayerLink(elementName, playerId, text)
{
var theEle = getElement(elementName);
if (theEle != null)
{
if (playerId != null)
theEle.href = "https://www.espn.com/mlb/players/profile?statsId=" + playerId;
else
theEle.href = "javascript:void(0);";
setValue(theEle, text, false);
}
}
// ---------- UTIILITY FUNCTIONS -----------
function getElement(elementid)
{
if (document.getElementById)
{
return document.getElementById(elementid);
}
if (document.all)
{
return document.all[elementid];
}
}
function getGameById(gameId)
{
if (allGames[gameId] == null)
{
allGames[gameId] = new Object();
}
return allGames[gameId];
}
function debug(text)
{
DEBUGELE = getElement("DebugOutputWindow");
if (DEBUGELE != null && dodebug)
DEBUGELE.innerHTML = text + "
" + DEBUGELE.innerHTML ;
}
function getRelevantClassName(elementObj)
{
var className = elementObj.className;
var i = 2;
while (className == null && i > 0)
{
i--;
elementObj = elementObj.parentNode;
if (elementObj == null)
break;
className = elementObj.className;
}
return className;
}
function launchGameCast(gameId) {
//if (gameId) {
window.open("https://www.espn.com/mlb/gamecast?gameId="+gameId, "mlbgamecast", "width=960,height=603,left=20,top=20,scrollbars=no,menubar=no, resizable=no,location=no,toolbar=no");
//}
}
// END JS


Not an Insider? Click here to learn more about our RealTime feature.