jQuery.fn.smallCalendar = function(options) {
	this.each(function() {
		var widget_url = '/widget.php';

		var t = this;

		function replaceCalendar(url) {
			// Set Target
			target = url;

			// Fade out
			$(t).fadeTo('slow', 0.5, function() {
				// Get new calendar
				var target = widget_url + '?widget=smallcalendar&target='+ url;

				$.ajax({
					url: target,
					success: function(e) {
						$(t).html(e).fadeTo('slow', 1);

						$(t).find('.month-link').bind('click', function() {
							return replaceCalendar($(this).attr('href'));
						});
						
						$('#smallcalendar_down').click(function() {
							$('#smallcalendar_months').toggle();
							return false;
						});
					}
				});
			});
			
			$('#smallcalendar_months').hide();

			return false;
		}

		$(this).find('.month-link').bind('click', function() {
			return replaceCalendar($(this).attr('href'));
		});
		
		$('#smallcalendar_down').click(function() {
			$('#smallcalendar_months').toggle();
			return false;
		});
	});


};
