$(document).ready(function(){
	menu();
	setFooterHeight();
	setBackgroundHeight();
});

function setFooterHeight() {
	var nTopHeight = $("#footer-top").height();
	var nBottomHeight = $(".list_container").height();
	var nHeight = Math.round(nTopHeight + nBottomHeight);
	$('#footer').css('height',nHeight);
	$('#site').css("padding-bottom",nHeight);
}
function setBackgroundHeight() {
	$("#background .background img").load(function() {
		var nBackgroundHeight = $("#background .background img").height();
		var nBgHeight = Math.round(nBackgroundHeight+1);
		$('#background, .background').css('height',nBgHeight);
	});
}

function menu() {
	$('.nav_item:not(.active)').hover(function() {
		$(this).addClass('active');
		$(this).children('.submenu').show();
	}, function() {
		$(this).removeClass('active');
		$(this).children('.submenu').hide();
	});
}

$(document).ready(function() {
    $('a[href=#top]').click(function(){
        $('html, body').animate({scrollTop:0}, 'slow');
        return false;
    });
});

$(document).ready(function() {
	$('.offerte').click(function(){
		$.scrollTo( '#offerte_form', 500, { axis:'y' } );
	});
});

function initLightbox(){
	var nTotal = $('.container .lightbox').size();		
	for(var nI = 1; nI <= nTotal; nI++){
		$('a.lightbox-'+nI+'').lightBox({
			containerResizeSpeed: 150						 
		});	
	}
}

