function pad(number){
return(100+number+"").slice(-2)
}
jQuery.getJSON(
'http://api.fotballdata.no/v1/clubs/1209/matches?clubid=1209&cid=362&cwd=BE7A1FB3-121F-4F28-A664-07FE384919DE&format=json&count=2&callback=?',
function(data) {
var kamper = [];
for (var i=0; i new Date())
kamper.push(data['Matches'][i]);
}
kamper.sort(function(a,b){return ((a.MatchStartDate < b.MatchStartDate) ? -1 : ((a.MatchStartDate > b.MatchStartDate) ? 1 : 0))});
for (var j=0; j<10; j++) { var kamp = kamper[j], d = new Date(parseInt(kamp.MatchStartDate.slice(6, -2))), fDate = pad(d.getDate())+'.'+pad(d.getMonth()+1)+'.'+' kl. '+pad(d.getHours()-2)+':'+pad(d.getMinutes()), where = kamp.HomeTeamClubId == 1209 ? 'H' : 'B', vsTeam = where == "H" ? kamp.AwayTeamName : kamp.HomeTeamName, team = where == "B" ? kamp.AwayTeamName : kamp.HomeTeamName, tmpName = kamp.TournamentName.indexOf(' avd') > 0 ? kamp.TournamentName.substring(0,kamp.TournamentName.indexOf(' avd')) : kamp.TournamentName,
fName = tmpName.indexOf('.div') > 2 ? tmpName.substring(0,tmpName.indexOf('.div') - 1) : tmpName,
tekst = fDate + ': ' + fName + ' mot ' + vsTeam + ' (' + where + ')',
title = kamp.TournamentName + ': ' + kamp.HomeTeamName + ' - ' + kamp.AwayTeamName,
a = jQuery('').attr('title',title).attr('target','_blank').attr('href','https://www.fotball.no/fotballdata/kamp/?fiksId=' + kamp.MatchId).text(tekst),
li = jQuery('
').append(a);jQuery('#kampDataLoading').remove();
jQuery('#res').append(li);
}
}
);