function getTeamDivision( teamNo ) {
        return teamDivisions[ teamNo - 1 ];
}

$(document).ready( function() {
    // Add classes for the teams
    var $gameCells  = $(".teams");
    var $dateCells  = $(".sched-date");

    // On load, show the Highlight Games bar and set the radio button filter to All Games
    $(".schedule-search-opts").show();
    $("input[name=rbGameFilter]").filter("[value=all]").attr("checked", true);

    $gameCells.each( function(index) {
        // Split out the teams, then add classes to the divs so they can be highlighted
        var gameText    = $(this).text();
        var teams;

        gameText    = $.trim(gameText);
        teams   = gameText.split("-");

        $(this).addClass( "team-" + teams[0] );
        $(this).addClass( "team-" + teams[1] );

        if ( getTeamDivision( teams[0] ) == getTeamDivision( teams[1] ) ) {
            $(this).parent().addClass("divisional");
        }
    });

    $dateCells.each( function(index) {
        // Add classes to the divs so they can be highlighted
        var $dateCell   = $(this);

        $dateCell.addClass( "sched-date-" + $(this).text() );
        $dateCell.click( function () {
            $(this).parent().parent().toggleClass("selected-date-row");
            $(this).toggleClass("selected-date");
            $(this).addClass("ui-corner-all");
            highlightGames();
        });
    });

    $(".team-assignment").click( function(event) {
        $(this).toggleClass("selected-team");
        $(this).addClass("ui-corner-all");
        highlightGames();
    });

    $("input[name=rbGameFilter]").click( function(event) {
        highlightGames();
    });

//    $('#schedule tbody tr:nth-child(odd)').addClass('odd');
});

function highlightGames() {
    var selectedTeams       = $(".team-assignments-table .selected-team");
    var selectedDateRows    = $("#schedule .selected-date-row");
    var selector            = "";
    var games               = null;
    var gameFilter          = $("input[name=rbGameFilter]:checked").val();

    $("#schedule .game").removeClass("highlight");

    // Nothing is selected, let's get out of here
    if ( selectedDateRows.length == 0 && selectedTeams.length == 0 && gameFilter == "all" ) {
        return;
    }

    if ( selectedDateRows.length > 0 ) {
        games   = $("#schedule .selected-date-row .teams");
    } else {
        games   = $("#schedule .teams");
    }

    selectedTeams.each( function(index) {
        games       = games.filter( ".team-" + parseInt( $(this).text() ) );
    });

    // Filter out divisional, non-divisional games
    switch (gameFilter) {
        case "div" :
            games   = games.parent(".divisional");
            break;
        case "nondiv" :
            games   = games.parent(":not(.divisional)");
            break;
        case "all" :
        default:
            games   = games.parent(".game");
            break;
    }

//    if ( games ) {
        games.addClass("highlight").addClass("ui-corner-all");
//    }
}



