repos = 0;

function init_floater() {
	var floater = document.getElementById('vacature_floating_buttons');
	
	if (floater) {
		repos_floater();
		if (window.onscroll) {
			window.onscroll = repos_floater;
		}
	}
}

function repos_floater() {

	var kolom_links = document.getElementById('kolom_links');
	var floater = document.getElementById('vacature_floating_buttons');
	var center_content = document.getElementById('center_content');
	var clientHeight = document.documentElement.clientHeight;
	
	if (document.body.scrollTop > 0) {
		var scroll = document.body.scrollTop;
	} else {
		var scroll = document.documentElement.scrollTop;
	}

	var floater_hoogte = floater.offsetHeight;
	var kolom_hoogte = kolom_links.offsetHeight + 10;
	var kolom_einde = kolom_links.offsetTop + kolom_hoogte;
	var max_top = center_content.offsetHeight - floater_hoogte;
	
	if (scroll + clientHeight > kolom_einde + floater_hoogte) {
		var top = scroll + clientHeight - kolom_links.offsetTop - floater_hoogte - 10;
		
		if (top > max_top) {
			top = max_top;
		}
		
	} else {
		
		var top = kolom_hoogte;
		
	}

	floater.style.top = top + 'px';	
}

function vacature_button_click() {

	var as = this.getElementsByTagName('a');

	if (as.length > 0) {

		document.location = as[0].href;

	}

}

function init_vacature() {

	var buttons_div = document.getElementById('vacature_buttons');

	if (buttons_div) {
		var as = buttons_div.getElementsByTagName('a');

		for (var i = 0; i < as.length; i++) {

			as[i].parentNode.onclick = vacature_button_click;

		}
	}
	
	
	var bedrijfsinfo_titel = document.getElementById('vacature_bedrijfsinfo_titel');
	
	if (bedrijfsinfo_titel) {
		bedrijfsinfo_titel.onclick = function() {
			$("#vacature_bedrijfsinfo_tekst").slideToggle("slow");
			
			var className = this.className.replace(' ', '');
	
			if (className) {
				$(this).removeClass('selected');
				$(this).removeClass('first');
			} else {
				$(this).addClass('selected');
			}
	
		}
	}
	
	var ci = document.getElementById('ci');
	
	if (ci) {
		
		ci.onmouseover = function() {
			
			if (document.ci_timer) {
				clearTimeout(document.ci_timer);
			}
			
			var ci_croon = document.getElementById('ci_croon');
			
			if (ci_croon) {
				ci_croon.style.display = 'block';
			}
		}
		
		ci.onmouseout = function() {
			
			document.ci_timer = setTimeout(function () {
				var ci_croon = document.getElementById('ci_croon');	
				if (ci_croon) {
					ci_croon.style.display = 'none';
				}
			}, 1000);
		}
	}	
	
	/*
	var vacature_tekst_container = document.getElementById('vacature_tekst_container');

	var titels = vacature_tekst_container.getElementsByTagName('b');
	
	if (titels) {
		for (var i = 0; i < titels.length; i++) {
			titels[i].id = 'titel_' + i;
			titels[i].onclick = vacature_tekst_click;
			if (i == 0) {
				titels[i].className = 'first';
			}
		}
	}
	
	var paragrafen = vacature_tekst_container.getElementsByTagName('div');
	
	if (paragrafen) {
		for (var i = 0; i < paragrafen.length; i++) {
			paragrafen[i].id = 'paragraaf_' + i;
			paragrafen[i].style.display = 'none';
		}
	}*/
	
	$("#paragraaf_0").slideToggle("hide");

	init_floater();
	
}

function vacature_tekst_click() {

	// de tekst die bij deze titel hoort.
	var id = this.id.replace('titel', 'paragraaf');
	$("#" + id).slideToggle("slow");
	
	var className = this.className.replace(' ', '');
	
	if (className) {
		$(this).removeClass('selected');
		$(this).removeClass('first');
	} else {
		$(this).addClass('selected');
	}
	
}
