function initCalendar (jsonUrl, targetId) {
	
	/**
 	* Month names
 	* @var array
 	*/
	var months = [
		'Januari',	'Februari',		'Maart',
		'April',	'Mei',			'Juni',
		'Juli',		'Augustus',		'September',
		'Oktober',	'November',		'December',
	];
	
	var today = new Date();
	
	var dstring = function(dt) {
		return 'd'+dt.getFullYear()+'.'+dt.getMonth()+'.'+dt.getDate();
	}

	var getItem = function (date) {
		var str = dstring(date);
		return (items[str]) ? items[str] : false;
	}
	
	var drawCalendar = function (year, month) {
	
		if (month < 1) {
			year = (year*1) - (Math.ceil(month/12) + 1);
			month = month%12 + 12;
		} else if (month > 12) {
			year = (year*1) + (Math.floor(month/12));
			month = month%12;
		}
		
		//date object to iterate trough the month
		var iDate = new Date();
		iDate.setFullYear(year, month-1, 1);
	
		//set the date iterator to the last monday preceding the 2nd day of the month
		var dayOfWeek = iDate.getDay();
		var dayOffset = (dayOfWeek == 0) ? -5 : 2 - dayOfWeek;
		iDate.setDate(dayOffset);
		
		var calendar = $('<div id="'+targetId+'" class="agenda"><h3><a class="prev"><span>«</span></a>'
					+ '<span class="date">'+months[month-1%12]+' '+iDate.getFullYear()+'</span>'
					+ '<a class="next"><span>»</span></a>'
					+ '</h3>'
					+ '<ul class="head"><li>M</li><li>D</li><li>W</li><li>D</li><li>V</li><li>Z</li><li>Z</li></ul>'
					+ '</div>');
		var week;
		for(var i=6; i>0; i--) {
			week = $('<ul />');
			calendar.append(week);
			for(j=0; j<7; j++) {
				var curDay = iDate.getDate();
				var curMonth = iDate.getMonth();
				
				//Break out of the week loop when we enter the first day of the next month
				if (curMonth == month) {
					i=0;
					if(j==0) {  break; }
				}
				
				var li = $('<li />');
				if(curMonth != month-1) {
					li.addClass('other');
				}
				li.text(curDay);
				
				if(agItem = getItem(iDate)) {
					li.addClass(agItem.cname);
					var itemDiv = $('<div />');
					var head = $('<h4 />');
					head.text(agItem.title);
					var desc = $('<span class="desc" />');
					desc.text(agItem.desc)
					var a = $('<a>[meer]</a>');
					a.attr('href',agItem.url);
					
					li.append(itemDiv.append(head).append(desc).append(a).hide());
					itemDiv.hide();
					li.click(function(){
						window.location = $('a',this).attr('href'); }
					);
					li.css('cursor','pointer');
					li.hover(
						function(){
							$(this).css('z-index',120);
							$('ul li div',calendar).hide();
							$('div',$(this)).show(100);
						},
						function(){
							$(this).css('z-index',10);
							$('div',$(this)).hide();}
					);
					/*
					li.click(function(){
							$('div',$(this)).toggle();
						}
					);
					*/
				}
				week.append(li);
				
				iDate.setDate(curDay + 1);
			}
		}
		$('#'+targetId).replaceWith(calendar);
		$('a.prev',$('#'+targetId)).click(function(){drawCalendar(year,month-1)});
		$('a.next',$('#'+targetId)).click(function(){drawCalendar(year,month+1)});
	}
	
	
	
	
	// Fill the items object using json data from the specified URL, upon succes,
	// teh drawCalendar function is used to draw this months calendar
	var items = {};
	$.getJSON(jsonUrl,
		function(data) {
			var i = data.length;
			while(i--) {
				var d = data[i];
			
				//parse the date string into a date object 
				var dp = d.datumtxt.split('/');
				var date = new Date(dp[2],dp[1]-1,dp[0],0,0,0);
				var datestr = dstring(date);
			
				//transforms the target group into an html class name
				var tp = d.types.doelgroep.split("\t");
				var cname = 'default';
				if(tp.length == 1) {
					switch(tp[0].toLowerCase()) {
						case 'leerlingen'		:
						case 'scholen'			:
						case 'stagebieders'		:
						case 'stagemakelaars'	:
								cname = tp[0].toLowerCase();
							break;
					}			
				}
				items[datestr] = {
					date 	: date,
					url		: d.fullpath,
					title	: d.title,
					desc	: d.itemdescription,
					cname	: cname
				};
				
				//extra dates 
				if(d.xdate) {
					dates = d.xdate.split(',');
					for(j=0; j<dates.length; ++j) {
						dp = dates[j].split('/');
						if(dp.length == 3) {
							xd = new Date(dp[2],dp[1]-1,dp[0],0,0,0);
							datestr = dstring(xd);
						
							items[datestr] = {
								date 	: xd,
								url		: d.fullpath,
								title	: d.title,
								desc	: d.itemdescription,
								cname	: cname
							};
						}
					}
				
				}
				
				//enddate (this is deprecated...)
				if(d.enddate) {
					dp = d.enddate.split('/');
					var enddate = new Date(dp[2],dp[1]-1,dp[0],0,0,0);
					while(date < enddate) {
						
						date.setDate(date.getDate()+1);	
						datestr = dstring(date);
						items[datestr] = {
							date 	: date,
							url		: d.fullpath,
							title	: d.title,
							desc	: d.itemdescription,
							cname	: cname
						};
					}					
				}
			}
			drawCalendar(today.getFullYear(), today.getMonth()+1);
		}
	);
}
