var ddSmallAjaxCalendar = new Class({
	
	initialize: function(calendarId, monthId, prevLinkId, nextLinkId) {
		this.calendarId = calendarId;
		this.monthId = monthId;
		this.prevLinkId = prevLinkId;
		this.nextLinkId = nextLinkId;
		this.used = false;
		this.setElements();
		this.setLinkEvents();
	},
	
	setElements: function() {
		this.calendar = false;
		this.month = false;
		this.prevLink = false;
		this.nextLink = false;				
		this.calendar = $(this.calendarId);
		this.month = $(this.monthId);
		this.prevLink = $(this.prevLinkId);
		this.nextLink = $(this.nextLinkId);		
	},
	
	setLinkEvents: function() {
		this.prevLink.addEvent('click', function() {
			this.prevMonth();
		}.bind(this));
	
		this.nextLink.addEvent('click', function() {
			this.nextMonth();
		}.bind(this));		
	},
	
	prevMonth: function() {
		this.prevLink.blur();
		var calElements = this.prevLink.get('rel').split(':');
		this.loadMonth(calElements[1]);
	},
	
	nextMonth: function() {
		this.nextLink.blur();
		var calElements = this.nextLink.get('rel').split(':');
		this.loadMonth(calElements[1]);			
	},
	
	loadMonth:function (getdate) {
		
		var myHTMLRequest = new Request.HTML({
			url:'/index.php',
			onRequest: function() {
				this.month.set('html', 'lade Monat...');
			}.bind(this),
			onSuccess: function(responseTree, responseElements, responseHTML, responseJavaScript) {
				//this.calendar.set('html', responseHTML);
				if (this.used) {
					$('content333').destroy();
				}
				else {
					$('calMonthCurrentTable').destroy();
				}
				this.calendar.adopt(responseTree);
				this.month.set('html', $('calMonthNewMonth').get('html'));
				$('calMonthNewMonth').destroy();
				this.prevLink.set('rel', 'cal:'+$('calMonthNewPrev').get('text'));
				$('calMonthNewPrev').destroy();
				this.nextLink.set('rel', 'cal:'+$('calMonthNewNext').get('text'));
				$('calMonthNewNext').destroy();				
			}.bind(this)
			}).get({
				'id': 104,
				'tx_cal_controller[getdate]': getdate
				});

	}
});

window.addEvent('domready', initSmallAjaxCalendar);
function initSmallAjaxCalendar() {
	ajaxCalendar = new ddSmallAjaxCalendar('calMonthCurrent', 'calMonthCurrentMonth', 'calMonthCurrentPrevLink', 'calMonthCurrentNextLink');
	
}
