$(document).ready(function(){
    
    var urlParams = getUrlVars();   
    var pageOption = getUrlVars()["option"];
    if(pageOption == undefined) {
        pageOption = "home";
    }
    $("body").addClass("option-" + pageOption);
    
    //Wedstrijdschema
    if(pageOption == 100) { updateWedstrijdschema(); }
    
    //Teampagina
    if(pageOption == 101) { updateTeampagina(); }
    
    //Barrooster
    if(pageOption == 10017) { updateBarrooster(); }
    
    //Organisatie
    if(pageOption == 850) { updateOrganisatie(); }
    
    //Trainingsschema
    if(pageOption == 960) { updateTrainingsSchema(); }
    
    //Logged on, Team
    if(pageOption == 710) { updateMijnTeampagina(); }

    //Logged on, Team
    if(pageOption == 825) { updateTeamprofiel(); }

    //Logged on, Mijnschema
    if(pageOption == 780) { updateMijnSchema(); }

    //Logged on, Mijn rijschema
    if(pageOption == 715) { updateMijnRijschema(); }

    //Logged on, Mijn Verjaardagen
    if(pageOption == 900) { updateVerjaardagen(); }
    
    //Logged on, Instellingen
    if(pageOption == 730) { updateInstellingen(); }
    
});

function updateTeampagina() 
{
    resetTable();
    $("#column-2 form[name='frm_WedstrijdenTeam']").hide();
    $('#column-2 table td').removeAttr("style");
    $("#column-2 table td:contains('Spelers ')").parents("table").addClass("spelers");
    $("#column-2 table td:contains('Spelers ')").parent().addClass("head");
    $("#column-2 table td:contains('Teamfoto')").parent().addClass("head");
    $("#column-2 table td:contains('Teamondersteuning')").parents("table").addClass("teamondersteuning");
    $("#column-2 table td:contains('Teamondersteuning')").parent().addClass("head");
    $("#column-2 table td:contains('Stand in de poule')").parents("table").addClass("stand");
    $("#column-2 table td:contains('Pntn')").parent().addClass("subhead");
    $("#column-2 table td font:contains('wedstrijdschema')").parents("table").addClass("schema");
    $("#column-2 table.schema td:contains('Leerdam')").addClass("leerdam");
    $("#column-2 table td font:contains('wedstrijden:')").parents("table").addClass("agenda");

}

function updateMijnTeampagina() {
        resetTable();
        $("#column-2 table font").removeAttr("color");
        $("#column-2 table").removeAttr("style");
        $("#column-2 table:first").addClass("team");
        $("#column-2 table.team tr:nth-child(2)").addClass("head");
        $("#column-2 table.team tr:nth-child(3)").addClass("subhead");
        $("#column-2 table td font:contains('Training:')").parents("table").addClass("training");
        $("#column-2 table.training tr:nth-child(2)").addClass("subhead");

        $("#column-2 table td font:contains('wedstrijden:')").parents("table").addClass("agenda");
        $("#column-2 table.agenda tr:nth-child(2)").addClass("subhead");
        
        $("#column-2 table td font:contains('Rijschema:')").parents("table").addClass("rijschema");
        $("#column-2 table.rijschema tr:nth-child(2)").addClass("subhead");
        $("#column-2 table.rijschema tr:nth-child(2) font").removeAttr("class");
        
        $("#column-2 table td font:contains('poule')").parents("table").addClass("stand");
        $("#column-2 table.stand tr:nth-child(2)").addClass("subhead");
}

function updateTeamprofiel() {
        resetTable();
        $("#column-2 table").removeAttr("style");
}

function updateMijnRijschema() {
        resetTable();
        $("#column-2 table").removeAttr("style");
        $("#column-2 table tr:nth-child(2)").addClass("subhead");
        $("#column-2 table tr td b").unwrap();
}

