page_section = "Players";
var page_load = true;
/********************************************************************
function to remove all player data
*********************************************************************/
function clearPlayerData(){
$("#currentInfo").html('');
$("#flagName").html('');
$('.overviewPicture').html('');
$('.overviewStats').html('');
$("#overviewBar").html('');
$('.overviewText').html('');
$('#playerNews').html('');
$('#video-content-holder').html('');
$('#playerPhotosImage').html('');
$('#playerPhotosCredit').html('');
$('#playerPhotoCaption').html('');
$("#playerPhotosNavPrevious").html('');
$("#playerPhotosNavPrevious").html('');
$('#photo-content-holder').html('');
$("#results-scroll-content").html('')
}
/********************************************************************
function to load player current info
*********************************************************************/
function loadPlayerInfo(){
$("#currentInfo").append('Position: '+player_info.scores.score.position+'<span style="margin:0px 7px;">|</span>');
$("#currentInfo").append('Status: '+player_info.scores.score.status+'<span style="margin:0px 7px;">|</span>');
if(player_info.scores.score.playing == "") {
var playing_text = 'Currently: In the Clubhouse';
} else {
if(player_info.scores.score.playing == "MC") {
var playing_text = 'Missed Cut';
} else if(player_info.scores.score.playing == "WD") {
var playing_text = 'Widthdrawn';
} else {
if(player_info.scores.score.playing.indexOf(":") != -1){
var playing_text = 'Tee Time: '+player_info.scores.score.playing;
} else {
var playing_text = 'Currently: Playing Hole '+player_info.scores.score.playing;
}
}
}
$("#currentInfo").append(playing_text);
}
/********************************************************************
function to load player overview data
*********************************************************************/
function loadPlayerOverview(data){
if(data && data == "none"){
$('.overviewText').html('<div style="width:748px; text-align:center;">There is no bio information for this player.</div>');
} else {
s.prop24 = player_bio.bio.player.firstname +" "+player_bio.bio.player.lastname;
$("#flagName").html('<img src="/images/flags/'+player_bio.bio.player.nationcode+'_sm.gif" width="26" height="16" border="0" alt="'+player_bio.bio.player.nation+'""/>'+player_bio.bio.player.firstname+' '+player_bio.bio.player.lastname);
$('.overviewPicture').html('<img src="/images/players/'+player_id+'.jpg" width="115" height="154" border="0" alt="'+player_bio.bio.player.firstname+' '+player_bio.bio.player.lastname+'"/>');
$('.overviewStats').append('<div class="statsRow"><div class="stat">Birthdate:</div> <div class="data">'+player_bio.bio.player.birthdate+'</div></div>');
$('.overviewStats').append('<div class="statsRow"><div class="stat">Country:</div> <div class="data">'+player_bio.bio.player.nation+'</div></div>');
$('.overviewStats').append('<div class="statsRow"><div class="stat">Best Masters Finish:</div> <div class="data">'+player_bio.bio.player.best+'</div></div>');
if(player_bio.bio.player.best.indexOf("First") == -1){
$('.overviewStats').append('<div class="statsRow"><div class="stat">First/Last Year:</div> <div class="data">'+player_bio.bio.player.firstlast+'</div></div>');
$('.overviewStats').append('<div class="statsRow"><div class="stat">Tournaments Entered:</div> <div class="data">'+player_bio.bio.player.tournaments+'</div></div>');
$('.overviewStats').append('<div class="statsRow"><div class="stat">Cuts Made:</div> <div class="data">'+player_bio.bio.player.cuts+'</div></div>');
$('.overviewStats').append('<div class="statsRow"><div class="stat">Rounds Played:</div> <div class="data">'+player_bio.bio.player.rounds+'</div></div>');
$('.overviewStats').append('<div class="statsRow"><div class="stat">Money Won:</div> <div class="data">$'+player_bio.bio.player.money+'</div></div>');
$(".overviewStatsMore").show();
$('.overviewStatsMore').append('<div class="statsRow"><div class="stat">Scoring Avg:</div> <div class="data">'+player_bio.bio.player.avg+'</div></div>');
$('.overviewStatsMore').append('<div class="statsRow"><div class="stat">Low Round:</div> <div class="data">'+player_bio.bio.player.low+'</div></div>');
$('.overviewStatsMore').append('<div class="statsRow"><div class="stat">High Round:</div> <div class="data">'+player_bio.bio.player.high+'</div></div>');
$('.overviewStatsMore').append('<div class="statsRow"><div class="stat">Rounds Under Par:</div> <div class="data">'+player_bio.bio.player.underpar+'</div></div>');
} else {
$(".overviewStatsMore").hide();
}
$('.overviewText').html(player_bio.bio.player.overview);
}
}
/********************************************************************
function to load player scores
*********************************************************************/
function loadPlayerScores(){}
/********************************************************************
function to load player articles
*********************************************************************/
function loadPlayerArticles(data){
if(data && data == "none"){
$('#playerNews').html('<div style="width:748px; text-align:center;">There is no news for this player.</div>');
} else {
var article_html = "";
$.each(player_articles.news.article,function(x){
if(x%2 == 0){var divClass = "playerNewsLeft";}
else{var divClass = "playerNewsRight";}
if(x%2 == 0){
article_html+='<div class="playerNewsRow">';
}
article_html+=' <div class="'+divClass+'">';
if(this.image != ""){
article_html+=' <div class="playerNewsPhoto"><a href="'+this.link+'"><img src="'+this.image+'" width="157" height="88" border="0" alt=""/></a></div>';
} else {
article_html+='	 <div class="playerNewsPhoto"><a href="'+this.link+'"><img src="/images/misc/Generic_graphic1.jpg" width="157" height="88" border="0" alt=""/></a></div>';
}
article_html+=' <div class="playerNewsText">';
article_html+=' <a href="'+this.link+'" class="articleTitleLink">'+this.title+'</a>';
if(this.video != "no"){
article_html+=' <div style="float:left; display:inline; margin:0px 3px;"><a href="'+this.link+'"><img style="display:inline;" src="/images/misc/video-icon.gif" width="20" height="11" border="0" alt="Video Available"/></a></div>';
}
article_html+=' <p class="noMargin">'+this.text+'</p>';
article_html+=' </div>';
article_html+=' </div>';
if(x%2 != 0){
article_html+='</div>';
}
if(x == player_articles.news.article.length-1 && x%2 == 0){
article_html+='</div>';
}
});
$('#playerNews').html(article_html);
}
}
/********************************************************************
functions for player player photos
*********************************************************************/
var currIndex;
var playerGallerySlider;
function initPlayerSlider(selector){
var pSliderObj= $(selector).bxSlider({
infiniteLoop: false,
hideControlOnEnd: true,
displaySlideQty: 5,
moveSlideQty: 5
});
return pSliderObj;
}
/* change selected image */
function changeSelectedThumb(sel){
$('#.pgalleryItem a').each(function(){ $(this).removeClass('selected'); });
$('#playersGalleryList #photo'+sel+' a').addClass('selected');
}
/* load selected image */
function loadImage(which){
var imgOrientation;
currIndex = which;
var galleryLength = player_photos.gallery.item.length;
changeSelectedThumb(which);
if(playerGallerySlider != undefined){playerGallerySlider.goToSlide(which);}
$.each(player_photos.gallery.item, function(index,value) {
if(this.number == which) {
if(this.imagewidth == "748"){imgOrientation = "landscape";}
if(this.imagewidth == "380"){imgOrientation = "portrait";}
$('#playerPhotosImage').html('<img class="'+imgOrientation+'" src="'+ this.imagefile +'" width="'+ this.imagewidth +'" height="'+ this.imageheight +'" border="0" alt="'+ this.scaption +'"/>');
$('#playerPhotosCredit').html('&copy; '+ this.credit);
$('#playerPhotosCaption').html(this.lcaption);
if(index > 0) {
$("#playerPhotosNavPrev").html('<a href="javascript:loadImage(\''+ eval(index-1) +'\',\'Left\');"><img class="jumpPrev" src="/images/misc/photo_prev_lg.png" width="374" height="420" border="0" alt="Previous Image"/></a>');
} else {
$("#playerPhotosNavPrev").html('');
}
if(index < galleryLength-1) {
$("#playerPhotosNavNext").html('<a href="javascript:loadImage(\''+ eval(index+1) +'\',\'Right\');"><img class="jumpNext" src="/images/misc/photo_next_lg.png" width="374" height="420" border="0" alt="Next Image"/></a>');
} else {
$("#playerPhotosNavNext").html('');
}
if (arguments.length > 1){
if (arguments[1] != 'init'){
// Measurement - if this isnt an image load from an initial gallery load, then capture Next/Previous
measureApp("Newsroom","Photos",player_photos.gallery.title[0],arguments[1]);
}
} else {
// Measurement -- this is the result of someone clicking a thumbnail, measure it
measureApp("Newsroom","Photos",player_photos.gallery.title[0],photoTitle);
}
}
});
}
/* load player gallery images */
function loadPlayerPhotos(data){
if(data && data == "none"){
$('#playerPhotos').html('<div style="width:748px; text-align:center;">There are no photos for this player.</div>');
} else {
$.each(player_photos.gallery.item, function(index,value){
if (x == 0){
$('#playersGalleryList').append('<li><div id="photo'+ this.number +'" class="pgalleryItem"><a class="selected" href="javascript:loadImage(\''+ this.number +'\');"><img src="'+ this.thumbfile +'" width="128" height="72" border="0" alt="'+ this.scaption +'"/></a></div></li>');
} else {
$('#playersGalleryList').append('<li><div id="photo'+ this.number +'" class="pgalleryItem"><a href="javascript:loadImage(\''+ this.number +'\');"><img src="'+ this.thumbfile +'" width="128" height="72" border="0" alt="'+ this.scaption +'"/></a></div></li>');
}
});
$('.pgalleryItem a').click(function(){
$('.pgalleryItem a').each(function(){ $(this).removeClass('selected'); });
$(this).addClass('selected');
});
loadImage('0','init'); // 2nd arg 'init' used to stop measurement of default image load
}
}
/***************************************************************************
functions for fullScreen flash app
***************************************************************************/
function getGalleryInfo(){
measureApp('Players','Photos','go_fs',player_photos.gallery.item[currIndex].hdimage);
swfobject.getObjectById('photosHDButton').setInitialImage(player_photos.gallery.item[currIndex].hdimage, currIndex, player_photos.gallery.item.length, player_photos.gallery.longdate);
}
function getImageInfo(which){
measureApp('Players','Photos','next/prev',player_photos.gallery.item[currIndex].hdimage);
swfobject.getObjectById('photosHDButton').setSubsequentImage(player_photos.gallery.item[which].hdimage);
}
function getText(which){
if (photoDebug){
traceDebug("getText: " + player_photos.gallery.item[which].credit + ", " + player_photos.gallery.item[which].lcaption);
}
swfobject.getObjectById('photosHDButton').setCreditCaption(escape(player_photos.gallery.item[which].credit), escape(player_photos.gallery.item[which].lcaption));
}
/********************************************************************
function to load player results data
*********************************************************************/
function loadPlayerResults(data){
if(data && data == "none"){
$('#playerResultsContent').html('<div style="width:748px; text-align:center;">There are no results for this player.</div>');
} else {
$.each(player_results.history.results, function(x,val){
if(x%2 == 0){var rowClass = "row1";}
else{var rowClass = "row2";}
rhtml = "";
if(this.position == ""){this.position = "-";}
if(this.r1 == "0"){this.r1 = "-";}
if(this.r2 == "0"){this.r2 = "-";}
if(this.r3 == "0"){this.r3 = "-";}
if(this.r4 == "0"){this.r4 = "-";}
rhtml+='<div class="'+rowClass+'">';
rhtml+='<div class="year">'+this.year+'</div>';
rhtml+='<div class="position">'+this.position+'</div>';
rhtml+='<div class="r1">'+this.r1+'</div>';
rhtml+='<div class="r2">'+this.r2+'</div>';
rhtml+='<div class="r3">'+this.r3+'</div>';
rhtml+='<div class="r4">'+this.r4+'</div>';
rhtml+='<div class="total">'+this.total+'</div>';
rhtml+='<div class="money">$'+this.money+'</div>';
rhtml+='</div>';
$("#playerResultsContent").append(rhtml);
});
}
}
/********************************************************************
measurement functions
*********************************************************************/
function viewPlayerOverview(){
if ( $('#overviewTab:not(.ui-tabs-disabled)') ){ checkVideo(); }
measureApp(page_section,s.prop24,'Overview');
}
function viewPlayerScores(){
if ( $('#scoresTab:not(.ui-tabs-disabled)') ){ checkVideo(); }
$('#tabsBio').tabs('select',1);
if(!page_load){
measureApp(page_section,s.prop24,'Scores');
page_load = false;
}
}
function viewPlayerNews(){
if ( $('#newsTab:not(.ui-tabs-disabled)') ){ checkVideo(); }
measureApp(page_section,s.prop24,'News');
}
function viewPlayerVideos(){
// link to video... if on iOS device, use mediumlink
var videoLink = videos[0].highlink;
if(browser.isIPad || browser.isIPhone) {
videoLink = videos[0].mediumlink;
}
if (!video_playing){writeInlinePlayer('videoPlayer',latestImageFile, videos[0].lowlink, videoLink)}
measureApp(page_section,s.prop24,'Video');
}
function viewPlayerPhotos(){
if ( $('#photosTab:not(.ui-tabs-disabled)') ){ checkVideo(); }
measureApp(page_section,s.prop24,'Photos');
}
function viewPlayerResults(){
if ( $('#resultsTab:not(.ui-tabs-disabled)') ){ checkVideo(); }
measureApp(page_section,s.prop24,'Results');
}
/***************************************************************************
functions to execute on page load
***************************************************************************/
$(document).ready(function(){
/* initialize tabs with all disabled */
$('#tabsBio').tabs({disabled:[0,1,2,3,4]});
/* initialize slider when photo tab is clicked */
$('#tabsBio').bind('tabsshow', function(event, ui) {
if (ui.index==3) {	// PHOTOS tab
playerGallerySlider = initPlayerSlider('#playersGalleryList');
playerGallerySlider.goToSlide(0);
}
});
if(browser.isIPad || browser.isIPhone) {
// set in iPad specific stylesheets
}
// all others
else {
/* add hover state for photo next/prev arrows */
$('#playerPhotosNavNext').hover(
function(){	$('#playerPhotosNavNext .jumpNext').show(); },
function(){	$('#playerPhotosNavNext .jumpNext').hide(); }
);
$('#playerPhotosNavPrev').hover(
function(){	$('#playerPhotosNavPrev .jumpPrev').show(); },
function(){	$('#playerPhotosNavPrev .jumpPrev').hide(); }
);
}
/* change page when player is selected in dropdown */
$('#page').bind('change', function(event,ui){
var page_id = $(this).val();
if(page_id != ""){
clearPlayerData();
document.location.href="/en_US/players/player_"+page_id+".html";
}
});
});
/********************************************************************
functions to check video
*********************************************************************/
var video_playing = false;
function checkVideo(){
if(video_playing){stopVideo('videoPlayer'); video_playing=false;}
}
/***************************************************************************
load player json files
***************************************************************************/
var json_url;
var path;
var player_bio;
var player_articles;
var player_history;
var player_photos;
var player_scores;
var videos;
var player_videos;
var player_files = new Array();
var disabled_tabs = new Array();
function loadPlayerData(json_url,tab_id){
$.ajax({
url: json_url,
type: 'GET',
dataType: 'json',
error: function(){
alert('Error loading document - '+json_url);
},
success: function(jsonResp){
if(json_url.indexOf("scores") != -1){
player_info = jsonResp;
if(player_info.none != ""){
if(player_info.scores.score.position != "" || player_info.scores.score.status != ""){ $('#tabsBio').tabs('enable',1); }
loadPlayerInfo();
}
}
if(json_url.indexOf("bios") != -1){
player_bio = jsonResp;
var overview_tab = tab_id;
if(player_bio.none != ""){ $('#tabsBio').tabs('enable',0); loadPlayerOverview(); }
}
if(json_url.indexOf("articles") != -1){
player_articles = jsonResp;
var articles_tab = tab_id;
if(player_articles.none != ""){ $('#tabsBio').tabs('enable',2); loadPlayerArticles(); }
}
if(json_url.indexOf("photos") != -1){
player_photos = jsonResp;
var photos_tab = tab_id;
if(player_photos.none != ""){ $('#tabsBio').tabs('enable',3); loadPlayerPhotos(); }
}
if(json_url.indexOf("history") != -1){
player_results = jsonResp;
var results_tab = tab_id;
if(player_results.none != ""){ $('#tabsBio').tabs('enable',4); loadPlayerResults(); }
}
}, complete: function(){
viewPlayerScores();
}
});
}
function getPlayerFiles(){
var file_url = "/en_US/xml/gen/players/"+player_id+".json";
$.ajax({
url: file_url,
type: 'GET',
dataType: 'json',
error: function(){
//alert('Error loading document - '+file_url);
},
success: function(jsonFiles){
var json_files = jsonFiles.files;
var count = 0;
for (var key in json_files) {
path = "/en_US/xml/gen/players/"+json_files[key];
loadPlayerData(path,count);
count++;
}
}
});
}
getPlayerFiles();

