$(document).ready(function(){
    var currentpage = 0;

    $("a.pageselector").bind("click", switchPage);
    $("a.popup").bind("click", doPopup);
    
    // Init
    $("div#footer-home").fadeOut(500);
    doFadein();
    var aantal = $("table.schip").length;
    $("span#schip_van").html("1");
    $("span#schip_tot").html("" + ((aantal < 6) ? aantal : 6));

    function doPopup(e)
    {
        e.preventDefault();
        var wnd = window.open($(this).attr("href"), "bs24popup", "scrollbars=1,resizable=1,location=0,menubar=0,directories=0,toolbar=0,status=0");
    }

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

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

    function doFadein()
    {
        for(i = 0; i < 6; i++)
        {
            $("table#schip-" + ((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);
    }
});