$(document).ready(function(){
	$("#news_left ul li a").click(load_news);
	$("#news_pagination a").click(load_news_left);
	$("#prev_date").click(load_prev_date);
	$("#next_date").click(load_next_date);
});

var month_array = new Array(
	'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'
);

function load_prev_date()
{
	cur_month--;
	if (cur_month == 0)
	{
		cur_month = 12;
		cur_year--;
	}
	$('#news_month').html(month_array[cur_month - 1] + ' ' + cur_year);
	load_news_left();
}

function load_next_date()
{
	var test = new Date();
	if (cur_year == test.getFullYear() && cur_month == test.getMonth() + 1)
	{
		
	} else
	{
		cur_month++;
		if (cur_month == 13)
		{
			cur_month = 1;
			cur_year++;
		}
		$('#news_month').html(month_array[cur_month - 1] + ' ' + cur_year);
		load_news_left();		
	}
}

function load_news_left()
{
	var page_offset = $(this).attr('title');
	if (!page_offset)
		page_offset = '0';
	if (page_offset == 0)
		page_offset = '0';
	$('#news_left_spinner').show();
	$.post("/press/load_news_left_ajax/" + page_offset,
		{ year: cur_year, month: cur_month },
	  function(data){
	  	$('#news_left_spinner').hide();
	    $('#news_left').html(data);
	    $("#news_pagination a").click(load_news_left);
	    $("#news_left ul li a").click(load_news);
	  }
	);
}

function load_news()
{
	var news_id = $(this).parent().attr('value');
	$("#news_left ul li.news_selected").removeClass();
  	$(this).parent().addClass('news_selected');
  	$('#news_center').html('<b>Loading...</b>');
	$.post("/press/load_news_ajax",
	  { id: news_id },
	  function(data){
	    $('#news_center').html(data);
	  }
	);
  	return false;
}
