﻿$(document).ready(function() {
    //round rows
    var rounds = $("tr.roundrow");
    //add closed class to all round rows
    $(rounds).addClass("closed");
    //change class to open for the latest round
    var lastround = $(rounds).filter(":last");
    lastround.removeClass("closed");
    lastround.addClass("open");
    //hide all rows after the last round
    var tr = $(lastround).nextAll('tr');
    $("tr").hide();
    tr.show();
    rounds.show();
    //pointer hover
    $("tr.roundrow").hover(function() {
        $(this).css({'cursor' : 'pointer'});
    }, function() {
        $(this).css({'cursor' : 'none'});
    });
    
    //expand/collapse rows
	$("tr.roundrow").click(function() {
	    $(this).toggleClass("open");
	    $(this).toggleClass("closed");
	    //row clicked
        var tr = $(this).nextAll('tr');
        for (i = 0; i < tr.length; i++) {
          var rowclass = $(tr[i]).attr('class');
          if (rowclass != 'roundrow' && rowclass != 'roundrow open' && rowclass != 'roundrow closed') {
            $(tr[i]).toggle($(tr[i]).css('display') == 'none');            
          }
          else {
            break;
          }
        }
    });
});