function updateVerjaardagen() {
        resetTable();
        $("#column-2 table").removeAttr("style");
        $("#column-2 table tr:nth-child(1)").addClass("head");
        $("#column-2 table tr:nth-child(1) td font").removeAttr("color");
        $("#column-2 table tr:nth-child(2)").addClass("subhead");
}

function updateInstellingen() {
        resetTable();
        $("#column-2 table").removeAttr("style");
        $("#column-2 table tr:nth-child(1)").addClass("head");
        $("#column-2 table tr td[colspan='3']").parent().addClass("empty");
        $("#column-2 table tr td font:contains('Wachtwoord wijzigen')").parents("tr").addClass("head");

}

function updateMijnSchema() {
        resetTable();
        $("#column-2 table").removeAttr("style");
        $("#column-2 table").addClass("info");
        $("#column-2 table.info tr:nth-child(2)").addClass("subhead");
}

function updateBarrooster() {
    resetTable();
    $('#column-2 table').unwrap();
    $("#column-2 table td[colspan='4']").addClass("date");  
}

function updateTrainingsSchema() {
    resetTable();
    $('#column-2 table td').removeAttr("style");
    $("#column-2 table td[colspan='5']").parent().addClass("head"); 
    $("#column-2 table tr.head").next().addClass("subhead");
}


function updateOrganisatie() {
    resetTable();

		var linkInformatie = "http://www.hcleerdam.nl/site/default.asp?Option=2500&CatID=4#e-mailadressen";
		
    $("#headlines_page_header_container").append('<p>Klik <a style="color:#1985B5;" href="' + linkInformatie + '">hier</a> voor de algemene HCL e-mailadressen</p>');

    $("#column-2 table td[colspan='5']").parents("tr").addClass("subsection");  
    $("#column-2 table td[colspan='5'] b").parents("tr").addClass("section");   
    $("#column-2 table tr td").removeAttr("style");
}

function updateWedstrijdschema() {
    
    $("#column-2 form[name='form_wedstrijden']").hide();
    resetTable();

    var linkBarrooster = "http://hcleerdam.nl/site/default.asp?option=10017&m=9";
    
    $("#headlines_page_header_container").next().hide();
    $("#headlines_page_header_container").append('<p>Klik <a style="color:#1985B5;" href="' + linkBarrooster + '">hier</a> voor het barrooster</p>');
    
    
    // Hide de reistijd
    columnIndex = 3;
    $('#column-2 table td:nth-child('+(columnIndex+1)+')').hide();

    
    $("#column-2 table td:contains(': ')").parent().addClass("comments");
    $("#column-2 table td:contains(': ')").prev().attr("colspan","1");
    $("#column-2 table td:contains(': ') font").removeAttr("color");        

    $("#column-2 table td:nth-child(1)").css("width","20%");
    $("#column-2 table td:nth-child(2)").css("width","8%");
    $("#column-2 table td:nth-child(3)").css("width","30%");
    $("#column-2 table td:nth-child(4)").css("width","8%");
    $("#column-2 table td:nth-child(5)").css("width","8%");
    $("#column-2 table td:nth-child(6)").css("width","8%");
    $("#column-2 table td:nth-child(7)").css("width","18%");
    $("#column-2 table td:nth-child(8)").css("width","6%");
    $("#column-2 table td[colspan='8']:parent").hide();
    $("#column-2 table td[colspan='8']:contains('--'):parent").show();
    $("#column-2 table td:contains('Rijders')").css("font-weight","bold");
}

function resetTable() 
{
    $('#column-2 table').attr("cellspacing","0");
    $('#column-2 table').attr("cellpadding","0");
    $('#column-2 table td').removeAttr('width');
    $('#column-2 table td').removeAttr('align');
    $("#column-2 table td").css("padding-left","3px");
    $("#column-2 table td").css("padding-top","3px");
    $("#column-2 table td").css("padding-bottom","3px");
}

/* functie om de URL parameters uit te lezen */
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0].toLowerCase()] = hash[1];
    }
    return vars;
}
