var _ni_calendar = new function ()
{
	this.year;
	this.month;
	this.months = ['','Januar','Februar','März','April','Mai','Juni','Juli','August','September','Oktober','November','Dezember'];
	this.days   = ['','Mo','Di','Mi','Do','Fr','Sa','So'];

	this.next = function()
	{
		this.month++;
		if(this.month > 12  ) {
			this.year++;
			this.month = 1;
		}
		this.render();
	}

	this.prev = function()
	{
		this.month--;
		if(this.month <= 0 ){
			this.year--;
			this.month = 12;
		}
		this.render();
	}

	this.render = function()
	{
		var last = this.countDays(this.year, this.month - 1);
		var view = '';
		var m = this.month < 10 ? '0'+this.month : this.month;
		var w = new Date(this.year, this.month - 1, 1).getDay();
		w = (w == 0) ? 7 : w;

		for (i = 1; i <= last; i++ ) {

			var c = '';
			switch (w) {
				case 5:
				case 6:
					c = ' fri-sat';
					break;
				case 7:
					c = ' sunday';
			}
			view += '<a class="day'+c+'" href="http://www.meinsol.de/termine/?day='+this.year+'-'+m+'-'+(i < 10 ? '0'+i : i)+'"><div class="head">'+this.days[w]+'</div><div class="body">'+i+'</div></a>';
			++w;
			w = (w > 7) ? 1 : w;
		}
		view += '<div style="clear: both;"></div>';
		document.getElementById('ni_calendar_days').innerHTML = view;
		document.getElementById('ni_calendar_month').innerHTML = this.months[this.month] + ' ' + this.year;
	}
 
	this.init = function ()
	{
		document.getElementById('ni_calendar_next').onclick = function(){_ni_calendar.next()};
		document.getElementById('ni_calendar_prev').onclick = function(){_ni_calendar.prev()};
		var oDate  = new Date();
		this.year  = oDate.getFullYear();
		this.month = oDate.getMonth() + 1;
		this.render();
	}

	this.countDays = function (iYear, iMonth)
	{
		return 32 - new Date(iYear, iMonth, 32).getDate();
	}
}
_ni_calendar.init();
