$(document).ready(function(){
    var currentpage = 0;
    $("a.pageselector").bind("click", switchPage);

    // Init
    $("div#footer-home").fadeOut(500);
    $("div.hr").hide();
    doFadein();
    var aantal = $("table.bericht").length;
    $("span#bericht_van").html("1");
    $("span#bericht_tot").html("" + ((aantal < 6) ? aantal : 6));

    function switchPage()
    {
        id = $(this).attr("id");
        currentpage = parseInt(id.replace("pageselector-", ""));
        $("div#footer-home").fadeOut(500);
        $("table.bericht").fadeOut(500);
        $("div.hr").fadeOut(500);
        setTimeout(doFadein, 500);

        $("span#bericht_van").html("" + (currentpage * 6 + 1));
        $("span#bericht_tot").html("" + ((aantal < (currentpage + 1) * 6) ? aantal : (currentpage + 1) * 6));
    }

    function doFadein()
    {
        for(i = 0; i < 6; i++)
        {
            $("table#bericht-" + ((currentpage * 6) + i)).fadeIn(1000, setHeight);
            $("div#hr-bericht-" + ((currentpage * 6) + i)).fadeIn(1000, setHeight);
        }
    }

    function setHeight()
    {
        var height = $("div#content").height() + 115 + 285;
        if($("div#footer-home").css("position") == "static")
        {
            height = height - 245;
        }
        var bheight = $(window).height();

        if(height <= bheight)
        {
            $("div#footer-home").css("position", "fixed");
            $("div#footer-home").css("bottom", "0px");
        }
        else
        {
            $("div#footer-home").css("position", "static");
        }
        $("div#footer-home").fadeIn(500);
    }
});