Kalendarz=function(Y,m,d){
	this.data;
	this.now;
	this.nazwy={
		month:['stycze&#324;','luty','marzec','kwiecie&#324;','maj','czerwiec','lipiec','sierpie&#324;','wrzesie&#324;','pa&#378;dziernik','listopad','grudzie&#324;'],
		days:['nd','pn','wt','&#347;r','cz','pt','sb']
	}
	this.prepareDateObjeckt=function(Y,m,d){
		this.data=new Date(Y,m,d);
	}
	this.prepareDateObjeckt(Y,m,d);
	
	this.setNow=function(Y,m,d){
		this.now=new Date(Y,m,d);
	}	
	this.isRokPrzestepny=function(){
	  return ((this.data.getFullYear() % 4 == 0) && ((this.data.getFullYear() % 100 != 0) || (this.data.getFullYear() % 400 == 0)));
	}
	this.ileDniMaMiesiac=function(){
		if(this.data.getMonth()==1)
			return this.isRokPrzestepny()?29:28;
		return this.xor((this.data.getMonth()>6),(this.data.getMonth()%2==0))?31:30;
	}	
	this.xor=function(a, b){
		return (( a && !b ) || ( !a && b ));
	}
	this.getHtml=function(){
		var iter_date=new Date();
		iter_date.setTime(this.data.getTime());
		$("#gKalUl").empty();
		for(var i=0;i<this.ileDniMaMiesiac();i++){
			iter_date.setDate(i+1);
			var full_data=iter_date.getFullYear()+'-'+(iter_date.getMonth()+1)+'-'+(iter_date.getDate());
			var html="<li"+((this.now.toLocaleDateString()==iter_date.toLocaleDateString())?' class="aktywny"':'')+'>';
			html+='<a href="/0,'+full_data+',0,artykuly,cgk.html"'+((iter_date.getDay()==0)?' class="swieto"':'')+'>';
			html+=this.nazwy.days[iter_date.getDay()]+'<br>'+(i+1);
			html+='</a></li>';
			$("#gKalUl").append(html);
		}
		$("#month_name").html(this.nazwy.month[this.data.getMonth()]+' '+this.data.getFullYear());
	}
	this.step=function(kierunek){
		if (this.data.getMonth() == 11 && kierunek>0) {
			this.data.setMonth(0);
			this.data.setFullYear(this.data.getFullYear()+1);
		}else if(this.data.getMonth() == 0 && kierunek<0){
			this.data.setMonth(11);
			this.data.setFullYear(this.data.getFullYear()-1);
		}else{
			this.data.setMonth(this.data.getMonth()+kierunek);
		}
		this.getHtml();
	}
}
