$(document).ready(function(){

	$('#home').hover(function(){
		$(".submenu").hide();
		$("#submenu_home").show();
		//$(".submenu").css('display', 'block');
	});

	$('#over_ons').hover(function(){
		$(".submenu").hide();
		$("#submenu_over_ons").show();
	});

	$('#showroom').hover(function(){
		$(".submenu").hide();
		$("#submenu_showroom").show();
	});

	$('#occasions').hover(function(){
		$(".submenu").hide();
		$("#submenu_occasions").show();
	});

	$('#media').hover(function(){
		$(".submenu").hide();
		$("#submenu_media").show();
	});

	$('#contact').hover(function(){
		$(".submenu").hide();
		$("#submenu_contact").show();
	});

	$('.submenu').hover(
		function(){

		},
		function(){
			$('.submenu').hide();
		}
	);


	$('.kopje').click(function(){
		if ($(this).siblings('.inhoud').hasClass('active')==false)
			$('.inhoud').slideUp().removeClass('active');

		$(this).siblings('.inhoud').addClass('active').slideDown();
	});

	$('.inhoud').hide();
	$('.inhoud:first').slideDown();

	
	//AJAX FORMS automatisch
	if (typeof $().ajaxForm == 'function')
	{
		$('form.js_ajaxform').each(function(){
			$(this).append('<input type="hidden" name="ajax_post" value="oke" />');
			var form = $(this);
			$(this).ajaxForm({
				dataType: 'json',
				beforeSerialize: function(){
					form.find('.js_hint').val('');
				},
				beforeSubmit: function(){
					form.parent().find('.js_errormelding').remove();

					//vereiste velden
					form.find('.js_required').each(function(){
						if ($(this).val().replace(' ', '') == '' || $(this).hasClass('js_hint')) //leeg of bevat nog de hint
						{
							return false;
							$(this).addClass('js_formerror');
						}
						else
							$(this).removeClass('js_formerror');
					});
					form.find('.js_required.email').each(function(){
						var regex = /^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
						if (!regex.test($(this).val()))
						{
							return false;
							$(this).addClass('js_formerror');
						}
					});
				},
				success: function(response){
					if (response.success)
					{
						if ( response.type == 's60_intro' )
						{
							$('#maincontainer').addClass('bedankt');
							form.remove();
						}
						else
							form.html('<p>'+response.melding+'</p>');
					}
					else if (response.type == 'inline')
					{
						form.before($('<p class="errormelding">'+response.melding+'</p>'));
					}
					else if (response.type == 'alert')
					{
						alert(response.melding);
					}
					
					form.find('.js_hint').trigger('blur');
				}
			})
		})
	}
	
	$('.js_colorbox').colorbox({ iframe: true, height:'630px', width:'770px' });
	
	
});


function is_child_of(parent, child) {
	if( child != null ) {
		while( child.parentNode ) {
			if( (child = child.parentNode) == parent ) {
				return true;
			}
		}
	}
	return false;
}
