function initeCalendar()
{
	new Ajax.Request('/ajax/events-calendar-req.php', {
		method: 'post',
		onSuccess: function(transport) {
			$('calendar-container').innerHTML = transport.responseText;
		}
	});
}

function fe_showLoading()
{
	$('calendar-container').innerHTML = '<img src="http://www.jurgita.com/css/ajax-loader-darkblue.gif" alt="" title="" style="margin-top:40px;" />';
}

function fe_calNavigate(direction)
{
	var month = parseInt($('c_month').value);
	var year = parseInt($('c_year').value);
	
	if (month == 1 && direction == 'm')
	{
		year = year - 1;
		month = 12;
	}
	else if (month == 12 && direction == 'p')
	{
		year = year + 1;
		month = 1;
	}
	else
	{
		if (direction == 'p')
		{
			month = month + 1;
		}
		else
		{
			month = month - 1;
		}
	}
	
	$('c_month').value = month;
	$('c_year').value = year;
	
	new Ajax.Request('/ajax/events-calendar-req.php?date='+year+'-'+month, {
		method: 'post',
		onLoading: function () {
			fb_showLoading();
		},
		onSuccess: function(transport) {
			$('calendar-container').innerHTML = transport.responseText;
		}
		
	});
}

function fe_calLink(obj)
{
	var date = obj.id;
	var url_parts = new Array();
	url_parts = window.location.toString().split('/');
	
	var file = url_parts[3];
	if (file.indexOf('.') != -1)	//taskas yra /events.php
	{
		var file_parts = new Array();
		file_parts = file.split('.');
		url_parts[3] = file_parts[0];
	}
	
	window.location = url_parts[0]+'//'+url_parts[2]+'/'+url_parts[3]+'/'+date;
}

Event.observe(window, 'load', initeCalendar);
