var holes = new Array();
var holeIndex = "hole1";
var isVideoPlaying = false;
var hasVideo=false;
/**************************************************************************
function to preload large hole images
**************************************************************************/
var cache = [];
function preloadHoleImage(which){
var cacheFound = false;
var cacheVidFound = false;
var cacheImage = document.createElement('img');
var cacheVidImage = document.createElement('img');
cacheImage.src = '/images/course/H_'+which+'.jpg';
cacheVidImage.src = holes[which].videothumb;
$.each(cache,function(){
if( cacheImage.src.indexOf( $(this).attr('src') ) > -1 ){ cacheFound = true; }
else {cacheFound = false; }
if( cacheVidImage.src.indexOf( $(this).attr('src') ) > -1 ){ cacheVidFound = true; }
else {cacheVidFound = false; }
});
if(!cacheFound) { cache.push(cacheImage); }
if(!cacheVidFound) { cache.push(cacheVidImage); }
}
/**************************************************************************
function to create hole objects
**************************************************************************/
function hole(){
this.number;
this.plant;
this.plantText;
this.holeDesc;
this.hist;
this.par;
this.yds;
this.highlink;
this.mediumlink;
this.lowlink;
this.videothumb;
this.videoslate;
}
/***************************************************************************
function to populate hole objects
***************************************************************************/
function setHoleObjects(xmlDoc){
$(xmlDoc).find("hole").each(function() {
var idx = "hole"+$(this).attr('number');
//preloadHoleImage(idx);
holes[idx] = new hole();
holes[idx].number = parseInt($(this).attr('number'));
holes[idx].plant = $(this).find('plant').text();
holes[idx].plantText = $(this).find('plantText').text();
holes[idx].holeDesc = $(this).find('holeDesc').text();
holes[idx].hist = $(this).find('hist').text();
holes[idx].par = $(this).find('par').text();
holes[idx].yds = $(this).find('yds').text();
holes[idx].videothumb = $(this).find('videothumb').attr('src');
holes[idx].videoslate = $(this).find('videoslate').attr('src');
holes[idx].highlink = $(this).find('highlink').attr('src');
holes[idx].mediumlink = $(this).find('mediumlink').attr('src');
});
//loadHole();
loadHoleGrid();
}
/***************************************************************************
function to load holes info into grid
***************************************************************************/
function loadHoleGrid(){
$('#hcgrid .holeGridItem').each(function(){
var currentHole = $(this).attr('id');
$(this).children('#holeImg').attr('src','/images/course/H_hole'+holes[currentHole].number+'_thumb.jpg');
$(this).children('.holeGridNumber').html(holes[currentHole].number);
$(this).children('.holeGridInfo').html('<div class="holeName">'+holes[currentHole].plant+'</div><div class="holeParYard">Par '+holes[currentHole].par+' - '+holes[currentHole].yds+' Yards</div>');
});
}
/***************************************************************************
function to load holes into div
***************************************************************************/
function loadHole(){
$('#hcgrid').hide();
$('#hcdetail').show();
if (holes[holeIndex]==undefined) {
holeIndex = 'hole1';
}
/* cache image for next/prev holes */
var nexthole = parseInt(holes[holeIndex].number)+1;
var prevhole = parseInt(holes[holeIndex].number)-1
if(nexthole > 18) { preloadHoleImage('hole1'); }
else{ preloadHoleImage('hole'+ nexthole); }
if(prevhole < 1) { preloadHoleImage('hole18'); }
else{ preloadHoleImage('hole'+ prevhole); }
/*if(holes[holeIndex].number == 1){ $('#previousHoleBtn').hide(); }
else { $('#previousHoleBtn').show(); }
if(holes[holeIndex].number == 18){ $('#nextHoleBtn').hide(); }
else { $('#nextHoleBtn').show(); }*/
$('#previousHoleBtn').show();
$('#nextHoleBtn').show();
$('#holeNumber').html(holes[holeIndex].number);
$('#holePlant').html(holes[holeIndex].plant);
$('#holePar').html(holes[holeIndex].par);
$('#holeYardage').html(holes[holeIndex].yds);
$('#holeImage').attr('src','/images/course/H_hole'+holes[holeIndex].number+'.jpg');
$('#holeDescription').html(holes[holeIndex].holeDesc);
$('#holePlantImg').attr('src','/images/course/P_hole'+holes[holeIndex].number+'.jpg');
$('#holeHistory').html(holes[holeIndex].hist);
$('#holeName').html(holes[holeIndex].plantText);
var highlink_trim = jQuery.trim(holes[holeIndex].highlink);
var mediumlink_trim = jQuery.trim(holes[holeIndex].mediumlink);
if (highlink_trim=='') {hasVideo=false;} else {hasVideo=true;}
if(hasVideo){
$('#holeFlyoverContainer').show();
$('#hcdetail #rightContent .more').hide();
$('#holeFlyoverContainer .image img').attr('src',holes[holeIndex].videothumb);
$('#holeFlyoverContainer .image').hover(
function(){
$(this).children('.imghover').show();
$(this).children('.icon').css('backgroundPosition','0px -20px');
},
function(){
$(this).children('.imghover').hide();
$(this).children('.icon').css('backgroundPosition','0px 0px');
}
);
$('#holeFlyoverContainer .image').unbind('click');
$('#holeFlyoverContainer .image').click(
function(){
var videotitle = "Hole No. "+holes[holeIndex].number+": "+holes[holeIndex].plant;
videotitle = videotitle.replace(/'/,"\\\'");
if(browser.isIPad || browser.isIPhone) {
playOverlayVideo(holes[holeIndex].mediumlink, holes[holeIndex].videoslate, videotitle);
if(browser.isIPad){
measureApp('Video Overlay','The Course','IPad','Flyover Video',videotitle);
} else {
measureApp('Video Overlay','The Course','IPhone','Flyover Video',videotitle);
}
} else {
playOverlayVideo(holes[holeIndex].highlink, holes[holeIndex].videoslate, videotitle);
measureApp('Video Overlay','The Course','Flyover Video',videotitle);
}
}
);
} else {
$('#holeFlyoverContainer').hide();
$('#hcdetail #rightContent .more').show();
}
// measure this
courseMeasure('Holes','Hole '+ holes[holeIndex].number);
}
function setHoleContent(){
$('#previousHoleBtn').click(function(){
// measure this
courseMeasure('Holes','Back');
if (holes[holeIndex].number != 1) {
holeIndex="hole"+(holes[holeIndex].number -1);
loadHole();
$('#holeImage').fadeIn('fast');
$('#holeHistoryContainer').fadeIn('fast');
//$('#holeFlyoverContainer').hide();
} else {
holeIndex="hole18";
loadHole();
$('#holeImage').fadeIn('fast');
$('#holeHistoryContainer').fadeIn('fast');
//$('#holeFlyoverContainer').hide();
}
});
$('#nextHoleBtn').click(function(){
// measure this
courseMeasure('Holes','Next');
if (holes[holeIndex].number != 18) {
holeIndex="hole"+(holes[holeIndex].number +1);
loadHole();
$('#holeImage').fadeIn('fast');
$('#holeHistoryContainer').fadeIn('fast');
//$('#holeFlyoverContainer').hide();
} else {
holeIndex="hole1";
loadHole();
$('#holeImage').fadeIn('fast');
$('#holeHistoryContainer').fadeIn('fast');
//$('#holeFlyoverContainer').hide();
}
});
}
$(document).ready(function(){
$.ajax({
url: "/en_US/xml/man/course/course.xml",
type: 'GET',
dataType: 'xml',
error: function(){
//alert('Error loading document');
},
success: function(xmlResp){
setHoleContent();
setHoleObjects(xmlResp);
//measureApp("Course","The Course - Holes","Hole Detail",holeIndex);
}
});
$('.holeGridItem').hover(
function(){ $(this).children('div.holeGridInfo').toggle(); $(this).children('div.holeGridNumber').toggleClass('selected'); },
function(){ $(this).children('div.holeGridInfo').toggle(); $(this).children('div.holeGridNumber').toggleClass('selected'); }
);
$('#hcgrid .holeGridItem').click(function(){
holeIndex = $(this).attr('id');
loadHole();
});
});
