$(function() {
	$(".calendarcontainer").load("/kalenteri", {}, function() {
		refreshCalNav();
	});	
	$(".fpnews .fpheader").click(function() {
		document.location.href="/uutiset";
	});
});

function refreshCalNav() {
	$(".calprev").unbind("click");
	$(".calnext").unbind("click");
	$(".hasevent").unbind("click");
	
	$(".calprev").click(function() {
		var ts = $(".monthcalendar").attr("id");
		$(".calendarcontainer").load("/kalenteri", {ts: ts, operation: "prev"}, function() {
			refreshCalNav();
		});
	});
	$(".calnext").click(function() {
		var ts = $(".monthcalendar").attr("id");
		$(".calendarcontainer").load("/kalenteri", {ts: ts, operation: "next"}, function() {
			refreshCalNav();
		});
	});
	$(".hasevent").mouseover(function() {
		var ts = $(this).attr("id");
		$(".eventinfo").html("");
		$(".eventinfo").show();	
		$.post("/kalenteri/dayevents", {ts: ts}, function(data) {
		    $(".eventinfo").html(data);
		});
	});
	$(".monthcalendar").mouseout(function() {
		$(".eventinfo").hide();
	});
	$(".monthitem").mouseout(function() {
		$(".eventinfo").hide();
	});
	$(".hasevent").click(function() {
		var ts = $(this).attr("id");
		var url = "/konsertit/?kid=" + ts;
		document.location.href = url;
	});
}