/* hoverIntent r5 // 2007.03.27 // jQuery 1.1.2+ */
(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 p=(e.type=="mouseover"?e.fromElement:e.toElement)||e.relatedTarget;while(p&&p!=this){try{p=p.parentNode;}catch(e){p=this;}}if(p==this){return false;}var ev=jQuery.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);}if(e.type=="mouseover"){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.mouseover(handleHover).mouseout(handleHover);};})(jQuery);

	$(function() {
		/* External Links Function */
		$('a[rel*=external],a[rel*=nofollow]').click( function() {
			window.open(this.href);
			return false;
		});
		
		$('.educationItem h3 a').click(function() {
			$('.educationItemExtra').slideUp('fast');
			$('.educationItemExtra').parent().find('.arrowRight').removeClass('arrowDown');
			$(this).parent().parent().parent().find('.arrowRight').toggleClass('arrowDown');
			$(this).parent().parent().parent().parent().find('.educationItemExtra').slideToggle('fast');
			return false;
		});
		
		//Hover carrousel
		$(".carouselButton").hover(function() {
			elmNumber = $(this).attr('id');
			elmNumber = elmNumber.replace("carousel-", "");
			$('.carouselButtons').children().removeClass('current');
			$(".carouselImage img").hide();
			var i = 1;
			$('.carouselImage').children().each(
				function(){
					if (i == elmNumber){
						$('div #carousel-'+i).addClass('current');
						$(this).show();
					}
					i++;
				}
			)	
		});
		
		//E-mail adressen schrijven als "naam at domeinnaam dot nl" en het word getoond als "naam@domeinnaam.nl"
		var at = / at /;
		var dot = / dot /g;
		$('a.mailme').each(function () {
			var addr = $(this).text().replace(at,"@").replace(dot,".");
			var title = jQuery(this).attr('title');
			$(this).after('<a href="mailto:'+addr+'" title="'+title+'" rel="nofollow">'+ addr +'</a>');
			$(this).remove();
		});
		
		
		
		//plus en min een persoon bij inschrijf formulier
		$('div#plus-button, div#min-button').click(function() {
			var curPersons = parseInt($('#aantal-personen').val());
			var curPrijsPerPersoon = ($('#prijs-per-person').val()).replace(",",".");
			
			var aantalPersonen = 1;
			if($(this).attr('id') == 'min-button'){
					if(curPersons > 1) {
						aantalPersonen = (curPersons-1);
						$('#aantal-personen').val(aantalPersonen);
					}
			}
			if($(this).attr('id') == 'plus-button') {
				aantalPersonen = (curPersons+1);
				$('#aantal-personen').val(aantalPersonen);
			}
			prices = (curPrijsPerPersoon*aantalPersonen).toFixed(2)+'';
			var stringPrice = prices.replace(".",",");
			$('#nieuw-prijs').text(stringPrice);
            //replace totaal prijs naar hele euro's RDG
			//$('#totaal-prijs').val(stringPrice.replace(",00",""));
		});
		

		$('#aantal-personen').blur(function() {
			var curPersons = parseInt($('#aantal-personen').val());
			if(curPersons < 1) {
				curPersons = 1;
				$('#aantal-personen').val(1);
			}
			var curPrijsPerPersoon = ($('#prijs-per-person').val()).replace(",",".");	
			prices = (curPrijsPerPersoon*curPersons).toFixed(2)+'';
			var stringPrice = prices.replace(".",",");
			$('#nieuw-prijs').text(stringPrice);
			$('#totaal-prijs').val(stringPrice);
		});
		
		//Loop carrousel
		if ($('#carousel').length > 0 ) {
			(function showCarrouselImage() { setTimeout(function() {
					var $active = $(".carouselButtons .current"); 			
					var $next = $active.next(); 				
					if ($active.is(".carouselButtons DIV.carouselButton:last-child") ) {
						$next = $(".carouselButtons DIV.carouselButton:first-child");
						$next.addClass('current');
					} else {
						$next.addClass('current');
					}
					$(".carouselImage img").hide();
					elmNumber = $next.attr('id')
					elmNumber = elmNumber.replace("carousel-", "");
					$('.carouselImage :nth-child('+elmNumber+')').show()
					$active.removeClass('current');
					showCarrouselImage();
				}, 4000);
			})();
		}
        //print via jqprint.js
		function print() {
			$custj('.contentPage').jqprint({  operaSupport: true });
		}

        
        $('#contact_submit_form').click(function () {
            return_value = true;
            /*
            username_form
            password_form
            email_form
            
            
            
            var company = $('#company');
            var message = 'bedrijsnaam niet ingevuld';
            if (company.val().length == 0||company.val() == message) {
                company.addClass('errorForm');
                company.val(message);
                return_value = false;
            } else {
                company.removeClass('errorForm');
            }
            */
            var contactName = $('#naam');
            var message = 'naam niet ingevuld';
            if (contactName.val().length == 0||contactName.val() == message) {
                contactName.addClass('errorForm');
                //contactName.val(message);
                return_value = false;
            } else {
                contactName.removeClass('errorForm');
            }
            
            var contact_vericode = $('#achternaam');
            var message = 'code niet ingevuld';
            if (contact_vericode.val().length == 0||contact_vericode.val() == message) {
                contact_vericode.addClass('errorForm');
                //contact_vericode.val(message);
                return_value = false;
            } else {
                contact_vericode.removeClass('errorForm');
            }
            
            var phone = $('#telefoon');
            var message = 'tel. nummer niet ingevuld';
            if (phone.val().length == 0||phone.val() == message) {
                phone.addClass('errorForm');
                //phone.val(message);
                return_value = false;
            } else {
                phone.removeClass('errorForm');
            }
        /*
            var email_form = $('#vericode');
            var message = 'emailadres is niet correct';
            if (!isValidEmail(email_form.val())) {
                email_form.addClass('errorForm');
                //email_form.val(message);
                return_value = false;
            } else {
                email_form.removeClass('errorForm');
            }
             */
            var reaction = $('#vericode');
            var message = 'reactie niet ingevuld';
            if (reaction.val().length == 0||reaction.val() == message) {
                reaction.addClass('errorForm');
                //reaction.val(message);
                return_value = false;
            } else {
                reaction.removeClass('errorForm');
            }
           
                
            return return_value;
        });
        
        $('#form1005').submit(function(){
        	var field1054Value = 0;for (i = 0; i < 2; i++) {
	 			if (document.getElementById('field1054_'+ i).checked) {
		 			var bitValue = parseInt(document.getElementById('field1054_'+ i).value);
		 			field1054Value |= bitValue	 
		 		} 
			} 
			document.getElementById('field1054').value = field1054Value;
        });
        
        /** multiple education data */
        $('#educationListDetail').change(function(){
            if ($(this).find("option:selected").attr("title").length>1) {
                $('#educationData').html('<h2>Trainingsdata</h2><p>'+$(this).find("option:selected").attr("title")+'</p><br/>');
            } else {
                $('#educationData').html('');
            }
        });
        
        $('#educationListDetail').each(function(){
            if ($(this).find("option:selected").attr("title").length>1) {
                $('#educationData').html('<h2>Trainingsdata</h2><p>'+$(this).find("option:selected").attr("title")+'</p><br/>');
            } else {
                $('#educationData').html('');
            }
        });
        
        $('.educationItemSelect').change(function(){
            if ($(this).find("option:selected").attr("title").length>1) {
                $(this).parent().parent().parent().find('.educationItemDates').html('<span class="blackText">Opleiding data:</span>'+$(this).find("option:selected").attr("title"));
            } else {
                $(this).parent().parent().parent().find('.educationItemDates').html('');
            }
        });
        
        $('.educationItemSelect').each(function(){
            if ($(this).find("option:selected").attr("title").length>1) {
                $(this).parent().parent().parent().find('.educationItemDates').html('<span class="blackText">Opleiding data:</span>'+$(this).find("option:selected").attr("title"));
            } else {
                $(this).parent().parent().parent().find('.educationItemDates').html('');
            }
        });
        
        $('#dateAndTimeSelect').change(function(){
            if ($(this).find("option:selected").attr("title").length>1) {
                $('#multipleDates').html('<div class="formrow"><div class="col1"><h4>Trainingsdata</h4></div><div class="col2">'+$(this).find("option:selected").attr("title")+'</div><div class="clearfix"></div></div>');
                $('#trainingsDate').val($(this).find("option:selected").attr("title"));
            } else {
                $('#multipleDates').html('');
                $('#trainingsDate').val('');
            }
        });
        
        if ($('#dateAndTimeSelect').find("option:selected").attr("title").length>1) {
            $('#multipleDates').html('<div class="formrow"><div class="col1"><h4>Trainingsdata</h4></div><div class="col2">'+$(this).find("option:selected").attr("title")+'</div><div class="clearfix"></div></div>');
            $('#trainingsDate').val($('#dateAndTimeSelect').find("option:selected").attr("title"));
        } else {
            $('#multipleDates').html('');
            $('#trainingsDate').val('');
        }
        
        
		
	});
	
function Trim(inString) {
    var de_start = 0;
    var de_end = inString.length;
    while ((de_start < de_end) && (inString.charAt(de_start) == ' ')) {
        de_start++;
    }
    while ((de_end > 0) && (inString.charAt(de_end - 1) == ' ')) {
        de_end--;
    }
    return inString.substring(de_start, de_end);
}
function isValidEmail(str) {
    str = Trim(str);
    var pos = str.indexOf('@');
    if (str.length > 5) {
        if (str.indexOf(' ') == -1) {
            if (pos > 0 && pos < str.length - 4) {
                pos = str.indexOf('@', pos + 1);
                if (pos == -1) {
                    pos = str.length - str.lastIndexOf('.');
                    if (pos > 2 && pos < 6) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
				
	
