var months = null;
var currentMonth = 0;

function initMonths() {
	var now = new Date();
    months = $('homeCalendarContent').getChildren();	
	
    for (var i = 0; i < months.length; i++) {
        var item = $(months[i]);
        
        item.monthID = i;
        item.setStyle("position", "absolute");
        item.setStyle("top", "0");
        
        if (i == now.getMonth()) { 
			currentMonth = i;
            item.setStyle("left", "0px");
        } else {
            item.setStyle("left", "230px");
        }
    }
    
    $("homeCalendarScrollLeft").addEvent("click", monthClickBack);
    $("homeCalendarScrollRight").addEvent("click", monthClickForward);
    
    if (months.length == 1) {
        $("homeCalendarScrollLeft").setStyle("display", "none");
        $("homeCalendarScrollRight").setStyle("display", "none");
    }
	
	//var now = new Date();
	//for(var increment = 1; increment <= now.getMonth(); increment++){
		//monthClickForward();
	//}
}

function monthClickBack() {
    var currentMonthID  = currentMonth;
    var previousMonthID = currentMonthID;
    
    if (currentMonthID == 0) {
        previousMonthID = months.length - 1;
    } else {
        previousMonthID = currentMonthID - 1;
    }
    
    currentSlideFx  = new Fx.Styles("month-" + currentMonthID, { duration: 400 }); 
    previousSlideFx = new Fx.Styles("month-" + previousMonthID, { duration: 400 });
    
    currentSlideFx.start({ 'left': [0, 230] });
    previousSlideFx.start({ 'left': [-230, 0] });
    
    currentMonth = previousMonthID;
}

function monthClickForward() {
    var currentMonthID = currentMonth
    var nextMonthID    = currentMonthID;
    
    if (currentMonthID == (months.length - 1)) {
        nextMonthID = 0;
    } else {
        nextMonthID = currentMonthID + 1;
    }
    
    currentSlideFx = new Fx.Styles("month-" + currentMonthID, { duration: 400 }); 
    nextSlideFx    = new Fx.Styles("month-" + nextMonthID, { duration: 400 });
    
    currentSlideFx.start({ 'left': [0, -230] });
    nextSlideFx.start({ 'left': [230, 0] });
    
    currentMonth = nextMonthID;
}
