function Calendar(config) {
	this.id = 'calendar';
	this.currentYear = 2009;
	this.currentMonth = 6;
	this.currentDay = 23;
	this.yearSelection = true;
	
	this.monthLengths = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
	this.monthNames = ["Styczeń", "Luty", "Marzec", "Kwiecień", "Maj", "Czerwiec", "Lipiec", "¦ierpień", "Wrzesień", "Pa¼dziernik", "Listopad", "Grudzień"];
	this.tmpYear = 0;
	this.tmpMonth = 0;
	
	if (config) {
		if (config.id != undefined) 			this.id = config.id;
		if (config.currentYear != undefined) 	this.currentYear = config.currentYear;
		if (config.currentMonth != undefined)	this.currentMonth = config.currentMonth;
		if (config.currentDay != undefined)		this.currentDay = config.currentDay;
		if (config.yearSelection == false) 		this.yearSelection = config.yearSelection;
	}
	
	this.initCalendar = function() {
		this.currentMonth--;
		
		jQuery('#'+this.id).html(this.currentDay + ' ' + this.monthNames[this.currentMonth] + ' ' + this.currentYear);
		//jQuery('#'+this.id).after('<input type="hidden" class="input200_p" name="'+this.id+'" value="'+this.currentYear+'-'+this.currentMonth+'-'+this.currentDay+'" />')
		if (this.yearSelection) var prepend = '<div class="yearSelect">'+
			                '<div class="next" onclick="ntr_create_cal(\''+this.id+'\',\'nextYear\')"><img src="http://nettur.pl/gfx/blank.gif" width="25" height="13"></div>'+
							'<div class="prev" onclick="ntr_create_cal(\''+this.id+'\',\'prevYear\')"><img src="http://nettur.pl/gfx/blank.gif" width="25" height="13"></div>'+
			                '<div class="name"></div>'+
			                '<div class="clr"><!-- x --></div>'+
			              '</div>';
		else var prepend = '';
		
		prepend += '<div class="monthSelect">'+
			                '<div class="next" onclick="ntr_create_cal(\''+this.id+'\',\'next\')"><img src="http://nettur.pl/gfx/blank.gif" width="25" height="13"></div>'+
							'<div class="prev" onclick="ntr_create_cal(\''+this.id+'\',\'prev\');"><img src="http://nettur.pl/gfx/blank.gif" width="25" height="13"></div>'+
			                '<div class="name"></div>'+
			                '<div class="clr"><!-- x --></div>'+
			              '</div>'+
			              '<div class="weekHead">'+
			                '<div class="n">pn</div><div class="n">wt</div><div class="n">¶r</div><div class="n">cz</div><div class="n">pt</div><div class="n">so</div><div class="n">nd</div><div class="clr"><!-- x --></div>'+
			              '</div>'+
			              '<div id="' + this.id + '_cal">&nbsp;</div>';
		
		jQuery('#'+this.id+'_c').html(prepend);
		this.generateCalendar();
	}
	
	this.generateCalendar = function(direction) {
		
		if (this.tmpYear > 0) {
			var year = this.tmpYear;
			var month = this.tmpMonth;
		} else {
			var year = this.currentYear;
			this.tmpYear = this.currentYear;
			var month = this.currentMonth;
			this.tmpMonth = this.currentMonth;
		}
		
		// kierunek next/prev   
		if (direction == 'next') {
			if (month == 11) {
				month = 0;
				year = parseInt(year) + 1;
				this.tmpYear = year;
				this.tmpMonth = 0;
			}
			else {
				month++;
				this.tmpMonth = month;
			}
		} else if (direction == 'prev') {
			if (month == 0) {
				month = 11;
				year = parseInt(year) - 1;
				this.tmpYear = year;
				this.tmpMonth = 11;
			}
			else {
				month--;
				this.tmpMonth = month;
			}
		} else if (direction == 'nextYear') {
			year = this.tmpYear = parseInt(year) + 1;
			this.tmpMonth = month;
		} else if (direction == 'prevYear') {
			year = this.tmpYear = parseInt(year) - 1;
			this.tmpMonth = month;
		}
		
		// rok przestepny
		if (year/4 == parseInt(year/4)) this.monthLengths[2] = 29;
		else this.monthLengths[2] = 28;
		
		if (this.yearSelection) {
			jQuery('#' + this.id + '_c .monthSelect').find('.name').html(this.monthNames[month]);
			jQuery('#' + this.id + '_c .yearSelect').find('.name').html(year);
		}
		else {
			jQuery('#' + this.id + '_c .monthSelect').find('.name').html(this.monthNames[month] + ' ' + year);
		}
		// stworzenie wyznacznika daty
		newDate = new Date(year, month, 1);
		
		// przygotowanie do generowania miesiaca 
		var counterStart = newDate.getDay();
		if (counterStart == 0) counterStart = 7;
		var startFill = false;
		var message = '';
		var counter = 1;
		
		// generowanie miesiaca
		for (i = 1; i<=6; i++) {
			message += '<div class="week">\n';
			for (j = 1; j <= 7; j++) {
			  if (j == parseInt(counterStart)) startFill = true; 
			  if (startFill && counter <= this.monthLengths[month]) {
			    if (j<6) className = 'n';
			    else className = 'f'; 
			    
				if (counter == this.currentDay && year == this.currentYear && month == this.currentMonth) { 
			      className += ' selected'; 
			    }
				// onclick="ntr_set_date(\''+id+'\','+counter+', '+(month+1)+','+year+');"	
				//'+this.id+'.set_date(this, '+ year +', '+ month +');
				//
					  
			    message +='<div onclick="ntr_set_date('+counter+', '+year+', '+month+', \''+this.id+'\', this);" class="'+className+'">'+counter+'</div>\n';
			    counter ++;
			  } else {
			    message += '<div class="e">&nbsp;</div>';
			  }
			}
			message += '<div class="clr"><!-- x --></div>\n';
			message += '</div>\n';
			if (startFill && counter > this.monthLengths[month]) break;
		}
		
		jQuery('#'+this.id+'_cal').html(message);
	}
	
	this.initCalendar();
}
