var month_buttons;
jQuery(function(){
	var month=null;
	var now = new Date();
	month_buttons = $('div.month-navi img')
	
	if(location.href.match(/#([0-9]+)/) && 1<=RegExp.$1 && RegExp.$1<=12){
		month = RegExp.$1
	}
	else if(location.href.match(/y=([0-9]{4})/) && RegExp.$1!=get_fisical_year(now)){
  	month = 4;
	}
	else{
		month = now.getMonth() + 1;
	}
	
	month_buttons.filter('[src$=f1.gif]')
	.bind('mouseover', function(){
		$(this).attr('src', $(this).attr('src').replace('_f1', '_f2'));
	})
	.bind('click', function(){
		show($(this).parent('a').attr('href').replace('#', ''));
	})
	month_buttons.filter('[src$=f3.gif]')
								.css('cursor', 'default')
								.parent('a').unbind('click').bind('click', function(){return false;});

	show(month);
})

function show(show_month)
{
	var target = $('#main-contents-child');
  var list = $('#month_'+show_month);
	
	target.attr('class', "main-contents-child month"+show_month);
	month_buttons.each(function(){
		$(this).bind('mouseout', function(){
			$(this).attr('src', $(this).attr('src').replace('_f2', '_f1'));
		})
		$(this).attr('src', $(this).attr('src').replace('_f2', '_f1'));
	})
	var month_button = month_buttons.filter('[alt='+show_month+'月]');
	month_button.attr('src', function(){return $(this).attr('src').replace('_f1', '_f2')});
	month_button.unbind('mouseout');
	
	target.html(list.html());
	return false;
}

/**
 * 指定した日時の年度を取得する 
 * @param {Date} date
 */
function get_fisical_year(date)
{
	var year = date.getFullYear();
	var month = date.getMonth();
	
	return (4<=month && month<=12) ? year : year-1;
}