function validateForm(p_sForm) {

	$.validator.addMethod('group', function(value, element) {
		var obj = $('.form');
		return obj.find('.group:filled').length;
	}, '');	

	switch(p_sForm) {
		
		case 'contact':

			var rules = {};
			rules[oFields[p_sForm][1]] = {
				required: true,
				notags: true,
				minlength: 2
			};
			rules[oFields[p_sForm][2]] = {
				required: true,
				notags: true,
				minlength: 2
			};
			rules[oFields[p_sForm][3]] = {
				required: true,
				notags: true,
				number: true,
				minlength: 10
			};
			rules[oFields[p_sForm][4]] = {
				required: true,
				notags: true,
				email: true,
				minlength: 2
			};
			rules[oFields[p_sForm][5]] = {
				notags: true,
				minlength: 2
			};
			rules[oFields[p_sForm][6]] = {
				notags: true
			};
			
			var messages = {};
			messages[oFields[p_sForm][1]] = {
				required: 'Vul hier uw naam in.',
				notags: 'U mag geen tags invoeren.',
				minlength: 'Vul minimaal 2 karakters in.'
			};
			messages[oFields[p_sForm][2]] = {
				required: 'Vul hier uw woonplaats in.',
				notags: 'U mag geen tags invoeren.',
				nonumber: 'U mag hier geen nummers invoeren',
				minlength: 'Vul minimaal 2 karakters in.'
			};
			messages[oFields[p_sForm][3]] = {
				required: 'Vul uw telefoonnummer in.',
				notags: 'U mag geen tags invoeren.',
				number: 'Vul hier een geldig telefoonnummer in.',
				minlength: 'Vul minimaal 10 cijfers in.'
			};
			messages[oFields[p_sForm][4]] = {
				required: 'Vul uw e-mailadres in.',
				email: 'Vul hier een geldig e-mailadres in.',
				notags: 'U mag geen tags invoeren.',
				minlength: 'Vul minimaal 2 karakters in.'
			};
			messages[oFields[p_sForm][5]] = {
				notags: 'U mag geen tags invoeren.',
				minlength: "Vul minimaal 2 karakters in."
			};
			messages[oFields[p_sForm][6]] = {
				notags: 'U mag geen tags invoeren.'
			};
		
		break;
		case 'contactzakelijk':

			var rules = {};
			rules[oFields[p_sForm][1]] = {
				required: true,
				notags: true,
				minlength: 2
			};
			rules[oFields[p_sForm][2]] = {
				required: true,
				notags: true,
				minlength: 2
			};
			rules[oFields[p_sForm][3]] = {
				required: true,
				notags: true,
				minlength: 2
			};
			rules[oFields[p_sForm][4]] = {
				required: true,
				notags: true,
				number: true,
				minlength: 10
			};
			rules[oFields[p_sForm][5]] = {
				required: true,
				notags: true,
				email: true,
				minlength: 2
			};
			rules[oFields[p_sForm][6]] = {
				notags: true,
				minlength: 2
			};
			
			var messages = {};
			messages[oFields[p_sForm][1]] = {
				required: 'Vul hier uw naam in.',
				notags: 'U mag geen tags invoeren.',
				minlength: 'Vul minimaal 2 karakters in.'
			};
			messages[oFields[p_sForm][2]] = {
				required: 'Vul hier uw bedrijfsnaam in.',
				notags: 'U mag geen tags invoeren.',
				minlength: 'Vul minimaal 2 karakters in.'
			};
			messages[oFields[p_sForm][3]] = {
				required: 'Vul hier uw werklocatie in.',
				notags: 'U mag geen tags invoeren.',
				nonumber: 'U mag hier geen nummers invoeren',
				minlength: 'Vul minimaal 2 karakters in.'
			};
			messages[oFields[p_sForm][4]] = {
				required: 'Vul uw telefoonnummer in.',
				notags: 'U mag geen tags invoeren.',
				number: 'Vul hier een geldig telefoonnummer in.',
				minlength: 'Vul minimaal 10 cijfers in.'
			};
			messages[oFields[p_sForm][5]] = {
				required: 'Vul uw e-mailadres in.',
				email: 'Vul hier een geldig e-mailadres in.',
				notags: 'U mag geen tags invoeren.',
				minlength: 'Vul minimaal 2 karakters in.'
			};
			messages[oFields[p_sForm][6]] = {
				notags: 'U mag geen tags invoeren.',
				minlength: "Vul minimaal 2 karakters in."
			};

		break;
		case 'contactform':

			var rules = {};
			rules[oFields[p_sForm][1]] = {
				required: true,
				notags: true,
				minlength: 2
			};
			rules[oFields[p_sForm][2]] = {
				required: true,
				notags: true,
				minlength: 2
			};
			rules[oFields[p_sForm][3]] = {
				required: true,
				notags: true,
				number: true,
				minlength: 10
			};
			rules[oFields[p_sForm][4]] = {
				required: true,
				notags: true,
				email: true,
				minlength: 2
			};
			rules[oFields[p_sForm][5]] = {
				required: true,
				notags: true,
				minlength: 2
			};
			
			var messages = {};
			messages[oFields[p_sForm][1]] = {
				required: 'Vul hier uw naam in.',
				notags: 'U mag geen tags invoeren.',
				minlength: 'Vul minimaal 2 karakters in.'
			};
			messages[oFields[p_sForm][2]] = {
				required: 'Vul hier uw naam in.',
				notags: 'U mag geen tags invoeren.',
				nonumber: 'U mag hier geen nummers invoeren',
				minlength: 'Vul minimaal 2 karakters in.'
			};
			messages[oFields[p_sForm][3]] = {
				required: 'Vul uw telefoonnummer in.',
				notags: 'U mag geen tags invoeren.',
				number: 'Vul hier een geldig telefoonnummer in.',
				minlength: 'Vul minimaal 10 cijfers in.'
			};
			messages[oFields[p_sForm][4]] = {
				required: 'Vul uw e-mailadres in.',
				email: 'Vul hier een geldig e-mailadres in.',
				notags: 'U mag geen tags invoeren.',
				minlength: 'Vul minimaal 2 karakters in.'
			};
			messages[oFields[p_sForm][5]] = {
				required: 'Vul hier uw aanvraag in.',
				notags: 'U mag geen tags invoeren.',
				minlength: "Vul minimaal 2 karakters in."
			};
		
		break;
	}
	
	$('#'+p_sForm).validate({
		rules: rules,
		messages: messages,
		errorPlacement: function(error, element) {
			var obj = element.parent().next('div.icon');
			error.insertAfter(obj);
			obj.attr('class','icon invalid');
		},
		success: function(label) {
			label.prev('div.icon').attr('class','icon valid');
			label.remove();
		},
		submitHandler: function(form) {
			form.trigger('submit');
		}
	});	
}
