$(function(){

	// vertically align function
	$.fn.vAlign = function() {
		return this.each(function(i){
		var ah = $(this).height();
		var ph = $(this).parent().height();
			if(ph >= ah){
				var mh = (ph - ah) / 2;
				$("body").css('overflow', 'hidden');	
				$(this).css('margin-top', mh);	
				//$("body").css('margin-top', mh);	
			} else {
				$(this).css('margin-top', 10);
			}
		var aw = $(this).width();
		var pw = $(this).parent().width();
			if(pw >= aw){
				var mw = (pw - aw) / 2;
				$("body").css('overflow', 'hidden');	
				$(this).css('margin-left', mw);	
			} else {
				$(this).css('margin-top', 10);
			}
		});
	};

});

jQuery.validator.addMethod('phoneNL', function(phone_number, element) {
return this.optional(element) || phone_number.length > 9 &&
phone_number.match(/^(\(?(0|\+31)[1-9]{1}\d{1,4}?\)?\s?\d{3,4}\s?\d{3,4})$/);
}, 'Voer een correct telefoonnummer in.');

jQuery.validator.addMethod("dateNL", function(value, element) {
		return this.optional(element) || /^\d\d?[\.\/-]\d\d?[\.\/-]\d\d\d?\d?$/.test(value);
	}, "Vul hier een geldige datum in."
);
jQuery.validator.messages.required = '<img src="' + source + 'images/form/error.gif" alt="Error..." />';
jQuery(function() {
	// show a simple loading indicator
	jQuery().ajaxStart(function() {
		$(".submit").html('<img src="' + source + 'images/form/loader.gif" alt="loading..." /> Uw formulier wordt verwerkt. Een ogenblik geduld...');
	}).ajaxStop(function() {
		//loader.hide();
	}).ajaxError(function(a, b, e) {
		throw e;
	});
	
	var v = jQuery("#form").validate({
		submitHandler: function(form) {
			jQuery(form).ajaxSubmit({
				target: "#form_container"
			});
		}
	});
	
	jQuery("#reset").click(function() {
		v.resetForm();
	});
});

/* call jquery on ready */
$(document).ready(function(){
	$("#container").vAlign();
	createCookie('cont_top',$("#container").css("margin-top"),7);
	createCookie('cont_left',$("#container").css("margin-left"),7);
	$("body").pngFix();

	// add picture slider
	$("div#slide").slideView({ 
		easeTime: 1200 
	});

	// add scroll
	$('#content-holder').jScrollPane({showArrows:true});
});

/* call jquery on resize */
$(window).bind('resize', function(){	
	$("#container").vAlign(); 
	createCookie('cont_top',$("#container").css("margin-top"),7);
	createCookie('cont_left',$("#container").css("margin-left"),7);
});

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

Cufon.replace(['#nav_ul li a h4, #sub_nav h4'], {
    hover: true
});
