

refreshRankingList = function()
        { 
            jQuery.getJSON("/RankingList/GetRankingList",
            function(json)
            {
                loading= jQuery("#rankingList #divLoadingRankingList");
                contents = jQuery("#rankingList #divContentsRankingList")

                // Abort if there is no ranking list on the page to update.
                if (contents.length==0)
                {
                    return;
                }

                loading.fadeIn(1000);
                contents.fadeOut(1000);
                
                // If no response was given, the compared ranking was not yet available.
                // Ask again in two seconds!
                if (json == "")
                {
                    setTimeout(refreshRankingList, 2*1000);
                    return;
                }                
                
                loading.fadeOut(1000);

                contents = jQuery("#rankingList #divContentsRankingList")

                while (contents[0].childNodes[0]) {
                    contents[0].removeChild(contents[0].childNodes[0]);
                }

                var table1=document.createElement("table");
                table1.id="tableRanking";
                table1.setAttribute("className","rankingList");

                table1body = document.createElement("tbody");
                table1.appendChild(table1body);

                headerRow = document.createElement("tr");
                table1body.appendChild(headerRow);

                cell= document.createElement("td");
                cell.appendChild( document.createTextNode( "Nr"));
                headerRow.appendChild(cell);

                cell= document.createElement("td"); 
                cell.appendChild( document.createTextNode("Navn"));
                headerRow.appendChild(cell);

                cell= document.createElement("td"); 
                cell.appendChild( document.createTextNode("Point"));
                headerRow.appendChild(cell);

                cell= document.createElement("td"); 
                cell.appendChild( document.createTextNode("Nr, tidl."));
                headerRow.appendChild(cell);

                cell= document.createElement("td"); 
                cell.appendChild( document.createTextNode("Nr (diff)"));
                headerRow.appendChild(cell);

                cell= document.createElement("td"); 
                cell.appendChild( document.createTextNode("Point, tidl."));
                headerRow.appendChild(cell);

                cell= document.createElement("td"); 
                cell.appendChild( document.createTextNode("Point (diff)"));
                headerRow.appendChild(cell);
                                
                jQuery.each(json.Lines, function(i, item)
                {
                    tmpRow= document.createElement("tr");
                    table1body.appendChild(tmpRow);

                    jQuery.each(item, function(j,subitem)
                    {
                        tmpCell= document.createElement("td");
                        tmpCell.appendChild( document.createTextNode(subitem.Text));
                        tmpCell.setAttribute("align", subitem.Align);
                        tmpRow.appendChild(tmpCell);
                    });
                });

                tmpRow=document.createElement("tr");
                table1body.appendChild(tmpRow);
                tmpCell = document.createElement("td");
                tmpCell.setAttribute("colSpan", table1body.firstChild.childNodes.length);
                tmpCell.setAttribute("class", "rankingListPeriod");
                tmpCell.setAttribute("id", "rankingListPeriod");
                tmpCell.appendChild( document.createTextNode(json.Period));
                tmpRow.appendChild(tmpCell);

                contents[0].appendChild(table1);
                
                jQuery(contents).fadeIn(1000);
                
                // Success! The ranking may change over time, however, and we refresh every two minutes.
                setTimeout(refreshRankingList, 2*60*1000);
            });         
        }
jQuery("rankingList").ready( refreshRankingList )
