// JavaScript Document

/**
* hoverIntent r6 // 2011.02.26 // jQuery 1.5.1+
* <http://cherne.net/brian/resources/jquery.hoverIntent.html>
* 
* @param  f  onMouseOver function || An object with configuration options
* @param  g  onMouseOut function  || Nothing (use configuration options object)
* @author    Brian Cherne brian(at)cherne(dot)net
*/
(function($){$.fn.hoverIntent=function(f,g){var cfg={sensitivity:7,interval:100,timeout:0};cfg=$.extend(cfg,g?{over:f,out:g}:f);var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if((Math.abs(pX-cX)+Math.abs(pY-cY))<cfg.sensitivity){$(ob).unbind("mousemove",track);ob.hoverIntent_s=1;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=0;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type=="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).bind("mousemove",track);if(ob.hoverIntent_s!=1){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).unbind("mousemove",track);if(ob.hoverIntent_s==1){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.bind('mouseenter',handleHover).bind('mouseleave',handleHover)}})(jQuery);


// jQuery default loaders
$(document).ready( function() {  
	var config = {sensitivity: 2, interval: 100, over: megaHoverOver, timeout: 100, out: megaHoverOut};

	$("div.topNav .wrapper ul li .sub").css({'opacity':'0'});
	$("div.topNav .wrapper li").hoverIntent(config);
	
	
	function megaHoverOver(){
		$(this).find(".sub").stop().fadeTo('fast', 1).show();
		(function($) { //Calculate width of all ul's
			jQuery.fn.calcSubWidth = function() {
				rowWidth = 0;
				$(this).find("ul").each(function() {//Calculate row				
					rowWidth += $(this).width(); 
				});	
			};
		})(jQuery); 
		
		if ( $(this).find(".row").length > 0 ) { //If row exists...
			var biggestRow = 0;	
			//Calculate each row
			$(this).find(".row").each(function() {							   
				$(this).calcSubWidth();
				if(rowWidth > biggestRow) biggestRow = rowWidth;// Find biggest row
			});
			
			$(this).find(".sub").css({'width' :biggestRow});
			
		} else { //If row does not exist...
			$(this).calcSubWidth();
			rowWidth = rowWidth+75;
			$(this).find(".sub").css({'width' : rowWidth});
		}
	}
	
	function megaHoverOut(){ 
	  $(this).find(".sub").stop().fadeTo('fast', 0, function() {
		  $(this).hide(); 
	  });
	}
	
	
	// Functie om formulieren van hun standaard waarde te ontdoen als er op geklikt wordt; 
	// en weer terug te zetten als het veld leeg achtergelaten wordt.
	$('input[type=text]').click(function(){
		if($(this).val() == this.defaultValue){
			$(this).val('');	
		}
	});
	
	$('input[type=text]').blur(function(){
		if ($(this).val() == "") {
			$(this).val(this.defaultValue);
		} 
	});
	
	
	$('.leftBlockIndex').hover(function(){
		$('#linkingArrowHome').show();
		if($(this).hasClass('lbi_mbo')){
			$('#linkingArrowHome').css('top', '230px');
		}else if($(this).hasClass('lbi_volwassenen')){
			$('#linkingArrowHome').css('top', '426px');
		}else if($(this).hasClass('lbi_bedrijven')){
			$('#linkingArrowHome').css('top', '622px');
		}
	});
	
});


// JavaScript Document
function showFaq(id) {
	if (document.getElementById(id)) {
		document.getElementById(id).style.display = 'block';
	}
}
function hideFaq(id) {
	if (document.getElementById(id)) {
		document.getElementById(id).style.display = 'none';
	}
}
function toggleFaq(id) {
	if(document.getElementById(id)) {
		if ( (document.getElementById(id).style.display == 'block') || (document.getElementById(id).style.display == '') ) {
			document.getElementById(id).style.display = 'none';
		} else {
			document.getElementById(id).style.display = 'block';
		}
	}
}

function emthis(em3, em5, naam, em6, url, js, nooutput, title) {
	var em1 = 'mail';
	var em2 = 'to:';
	var em4 = '@';
	if (!em5) var em5 = 'rocflevoland.nl';
	if (!em6) var em6 = ''; else var em6 = '?subject=' + em6;
	if (!naam) var naam = em3+em4+em5;
	if (!js) var js = ''; else var js = ' onClick="'+js+'"';
	if (!title) var title = 'Stuur een e-mail';
	if (!url) {
		var url = em1 + em2 + em3 + em4 + em5 + em6;
		if (!nooutput) document.write('<a href="'+url+'" title="'+title+'"'+js+'>'+naam+'</a>'); else return url;
	} else {
		if (!nooutput) document.write('<span title="'+title+'">'+naam+'</span>'); else return naam;
	}
}


function showleeftijd (formulier) {
	document.getElementById('leeftijd').value = '';
	var vandaag = new Date();
	var thisform = document.forms[formulier];
	var huidig_dag = vandaag.getDate();
	var huidig_maand = vandaag.getMonth() + 1;
	var huidig_jaar = vandaag.getFullYear();
	var leeftijd_dag = thisform.geboortedatum_dag.value;
	var leeftijd_maand = thisform.geboortedatum_maand.value;
	var leeftijd_jaar = thisform.geboortedatum_jaar.value;
	while (leeftijd_dag.charAt(0) == "0") leeftijd_dag = leeftijd_dag.substring(1,leeftijd_dag.length);
	while (leeftijd_maand.charAt(0) == "0") leeftijd_maand = leeftijd_maand.substring(1,leeftijd_maand.length);
	if ( (leeftijd_dag > 0) && (leeftijd_maand > 0) && (leeftijd_jaar > 0) ) {
		var nieuweleeftijd = huidig_jaar - leeftijd_jaar;
		if ( ( (leeftijd_dag > huidig_dag) && (leeftijd_maand == huidig_maand) ) || (leeftijd_maand > huidig_maand) ) {
			var nieuweleeftijd = nieuweleeftijd - 1;
		}
		document.getElementById('leeftijd').value = nieuweleeftijd + ' jaar';
	}
}


$(function(){
	$('.homeBox').bind('mouseleave', function(){ $('.centerBlockIndex').hide(); } );
});
