/******************************
(c) 2010 Niels Kim, Studio BEN
Lay-out: StudioBEN.nl
Bestand: functies.js
******************************/

$(document).ready(function(){
	/* Controle Javascript bij laden */
	$('#contact_form').show();
	$('#contact_js_error').hide();
	$('.contact_error').hide();
	
	/* Versturen mail */
	$("#cont_submit").click(function() {
		$('.contact_error').hide();

		var cspam = $("#cont_spam").val();
		var cnaam = $("#cont_naam").val();
		var cemail = $("#cont_email").val();
		var cbericht = $("#cont_bericht").val();
		if(cspam.length > 0 || cnaam.length < 3 || cemail.length < 3 || cemail.indexOf('.') == -1 || cemail.search('@') == -1 || cbericht.length < 3) {
			if(cspam.length > 0) {
				$("#cont_spam_error").slideDown();
			}
			if(cbericht.length < 3) {
				$("#cont_bericht_error").slideDown();
				$("#cont_bericht").focus();
			}
			if(cemail.length < 3 || cemail.indexOf('.') == -1 || cemail.search('@') == -1) {
				$("#cont_email_error").slideDown();
				$("#cont_email").focus();
			}
			if(cnaam.length < 3) {
				$("#cont_naam_error").slideDown();
				$("#cont_naam").focus();
			}
			return false;
		}

		var cgegevens = 'cnaam='+ cnaam + '&cemail=' + cemail + '&cbericht=' + cbericht;
		$.ajax({
			type: 'POST',
			url: 'script_mail.php',
			data: cgegevens,
			success: function() {
				$('#contact_form').html('<div id="cont_uitkomst"></div>');
				$('#cont_uitkomst').html('<p>Je bericht is succesvol verzonden. We zullen zo spoedig mogelijk reageren op je mail.</p>').hide().fadeIn();
			}
		});
		return false;
	});
	
	/* Controle Javascript bij laden */
	$('#contact_form').show();
	$('#off_js_error').hide();
	$('.off_error').hide();
	
	/* Versturen mail */
	$("#off_submit").click(function() {
		$('.off_error').hide();

		var offspam = $("#off_spam").val();
		var offnaam = $("#off_naam").val();
		var offorg = $("#off_organisatie").val();
		var offemail = $("#off_email").val();
		var offtelnr = $("#off_telnr").val();
		var offsite = $("#off_site").val();
		var offorgtekst = $("#off_orgtekst").val();
		var offverzoek = $("#off_verzoek").val();

		if(offspam.length > 0 || offnaam.length < 3 || offemail.length < 3 || offemail.indexOf('.') == -1 || offemail.search('@') == -1 || offtelnr.length < 10 || offverzoek.length < 25) {
			if(offspam.length > 0) {
				$("#off_spam_error").slideDown();
			}
			if(offverzoek.length < 25) {
				$("#off_verzoek_error").slideDown();
				$("#off_verzoek").focus();
			}
			if(offtelnr.length < 10) {
				$("#off_telnr_error").slideDown();
				$("#off_telnr").focus();
			}
			if(offemail.length < 3 || offemail.indexOf('.') == -1 || offemail.search('@') == -1) {
				$("#off_email_error").slideDown();
				$("#off_email").focus();
			}
			if(offnaam.length < 3) {
				$("#off_naam_error").slideDown();
				$("#off_naam").focus();
			}
			return false;
		}

		var offgegevens = 'offnaam='+ offnaam + '&offorg='+ offorg +'&offemail=' + offemail + '&offtelnr=' + offtelnr + '&offsite=' + offsite + '&offorgtekst=' + offorgtekst + '&offverzoek=' + offverzoek;
		$.ajax({
			type: 'POST',
			url: 'script_offerte.php',
			data: offgegevens,
			success: function() {
				$('#contact_form').html('<div id="off_uitkomst"></div>');
				$('#off_uitkomst').html('<p>Uw bericht is succesvol verzonden. We zullen zo spoedig mogelijk reageren op uw offerte-aanvraag.</p>').hide().fadeIn();
			}
		});
		return false;
	});

	var tweeturl = 'http://api.twitter.com/1/statuses/user_timeline/Studio_BEN.json?callback=?';
	$.getJSON(tweeturl,function(tweet){
		$("#bot_tweet p").html(tweet[0].text); 
	});
});

$(function(){
	$('#slides').slides({
		play: 5000,
		pause: 2500,
		hoverPause: true
	});
});

