var CalendarManager = Class({
    calendar_change : function(type, args, obj, inst) {
        url = inst.url_root + args[0][0][0] + '/' + inst.month_map[args[0][0][1]] + '/';
        if (args[0][0][2] > 9) {
            url += args[0][0][2];
        }
        else {
            url += inst.pad_map[args[0][0][2]];
        }
        //console.log(url);
        window.location = url;
    },
    render : function() {
        calendar = new YAHOO.widget.Calendar(this.container);
        for (i=0; i<this.highlight_dates.length; i++) {   
            calendar.addRenderer(this.highlight_dates[i], calendar.renderCellStyleHighlight1);
        }
        
        //calendar.select(this.start_date);  // MM/DD/YYYY
        calendar.cfg.setProperty("pagedate", this.page_date);  // MM/YYYY
        calendar.render();
        var instance = this;
        calendar.selectEvent.subscribe(function (type, args, obj) {instance.calendar_change(type, args, obj, instance);}, calendar, true);
    },
    initialize : function(url_root, container, page_date, highlight_dates) {
        this.url_root = url_root;
        this.container = container;
        this.page_date = page_date;
        this.highlight_dates = highlight_dates;
        this.month_map = {1:'jan',2:'feb',3:'mar',4:'apr',5:'may',6:'jun',7:'jul',8:'aug',9:'sep',10:'oct',11:'nov',12:'dec'};
        this.pad_map = {1:'01',2:'02',3:'03',4:'04',5:'05',6:'06',7:'07',8:'08',9:'09'};
        
        var instance = this;
        window.addEvent("domready", function() {
            instance.render();
        });
    } 
});