var nrOfEducations = 0;
var maxEducations = 8;
var nrOfExpos = 0;
var maxExpos = 15;

$('div#opleidingen').ready(function(){
	nrOfEducations = $('div#opleidingen > div').length;
	
	$('input#opleiding_' + (nrOfEducations - 1)).change(function(){
		createNewEducation();
	});
});

$('div#exposities').ready(function(){
	nrOfExpos = $('div#exposities > div').length;
	
	$('input#expositie_' + (nrOfExpos - 1)).change(function(){
		createNewExposition();
	});
});

function createNewEducation(){
	var educationDiv = $('div#opleidingen > div:first').clone(); // clone first div
	educationDiv.css('display', 'none'); // hide the cloned div
	
	var educationDivHtml = educationDiv.html();
	educationDivHtml = educationDivHtml.replace(/0/g, nrOfEducations); // make sure the newly created item has a unique number
	educationDiv.html(educationDivHtml);
	$('div#opleidingen').append(educationDiv);
	
	$('div#opleidingen > div:last > input').val(''); // delete values from added div
	$('div#opleidingen > div:last').slideDown('normal');
	
	$('input#opleiding_' + (nrOfEducations - 1)).unbind();
	nrOfEducations = $('div#opleidingen > div').length;
	if(nrOfEducations < maxEducations){ // make sure the user cant add more than maxEducations 
		$('input#opleiding_' + (nrOfEducations - 1)).change(function(){
			createNewEducation();
		});
	}
}

function createNewExposition(){
	var expositionDiv = $('div#exposities > div:first').clone(); // clone first div
	expositionDiv.css('display', 'none'); // hide the cloned div
	
	var expositionDivHtml = expositionDiv.html();
	expositionDivHtml = expositionDivHtml.replace(/0/g, nrOfExpos); // make sure the newly created item has a unique number
	expositionDiv.html(expositionDivHtml);
	$('div#exposities').append(expositionDiv);
	
	$('div#exposities > div:last > input').val(''); // delete values from added div
	$('div#exposities > div:last').slideDown('normal');
	
	$('input#expositie_' + (nrOfExpos - 1)).unbind();
	nrOfExpos = $('div#exposities > div').length;
	if(nrOfExpos < maxExpos){ // make sure the user cant add more than maxExpos 
		$('input#expositie_' + (nrOfExpos - 1)).change(function(){
			createNewExposition();
		});
	}
}