﻿$(document).ready(function () {
    var heightContent = $("#content").height();
    var heightNavigation = $("#navigationList").height();
    var objHeights = 0;
    $("#content object").each(function() {
	objHeights += parseInt($(this).attr("height"));
    });
    heightContent = (heightContent + objHeights);
    //alert(heightContent);
    if (heightContent > heightNavigation) {
        $("#navigationList").css('height', heightContent);
        $("#linkList").css('height', heightContent);
    }
    else {
        $("#content").css('height', heightNavigation);
        $("#linkList").css('height', heightNavigation);
    }

    /* This is basic - uses default settings */
    $("a.single_image").fancybox();

    /* Using custom settings */
    $("a#inline").fancybox({
        'hideOnContentClick': true
    });

    $("a.group").fancybox({
        'speedIn': 600,
        'speedOut': 200,
        'overlayShow': false
    });

    $("ul.sf-menu").supersubs({
        minWidth: 10,   // minimum width of sub-menus in em units 
        maxWidth: 27,   // maximum width of sub-menus in em units 
        extraWidth: 1     // extra width can ensure lines don't sometimes turn over 
        // due to slight rounding differences and font-family 
    }).superfish({ dropShadows: false });  // call supersubs first, then superfish, so that subs are 
    // not display:none when measuring. Call before initialising 
    // containing tabs for same reason.

    $("#datepicker").datepicker({
        onChangeMonthYear: function (year, month, inst) { agenda(year, month, inst) }
    });
});

function agenda(y,m,i) {
    var agenda = $("#agenda");
    $.get('/usercontrols/Agenda/agenda.ashx?jaar=' + y.toString() + '&maand=' + m.toString() + '', function(data) {
        var listitems = "";
        var months = [ "januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december" ];
        listitems += "<h3>Evenementen in " + months[m - 1] + " " + y + "</h3>";
        listitems += "<ul>";
        var rootNodes = $(data).children();
        $(rootNodes).each(function(i) {
            listitems += parseNode($(this)[i],y,m);
        });
        listitems += "</ul>";
        agenda.html(listitems);
    });
}

function parseNode(node,year,month) {
    var listitems = "";
    if ($(node).children().length > 0) {
        $(node).children().each(function(i) {
            if ($(this).attr("nodeTypeAlias") == "Contentpage") {
                var day = $(this).parent().attr("nodeName");
                var title = $(this).attr("nodeName");
                var url = $(this).attr("urlName");
                listitems += "<li><a href='/agenda/" + year + "/" + month + "/" + day + "/" + url + ".aspx'><span>" + day + ": </span>" + title + "</a></li>";
            }
            if ($(this).children().length > 0) {
                listitems += parseNode($(this),year,month);
            }
        });
    }
    return listitems;
}

