jQuery.extend(jQuery.validator.messages, {
        required: "Verplicht",
        remote: "Controleer dit veld.",
        email: "Vul een geldig emailadres in.",
        url: "Vul hier een geldige URL in.",
        date: "Vul hier een geldige datum in.",
        dateISO: "Vul hier een geldige datum in (ISO).",
        number: "Vul hier een geldig nummer in.",
        digits: "Vul hier alleen nummers in.",
        creditcard: "Vul hier een geldig credit card nummer in.",
        equalTo: "Vul hier dezelfde waarde in.",
        accept: "Vul hier een waarde in met een geldige extensie.",
        maxlength: jQuery.validator.format("Vul hier maximaal {0} tekens in."),
        minlength: jQuery.validator.format("Vul hier minimaal {0} tekens in."),
        rangelength: jQuery.validator.format("Vul hier een waarde in van minimaal {0} en maximaal {1} tekens."),
        range: jQuery.validator.format("Vul hier een waarde in van minimaal {0} en maximaal {1}."),
        max: jQuery.validator.format("Vul hier een waarde in kleiner dan of gelijk aan {0}."),
        min: jQuery.validator.format("Vul hier een waarde in groter dan of gelijk aan {0}.")
});

var popupStatus = 0;

//loading popup with jQuery magic!
function loadPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disablePopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	//centering
	$("#popupContact").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

function goToPage(page)
{
	window.location.href = page;
}


$(document).ready(function($){

	$("a.photobox").fancybox({
		'zoomSpeedIn'	: 0, 
		'zoomSpeedOut'	: 0,
		'overlayShow'	: true,
		'padding'		: 0,
		'overlayOpacity': 0.6
	});    
	
	$("a.vimeo").fancybox({
		'zoomSpeedIn'	: 100, 
		'zoomSpeedOut'	: 100,
		'width'			: 720,
		'height'		: 415,
		'overlayShow'	: true,
		'padding'		: 0,
		'overlayOpacity': 0.6,
		'autoScale'		: true,
		'type'			: 'iframe'
	});    
	

	// Object photos
	$('#sfeer').cycle({ 
	    fx:    'fade', 
    	timeout:  4000,
   	 	speed: 4000 
	});
	
	/*jQuery("div.autopopup").fancybox({
		'zoomSpeedIn':	0, 
		'zoomSpeedOut':	0,
		'frameWidth':	800, 
		'frameHeight':	800,
		'overlayShow': true,
		'overlayOpacity': 0.8,
		'hideOnContentClick': false,
		'type': 'iframe'
	});*/
	
	 
	if(jQuery("div#popupContact").length>0){
        if(jQuery.cookie('stopbanner')==null){ // eerste bezoek
             jQuery.cookie('stopbanner', 'true', { expires: 1, path: '/', domain: 'avvafbouw.nl'});
            		loadPopup();
					centerPopup();
             // setTimeout("jQuery.fn.fancybox.close()", 5000); // automatisch sluiten
        }
    };
    
    $(".block-2, .block-3, .block-4").click(function () {
 		if($(this).find('a').attr("href")){
			window.location = $(this).find('a').attr("href");
		}
    });
    
	 setInterval(function() {
        var elt = $('#puntenslider p.active');
        var nextelt;
        if (elt.is(":last-child")) nextelt = $('#puntenslider p:first-child');
        else nextelt = elt.next();
        elt.removeClass('active');
        nextelt.addClass('active');
    }, 3000);
    
    $("div#autopopup").click(function(){
		//centering with css
		centerPopup();
		//load popup
		loadPopup();
	});
				
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disablePopup();
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disablePopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disablePopup();
		}
	});
	
	$("a.videolink").fancybox({
		'zoomSpeedIn':	100, 
		'zoomSpeedOut':	100,
		'frameWidth': 720,
		'frameHeight': 425,
		'overlayShow': true,
		'overlayOpacity': 0.8,
		'hideOnContentClick': false,
		'type' : 'iframe'
	}); 
	
	$("a.fancybox").fancybox({
			'width'				: '500',
			'height'			: '250',
			'autoScale'			: false,
			'transitionIn'		: 'none',
			'transitionOut'		: 'none',
			'overlayColor'		: '#000'
		});
		
		
	runEffect();

 	setInterval(function() {
      runEffect();
    }, 8000);

/*
$( "#content-body" ).animate( { 
width: "68%" }, { queue: false, duration: 1500 });

$('.test').slideDown(2000);
*/
});


// run the currently selected effect
function runEffect() {

	// get effect type from 
	var selectedEffect = "shake";
	
	// most effect types need no options passed by default
	var options = {};
			// run the effect
	$( ".block-2" ).effect( selectedEffect, options,100, callback );
};

// callback function to bring a hidden box back
function callback() {
	setTimeout(function() {
		$( ".block-2" ).removeAttr( "style" ).hide().fadeIn();
	}, 6000 );
};


