function toggleLeaderBoard(){
var leaderBoard = document.getElementById("leaderBoard");
if( hasClass(leaderBoard, "open")){
removeClass(leaderBoard, "open");
}else{
leaderBoard.className += " open";
}
updateLeaderBoard()
}
function populateBoard(){
var listBoard = document.getElementById("listBoard");
var results = "";
var rankings = data.data.rankings;
var date = new Date();
var seconds = date.getSeconds();
var minutes = date.getMinutes();
var hour = date.getHours();
var leaderBoardServerJson = {};
leaderBoardServerJson.timeStamp = date.getTime();
for (var i = rankings.length - 1; i >= 0; i--) {
if( rankings[i].teamId == 235 ){
results += "
Updated "+hour+"h "+minutes+"m "+seconds+"s
";
results += "Cazziammolla Placement: "+rankings[i].rank+"
";
results += "with a score of: "+rankings[i].score+"
";
leaderBoardServerJson.placement = rankings[i].rank;
leaderBoardServerJson.score = rankings[i].score;
if (rankings[i].rank != points && points != 0){
ringTheBell();
}
points = rankings[i].rank;
}
};
leaderBoardServerJson.settings = [];
var settings = data.data.settings;
for (var i = 0; i < settings.length; i++) {
for (var j = settings[i].rankings.length - 1; j >= 0; j--) {
if(settings[i].rankings[j].teamId == 235){
results += ""+i+" | "+settings[i].rankings[j].rank+" | "+settings[i].rankings[j].score+" |
"
leaderBoardServerJson.settings[i] = { rank: settings[i].rankings[j].rank, score: settings[i].rankings[j].score};
}
};
};
var results = "Setting | Placement | Score | "+results+"
";
listBoard.innerHTML = results;
try{
socket.emit('leaderBoard', JSON.stringify( leaderBoardServerJson));
}catch(e){
console.log("error");
}
}
function updateLeaderBoard(){
loadRankingJs('https://davar.icfpcontest.org/rankings.js?cachebuster='+ new Date().getTime());
var intervalID = setInterval( function(){
loadRankingJs('https://davar.icfpcontest.org/rankings.js?cachebuster='+ new Date().getTime());
}, 30000);
}
function loadRankingJs(scriptName) {
var rankingScript = document.getElementById("rankingScript");
if ( rankingScript ){
removeId("rankingScript");
}
var docHeadObj = document.getElementsByTagName("head")[0];
var dynamicScript = document.createElement("script");
dynamicScript.type = "text/javascript";
dynamicScript.id = "rankingScript";
dynamicScript.src = scriptName;
dynamicScript.onload = function(){ populateBoard();};
docHeadObj.appendChild(dynamicScript);
return dynamicScript;
}
function ringTheBell(){
document.getElementById("bell").play();
}
document.onkeydown = checkKey;
function checkKey(e) {
e = e || window.event;
if (e.keyCode == '37') {
slideBack();
}else if(e.keyCode == '39') {
slideForward();
}
}