$(function() {

    var model = $("#modelString").html();

    $(".month").live('click',function(event) {
	event.preventDefault();

	var target = $(this).children('a').attr('href');

	var targetString = model+'/viewReport/'+target;

	$("#reports").fadeOut('fast');

	$.get(targetString, function(data) {
	    $("#reports").html(data);
	    $("#reports").fadeIn('fast');
	});
	
    });


    $(".year").click(function() {
	var thisYear = $(this).attr('id');

	if(thisYear != 0) {

	    var lastYear = parseInt(thisYear) - 1;
	    var yearString = lastYear+'-'+thisYear;
	    $(".whichYear").html(yearString);

	    $(".months").html(getMonthsFY(thisYear));


	}

	$.get(model+'/viewReport/'+thisYear, function(data) {
	    $("#reports").html(data);
	});
	
    });



    function getMonthsFY(year) {
	var months = new Object();

	lastYear = parseInt(year) - 1;

	months['July'] = lastYear+'/07';
	months['August'] = lastYear+'/08';
	months['September'] = lastYear+'/09';
	months['October'] = lastYear+'/10';
	months['November'] = lastYear+'/11';
	months['December'] = lastYear+'/12';
	months['January'] = year+'/01';
	months['February'] = year+'/02';
	months['March'] = year+'/03';
	months['April'] = year+'/04';
	months['May'] = year+'/05';
	months['June'] = year+'/06';

	var monthList = '';

	for(var i in months) {
	    //alert(i +' is'+months[i] );
	    monthList += '<li class="month"><a href="'+months[i]+'">'+i+'</a>';
	}
	return monthList;
    }


/*$(".month").click(function() {
	var thisMonth = $(this).html();
	var thisYear = $(this).parents('.monthList').attr('id');
	
	$.get('/jobs/viewReport/'+thisYear+'/'+thisMonth, function(data) {
	    $("#reports").html(data);
	});

    });*/


    

});



