// given a game object from the schedule - millisecond gmt time, and // the timezone offsets to return a gameTime object with date objects // for these adjusted times, along with string versions of the times function createGameTimes(game) { var localDate = new Date(); gameTime = { milliseconds: parseInt(game.game_time, 10), date: "", dateObj: new Date() }; gameTime.local = { milliseconds: gameTime.milliseconds, time: "", dateObj: new Date() }; gameTime.eastern = { milliseconds: gameTime.milliseconds, time: "", dateObj: new Date() }; // adjust the milliseconds time for est/venue time based on provided timezone offset if (game.game_time_offset_local) { gameTime.local.milliseconds = gameTime.milliseconds + (60 * 60 * game.game_time_offset_local * 1000); } if (game.game_time_offset_eastern) { gameTime.eastern.milliseconds = gameTime.milliseconds + (60 * 60 * game.game_time_offset_eastern * 1000); } // create date objects from these millisecond time values gameTime.dateObj.setTime(gameTime.milliseconds + (localDate.getTimezoneOffset() * 60 * 1000)); gameTime.local.dateObj.setTime(gameTime.local.milliseconds + (localDate.getTimezoneOffset() * 60 * 1000)); gameTime.eastern.dateObj.setTime(gameTime.eastern.milliseconds + (localDate.getTimezoneOffset() * 60 * 1000)); // for 2006, every game is in March gameTime.date = gameTime.local.dateObj.getDate() + " Mar"; // write "US" versions of dates with am/pm, others all get 24hr time if (localize) { gameTime.local.time = gameTime.local.dateObj.getHours() + ":" + getTwoDigitValue(gameTime.local.dateObj.getMinutes()); gameTime.eastern.time = gameTime.eastern.dateObj.getHours() + ":" + getTwoDigitValue(gameTime.eastern.dateObj.getMinutes()); } else { gameTime.local.time = ":" + getTwoDigitValue(gameTime.local.dateObj.getMinutes()); gameTime.eastern.time = ":" + getTwoDigitValue(gameTime.eastern.dateObj.getMinutes()); var hour = gameTime.local.dateObj.getHours(); if (hour > 12) { hour = hour - 12; gameTime.local.time = hour + gameTime.local.time + "pm"; } else if (hour == 12) { gameTime.local.time = hour + gameTime.local.time + "pm"; // noon } else { gameTime.local.time = hour + gameTime.local.time + "am"; } hour = gameTime.eastern.dateObj.getHours(); if (hour > 12) { hour = hour - 12; gameTime.eastern.time = hour + gameTime.eastern.time + "pm"; } else if (hour == 12) { gameTime.eastern.time = hour + gameTime.eastern.time + "pm"; // noon } else { gameTime.eastern.time = hour + gameTime.eastern.time + "am"; } } gameTime.eastern.clock = gameTime.eastern.time; // if the EST time falls on another date, then add the date/month to the time string /* if (game.division_id == 310) { if (gameTime.local.dateObj.getDate() != gameTime.eastern.dateObj.getDate()) { gameTime.eastern.time = "" + gameTime.eastern.dateObj.getDate() + " Mar " + gameTime.eastern.time } else { gameTime.eastern.time = gameTime.eastern.dateObj.getDate() + " Mar " + gameTime.eastern.time } } */ if (gameTime.local.dateObj.getDate() != gameTime.eastern.dateObj.getDate()) { gameTime.eastern.time = gameTime.eastern.dateObj.getDate() + " Mar " + gameTime.eastern.time } return gameTime; } function buildLiveGame(params) { // for now its just the same function return buildUpcomingGame(params); } // build a single table row with the information for an upcoming or unfinished game function buildUpcomingGame(params) { var game = setupPreviewRecap(params.game, params.previews, "previews"); var html = ""; var matchup = ""; var stadium = ""; var video = ""; var audio = ""; var preview = ""; var gameday = ""; var gameId = game.game_id; gameId = gameId.replace(/\//g, "_").replace(/\-/g, "_"); audio = buildMedia(gameId, media, "audio"); video = buildMedia(gameId, media, "video"); try { if (game.away.previews || game.home.previews) { if (localize) { var lang = "en"; lang = lang.replace(/\-/g, "_"); if (game.home.previews[lang]) { game.home.preview = game.home.previews[lang]; } else { if (game.home.previews.en) { game.home.preview = game.home.previews.en; } } if (game.away.previews[lang]) { game.away.preview = game.away.previews[lang]; } else { if (game.away.previews.en) { game.away.preview = game.away.previews.en; } } } else { if (game.home.previews.en) { game.home.preview = game.home.previews.en; } if (game.away.previews.en) { game.away.preview = game.away.previews.en; } } } } catch (e) { } var tbdTeams = { // pool 1 pk39925: { away: "Pool A Runner-up", home: "Pool B Runner-up" }, // anaheim 3/12 1 pk39927: { away: "Pool B Winner", home: "Pool A Winner" }, // anaheim 3/12 2 pk39930: { away: "Pool B Runner-up", home: "Pool A Winner" }, // anaheim 3/13 pk39931: { away: "Pool A Runner-up", home: "Pool B Winner" }, // anaheim 3/14 pk39934: { away: "Pool A Winner", home: "Pool A Runner-up" }, // anaheim 3/15 pk39935: { away: "Pool B Runner-up", home: "Pool B Winner" }, // anaheim 3/16 // pool 2 pk39924: { away: "Pool C Runner-up", home: "Pool D Runner-up" }, // hiram 3/12 1 pk39926: { away: "Pool C Winner", home: "Pool D Winner" }, // hiram 3/12 2 pk39928: { away: "Pool D Winner", home: "Pool C Runner-up" }, // hiram 3/13 1 pk39929: { away: "Pool D Runner-up", home: "Pool C Winner" }, // hiram 3/13 2 pk39932: { away: "Pool D Runner-up", home: "Pool D Winner" }, // hiram 3/14 pk39933: { away: "Pool C Runner-up", home: "Pool C Winner" }, // hiram 3/15 pk39936: { away: "Pool 2 Runner-up", home: "Pool 2 Winner" }, // semi 1 pk39937: { away: "Pool 1 Runner-up", home: "Pool 1 Winner" }, // semi 2 pk39938: { away: "SF 1 Winner", home: "SF 2 Winner" } // example from final game } gameTime = createGameTimes(game); try { var teamAwayName = ""; var teamHomeName = ""; if (game.away.code_num == "32") { if (tbdTeams["pk" + game.game_pk]) { teamAwayName = tbdTeams["pk" + game.game_pk].away } else { teamAwayName = "TBD"; } } else { if (params.name == "display") { teamAwayName = countryName["t" + game.away.code_num]; } else { teamAwayName = countryAbbr["t" + game.away.code_num]; } } if (game.home.code_num == "32") { if (tbdTeams["pk" + game.game_pk]) { teamHomeName = tbdTeams["pk" + game.game_pk].home } else { teamHomeName = "TBD"; } } else { if (params.name == "display") { teamHomeName = countryName["t" + game.home.code_num]; } else { teamHomeName = countryAbbr["t" + game.home.code_num]; } } matchup = teamAwayName + " vs " + teamHomeName; } catch (e) { matchup = "TBD vs TBD"; } if (game.venue_id) { stadium = stadiumName["v" + game.venue_id]; } else if (game.game_venue) { stadium = game.game_venue; } // if we're on the main schedule page, display both previews, otherwise just display this teams preview // and only display previews in Preview, Warmup or Immediate Preview if ((game.game_status == "P") || (game.game_status == "IP") || (game.game_status == "W")) { if (params.name == "display") { if (game.away.preview) { preview += "" + countryAbbr["t" + game.away.code_num] + " Preview   "; } if (game.home.preview) { preview += "" + countryAbbr["t" + game.home.code_num] + " Preview"; } } else { if (("t" + game.home.code_num) == 'wbc') { if (game.home.preview) { preview = "Preview"; } } if (("t" + game.away.code_num) == 'wbc') { if (game.away.preview) { preview = "Preview"; } } } } // show gameday for "inprogress" games if ((game.game_status == "I") || (game.game_status == "D") || (game.game_status == "W") || (game.game_status == "IP")) { gameday = "Gameday \"Launch"; gameday = "\"Launch"; } else { stadium += " "; } html += ""; if (params.type != "component") { html += "" + gameTime.date + ""; html += "" + gameTime.local.time + ""; } if (params.type != "component") { html += "" + gameTime.eastern.time + ""; } else { html += "" + gameTime.eastern.clock + ""; } html += "" + matchup + ""; if ((params.type != "component") && (params.type != "subscription")) { html += "" + stadium + ""; } html += "" + video + ""; html += "" + audio + ""; if (params.type != "component") { if ((params.type == "full") || (params.type == "team")) { html += " " + gameday + ""; html += " " + preview + ""; } else { html += " "; // extra } html += " "; // extra } html += ""; return html; } function buildPlayedGame(params) { var game = setupPreviewRecap(params.game, params.recaps, "recaps"); var html = ""; var finalScore = ""; var box = ""; var gameday = ""; var video = ""; var audio = ""; var recap = ""; var gameId = game.game_id; gameId = gameId.replace(/\//g, "_").replace(/\-/g, "_"); audio = buildMedia(gameId, media, "audio"); video = buildMedia(gameId, media, "video"); try { if (game.away.recaps || game.home.recaps) { if (localize) { var lang = "en"; lang = lang.replace(/\-/g, "_"); if (game.home.recaps[lang]) { game.home.recap = game.home.recaps[lang]; } else { if (game.home.recaps.en) { game.home.recap = game.home.recaps.en; } } if (game.away.recaps[lang]) { game.away.recap = game.away.recaps[lang]; } else { if (game.away.recaps.en) { game.away.recap = game.away.recaps.en; } } } else { if (game.home.recaps.en) { game.home.recap = game.home.recaps.en; } if (game.away.recaps.en) { game.away.recap = game.away.recaps.en; } } } } catch (e) { } gameTime = createGameTimes(game); // always display the winner first var team1; var team2; if (game.away.result == null) { game.away.result = "0"; } if (game.home.result == null) { game.home.result = "0"; } if (parseInt(game.away.result,10) > parseInt(game.home.result,10)) { team1 = game.away; team2 = game.home; } else { team1 = game.home; team2 = game.away; } var team1Name = "TBD"; var team2Name = "TBD"; if (params.name == "display") { team1Name = countryName["t" + team1.code_num] team2Name = countryName["t" + team2.code_num] } else { team1Name = countryAbbr["t" + team1.code_num] team2Name = countryAbbr["t" + team2.code_num] } // bold the "current" team if (("t" + team1.code_num) == params.sid) { finalScore = "" + team1Name + " " + team1.result + ", " + team2Name + " " + team2.result; } else if (("t" + team2.code_num) == params.sid) { finalScore = team1Name + " " + team1.result + ", " + team2Name + " " + team2.result + ""; } else { finalScore = team1Name + " " + team1.result + ", " + team2Name + " " + team2.result; } box = "Box"; gameday = "Gameday \"Launch"; // if we're on the main schedule page, display both recaps, otherwise just display this teams recap if (params.name == "display") { if (game.away.recap) { recap += "" + countryAbbr["t" + game.away.code_num] + " Recap"; } if (game.home.recap) { recap += "   " + countryAbbr["t" + game.home.code_num] + " Recap"; } } else { if (("t" + game.home.code_num) == 'wbc') { if (game.home.recap) { recap = "Recap"; } } if (("t" + game.away.code_num) == 'wbc') { if (game.away.recap) { recap = "Recap"; } } } html += ""; html += "" + gameTime.date + ""; if (params.type != "component") { html += " "; // placeholder } html += "" + finalScore + ""; html += "" + video + ""; html += "" + audio + ""; if (params.type != "component") { if ((params.type == "full") || (params.type == "team")) { html += "" + gameday + ""; html += "" + recap + ""; html += "" + box + ""; } html += " "; // extra } html += ""; return html; } // go thru a game object in the preview/recap data files, and rename // "gamer_home" to "home", and then go thru each item in teh array and // assign a new properties named the local to hold that info // // this allows for the syntax 'game.away.en' rather than hunting thru // each item in away every time function setupPreviewRecap(game, links, type) { if (!links) { return game; } try { var gameId = game.game_id.replace(/\//g, "_").replace(/\-/g, "_"); var gamelinks = links["gid_" + gameId]; game.away[type] = new Object(); game.home[type] = new Object(); if (type == "previews") { indexTypeHome = "preview_home"; indexTypeAway = "preview_away"; } else { indexTypeHome = "gamer_home"; indexTypeAway = "gamer_away"; } if (gamelinks && gamelinks[indexTypeAway]) { for (var i=0; i< gamelinks[indexTypeAway].length; i++) { if (gamelinks[indexTypeAway][i].language) { game.away[type][gamelinks[indexTypeAway][i].language] = gamelinks[indexTypeAway][i].url; } } } if (gamelinks && gamelinks[indexTypeHome]) { for (var i=0; i< gamelinks[indexTypeHome].length; i++) { if (gamelinks[indexTypeHome][i].language) { game.home[type][gamelinks[indexTypeHome][i].language] = gamelinks[indexTypeHome][i].url; } } } } catch (e) { return game; } return game; } function buildMedia(gameId, media, mediaType) { var imgBase = ""; try { var languages = [ "en", "es", "ja", "ko", "it", "nl", "fr", "zh" ]; var links = ""; var gameId = "gid_" + gameId; var game = media[gameId]; var gameMedia = game[mediaType]; /* test if script is sourced in from external source, ie. MLB mediaplayer */ var docUrl = document.URL.toLowerCase(); if((docUrl.indexOf("www.mlb.com") != -1) || (docUrl.indexOf("mlb.mlb.com") != -1)){ imgBase = "http://www.worldbaseballclassic.com"; } if (gameMedia) { for (var l=0; l\"Live"; break; case "video_archive": case "audio_archive": links += "\"Archive"; break; case "video_done": links += "\"Coming"; break; default: links += "\"Upcoming"; break; } } } } } } } catch (e) { return "\"Upcoming"; } if (links == "") { links = "\"Upcoming"; } return links; }