$(document).ready(function() 
{
	// Elastic textarea
	$('.elastic').elastic();

	$('#huisstijlen a').lightBox({fixedNavigation:true});

	// Form validatie Homepage:
	// validate signup form on keyup and submit
	$("#snelcontact").validate({
		rules: {
			naam: {
				required: true,
				minlength: 2
			},
			telefoon: {
				required: true,
				minlength: 10
			},
			email: {
				required: true,
				email: true
			},
			bericht: {
				required: true,
				minlength: 10
			}
		},
		messages: {
			naam: {
				required: "<span class='fout'>Geen naam ingevuld<br /><br /></span>",
				minlength: "<span class='fout'>Naam is te kort <br /><br /></span>"
			},
			email: "<span class='fout'>E-mailadres is niet geldig <br /><br /></span>",
			bericht: {
				required: "<span class='fout'>Bericht is leeg<br /><br /></span>",
				minlength: "<span class='fout'>Bericht is te kort<br /><br /></span>"
			},	
			telefoon: {
				required: "<span class='fout'>Het telefoonnummer is leeg<br /><br /></span>",
				minlength: "<span class='fout'>Het telefoonnummer is te kort<br /><br /></span>"
			}	
		}
		
	});
	
	
	// Homepage Bewegende items:
	$(function(){
		
		var seconds = 3000;
		var aantal = $('.homeKaderLinks li', this).length;		
		var totaal = aantal-1;
		var i = 0;
		
		$('.homeKaderLinks ul li a', this).mouseover(function(){
			clearTimeout(timeout);
			
			$('#imgKaderRechts').attr('src', 'img/' + $(this).attr('id') + '.jpg');
			
			$('.homeKaderLinks ul li a').hover(function(){
				$('.homeKaderLinks ul li a').removeClass('homeKaderHover');
				$(this).addClass('homeKaderHover');
			});
		});
		
		$('.homeKaderLinks ul li a', this).mouseout(function(){
			i = $(this).attr('id').replace('kader', '');
			i = i-1;
			
			timeout = setInterval(function(){
				nextItem();
			}, seconds);
		});
		
		timeout = setInterval(function(){
			nextItem();
		}, seconds);
		
		function nextItem()
		{
			if(i == totaal)
			{
				i = 0;
			}
			else
			{
				i = (i >= totaal) ? totaal : i+1;
			}
			
			$('#imgKaderRechts').attr('src', 'img/kader' + i + '.jpg');
			
			$('.homeKaderLinks ul li a').removeClass('homeKaderHover');
			$('#kader' + i).addClass('homeKaderHover');
		}	
		
	});
		
	// Contact form, send email
	$('.error').hide();
	$("#submit").click(function(){
		$('.error').hide();
		
		var naam = $("#naam").val(); 
		if(naam == "" || naam == "Uw naam")
		{
			$('label#naam_error').show();
			$('input#naam').focus();
			return false;
		}
		
		var bedrijf = $("#bedrijf").val();  
		if(bedrijf == "" || bedrijf == "Uw bedrijfsnaam")
		{
			$('label#bedrijf_error').show();
			$('input#bedrijf').focus();
			return false;
		}
		
		var email = $("#email").val();  
		if(email == "" || email == "Uw e-mail")
		{
			$('label#email_error').show();
			$('input#email').focus();
			return false;
		}
		
		var telefoon = $("#telefoon").val();  
		if(telefoon == "" || telefoon == "Uw telefoonnummer")
		{
			$('label#telefoon_error').show();
			$('input#telefoon').focus();
			return false;
		}
		
		var bericht = $("#bericht").val();  
		if(bericht == "")
		{
			$('label#bericht_error').show();
			$('input#bericht').focus();
			return false;
		}
		
		var dataString = 'naam=' + naam + '&bedrijf=' + bedrijf + '&telefoon=' + telefoon + '&bericht=' + bericht + '&email=' + email;
		
		$.ajax({
		    type: "POST",
		    url: "mail.php",
		    data: dataString,
		    success: function(){  
				$('#contact_form').html("<div id='message'></div>");
				$('#message').html("<br /><p>Bedankt voor uw bericht!</p>");
			} 
		});
		return false;
	}); 

});
  
// clearTxt / onfocus
function clearTxt(field, txt)
{
	if($('#' + field).val() == txt)
	{
		$('#' + field).val('');
	}
}

// resetTxt / onblur
function resetTxt(field, txt)
{
	if($('#' + field).val() == '')
	{
		$('#' + field).val(txt);
	}
}