/********************************************************************
functions to hilight player when selected in dropdown
*********************************************************************/
var prev_which;
function changePage(round){
var which = $('#round'+round+'players').val();
var which_name = $('#round'+round+'players :selected').text();
if(which != prev_which){
$("#"+prev_which).removeClass("highlight");
$("#"+which).addClass("highlight");
}
measureApp("Pairings","Player Dropdown",which_name);
prev_which = which;
}
/********************************************************************
functions to populate page
*********************************************************************/
function setPlayerList(){
for(var x=1; x<5; x++){
if (x == round_id){
$('#round'+x+'players').show();
} else {
$('#round'+x+'players').hide();
}
}
}
function writeRound12(){
setPlayerList();
$('#pairingsContentHeaders').hide();
$('#pairingsPlayerList').show();
$('#pairingsContent').html('');
var json_pairings = eval('json_doc.round'+round_id+'.group');
for(var x=0; x<json_pairings.length; x++){
var pairings_html = '';
var star = '';
if (json_pairings[x].tee == 10) {star='*';}
pairings_html+='<div class="pairings12GroupRow">';
pairings_html+='	<div class="pairings12GroupText">GROUP '+json_pairings[x].number+'</div>';
pairings_html+='	<div class="pairings12TimeText">'+json_pairings[x].time+' '+star+'</div>';
for(var i=0; i<json_pairings[x].player.length; i++){
if(json_pairings[x].player[i].name != ""){
if(i==0 || i==1 ){
pairings_html+='<div class="pairings12PlayerListing" id="'+json_pairings[x].player[i].id+'">';
}else{
pairings_html+='<div class="pairings12PlayerListing" style="margin-right:0px;" id="'+json_pairings[x].player[i].id+'">';
}
pairings_html+=' 	<div class="image"><img src="/images/players/small/'+json_pairings[x].player[i].id+'.jpg" width="76" height="102" border="0" alt="'+json_pairings[x].player[i].name+'"/></div>';
pairings_html+=' 	<div class="text">';
pairings_html+=' 	<a href="/en_US/players/player_'+json_pairings[x].player[i].id+'.html">'+json_pairings[x].player[i].name+'</a><br/>';
pairings_html+= 	json_pairings[x].player[i].nation;
pairings_html+=' 	</div>';
pairings_html+='</div>';
}
}
pairings_html+='</div>';
$('#pairingsContent').append(pairings_html);
}
}
function writeRound34(){
setPlayerList();
$('#pairingsContentHeaders').hide();
$('#pairingsPlayerList').show();
$('#pairingsContent').html('');
var json_pairings = eval('json_doc.round'+round_id+'.group');
for(var x=0; x<json_pairings.length; x++){
var pairings_html = '';
var star = '';
var style = '';
if (json_pairings[x].tee == 10) {star='*';}
if(x%2 == 0){ style="margin-right:20px;"; }
pairings_html+='<div class="pairings34GroupRow" style="'+style+'">';
pairings_html+='	<div class="pairings34GroupText">GROUP '+json_pairings[x].number+'</div>';
pairings_html+='	<div class="pairings34TimeText">'+json_pairings[x].time+' '+star+'</div>';
for(var i=0; i<json_pairings[x].player.length; i++){
if(json_pairings[x].player[i].name != ""){
if(i==0){
pairings_html+='<a name="'+json_pairings[x].player[i].id+'" class="anchorLink"></a><div class="pairings34PlayerListing" id="'+json_pairings[x].player[i].id+'">';
}else{
pairings_html+='<a name="'+json_pairings[x].player[i].id+'" class="anchorLink"></a><div class="pairings34PlayerListing" style="margin-right:0px;" id="'+json_pairings[x].player[i].id+'">';
}
pairings_html+=' 	<div class="image"><img src="/images/players/small/'+json_pairings[x].player[i].id+'.jpg" width="76" height="102" border="0" alt="'+json_pairings[x].player[i].name+'"/></div>';
pairings_html+=' 	<div class="text">';
pairings_html+=' 	<a href="/en_US/players/player_'+json_pairings[x].player[i].id+'.html">'+json_pairings[x].player[i].name+'</a><br/>';
pairings_html+= 	json_pairings[x].player[i].nation;
pairings_html+=' 	</div>';
pairings_html+='</div>';
}
}
pairings_html+='</div>';
$('#pairingsContent').append(pairings_html);
}
}
function writeCut(){
$('#pairingsContentHeaders').show();
$('#pairingsPlayerList').hide();
$('#pairingsContent').html('');
for(var x=0; x<json_doc.withdrawn.player.length; x++){
if(x%2 == 0){var row_class = "row1";}
else {var row_class = "row2"};
var player_html = "";
player_html+='<div class="'+row_class+' status">'+json_doc.withdrawn.player[x].status+'</div>';
player_html+='<div class="'+row_class+' player">';
player_html+=' <div class="image"><img src="/images/players/xsmall/'+json_doc.withdrawn.player[x].id+'.jpg" width="42" height="42" border="0" alt="'+json_doc.withdrawn.player[x].name+'"/></div>';
player_html+=' <div class="text">';
player_html+=' <span class="lightBlue"><a href="/en_US/players/player_'+json_doc.withdrawn.player[x].id+'.html">'+json_doc.withdrawn.player[x].name+'</a></span><br/>';
if (json_doc.withdrawn.player[x].nation) {
player_html+= json_doc.withdrawn.player[x].nation;
}
player_html+=' </div>';
player_html+='</div>';
player_html+='<div class="'+row_class+' par_total">'+json_doc.withdrawn.player[x].par_total+'</div>';
player_html+='<div class="'+row_class+' r1">'+json_doc.withdrawn.player[x].r1+'</div>';
player_html+='<div class="'+row_class+' r2">'+json_doc.withdrawn.player[x].r2+'</div>';
player_html+='<div class="'+row_class+' r3">'+json_doc.withdrawn.player[x].r3+'</div>';
player_html+='<div class="'+row_class+' r4">'+json_doc.withdrawn.player[x].r4+'</div>';
player_html+='<div class="'+row_class+' total">'+json_doc.withdrawn.player[x].total+'</div>';
$('#pairingsContent').append(player_html);
}
}
/********************************************************************
function to load data
*********************************************************************/
var round_id;
var found_latest = false;
var latest_round;
//var latest_round = 3;
var page_load = true;
var count = 4;
var json_doc;
function loadPairingsData(which){
if ($(".round"+which).hasClass("disabled")){
return;
} else {
round_id = which;
if(!page_load){
if(which != 5){ measureApp("Pairings","Tab","Round "+which); }
else {measureApp("Pairings","Tab","WD/Missing Cut");}
}
if(which == "1" || which == "2"){ writeRound12(); }
if(which == "3" || which == "4"){ writeRound34(); }
if(which == "5"){ writeCut(); }
}
}
function checkPairings(){
var which;
$.ajax({
url: "/en_US/xml/gen/scores/pairings.json",
type: 'GET',
dataType: 'json',
async: false,
error: function(){
//alert('Error loading document - '+test_url);
},
success: function(jsonResp){
json_doc = jsonResp;
for(var x=1; x<6; x++){
if(x != 5){
var round = "round"+x;
} else {
var round = "widthdrawn";
}
if(eval('json_doc.'+round) != "none"){
if(x != 5) {
found_latest = true;
latest_round = x;
}
if(x != 5){ $('#tabsPairings .'+round).children('a').removeClass('disabled'); }
else { $('#tabsPairings .wdmc').children('a').removeClass('disabled'); }
}
}
},
complete: function(){
$('.round'+latest_round+' a').addClass('selected');
loadPairingsData(latest_round);
}
});
}
$(document).ready(function(){
setTimeout('checkPairings()',1000);
$('#tabsPairings .button').each(function(){
$(this).children('a').addClass('disabled');
});
$('.button a').click(function(){
$('.button a').each(function(){
$(this).removeClass('selected');
});
$(this).addClass('selected');
});
$(".find").change(function(event){ //adapted from scroll.js (http://beski.wordpress.com/2009/04/21/scroll-effect-with-local-anchors-jquery/)
//prevent the default action for the click (change) event
event.preventDefault();
//get the value of the select list
var trgt = $(this).val();
//get the top offset of the target anchor
var target_offset = $("#"+trgt).offset();
var target_top = target_offset.top - 60;
//goto that anchor by setting the body scroll top to anchor top
$('html, body').animate({scrollTop:target_top}, 500);
});
});
page_load = false;

