var CURRENT_MONTH = '';
var CURRENT_YEAR = '';

window.addEvent('domready', function() {
    activateMonthSelector();
});


function activateMonthSelector() {
    var prev = $('prev_month');
    var next = $('next_month');

    if (prev == null || next == null) return false;
    prev.addEvent('click', function (e) {
        e.stop();
        loadMonth('prev');
    });
    next.addEvent('click', function (e) {
        e.stop();
        loadMonth('next');           
    });

}

function loadMonth(type) {
    var url = VIRTUAL_URL + 'agenda/month';
    url += '?year=' + CURRENT_YEAR;
    url += '&month='+ CURRENT_MONTH;
    url += '&type=' + type;

    var complete = function(data) {
        CURRENT_YEAR = data.year;
        CURRENT_MONTH = data.month;

        var month_html = '<a href="' + VIRTUAL_URL + 'agenda/maand/' + data.month + '-' + data.year + '">';
        month_html += data.month_name;
        month_html += '</a>';

        $('month_selector_name').set('html', month_html);
        $('month_container').set('html', data.html);
    }

    var req = new Request.JSON({
        url: url,
        onComplete: complete
    });

    req.send();
}