document.observe("dom:loaded", function() {
    $$('.calendar').each(function(el) {
        var selectCalendarDay = function(date) {
            var day = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
            var m = date.getMonth() + 1;
            var month = m < 10 ? '0' + m : m;
            var url = SCHEDULE_DAY_URL + '/' + date.getFullYear() + '-' + month + '-' + day;
            document.location.href = url;
        };
        schedulecal = new scal(el.id, selectCalendarDay, {
            weekdaystart: 1,
            /*planner: PLANNER,
            oncalchange: function(d) {
                var url = EVENTS_URL + '/';
                new Ajax.Request(url, {
                    method: 'get',
                    onSuccess: function(transport) {
                        alert(transport.responseText.toJSON());
                    }
                });

            },*/
            dayheadlength: CAL_DAY_LENGTH
        });
    });
    
    Event.observe($('show-calendar'), 'click', function(event) {
        schedulecal.toggleCalendar();
    });
});