$(function() {


	$(".formbuilder_formpanel input:radio").addClass("noBorder");
	$(".formbuilder_formpanel input:checkbox").addClass("noBorder");
	$(".formbuilder_formpanel input:checkbox").css("border", "0");
			

/* Zoekformulier */
$('.zoekknop').click(function() {
	searchSubmit($(this));
	return false;
});
var searchSubmit = function(sNode) {
	var theForm = $(sNode).parent();
	var searchInputText = $(theForm).find('input:text');
	var searchInputHidden = $(theForm).find('input:hidden');
	searchTerm = encodeURIComponent(searchInputText.val());
	if (searchTerm.length > 1) {
		$("form").submit(function() { return false });
		var searchUrl = searchInputHidden.val();
		searchUrl += searchTerm;
		window.location = searchUrl;
	} else {
		alert('Vul minstens twee tekens in om te zoeken.');
		return false;
	}
}
$("#zoek input:text").each(function() {
	$(this).keydown(
			function(e) {
				if (e.keyCode == 13) {
					searchSubmit($(this));
					return false;
				}
			}
		);
	$(this).focus(
			function() {
				this.value = '';
				//				this.className = 'zoekveld';
			}
		);
	$(this).blur(
			function() {
				if (this.value == '') {
					this.value = '';
					//					this.className = 'zoekveld';
				}
			}
		)
}
	)

	if (document.body.id == 'homepage')
	{
		initShowCase();
		setShowFadeEventHandlers("#showCase");
	}
});

var initShowCase = function()
{
	var current = $("#showCase .case:first");
	current.find(".item").css("opacity","1")
	$("#showCase .case").each(
		function()
		{
			$("#showCase .case:first").addClass("aktief");
			$(this).hover(
				function()
				{
					current.removeClass("aktief");
					current = $(this);
					$(this).addClass("aktief");
				},
				function() { }
			)
			$(this).click(
				function()
				{
					window.location = $(this).find("a")[0].href;
					return false;
				}
			);
		}
	);
}

function setShowFadeEventHandlers(containerExpression)
{
	// Fade alle contentgebieden instant uit en verwijder alle active classes
	$(containerExpression+" .item").fadeOut(0);
	$(containerExpression+" .item").removeClass("active");
	$(containerExpression+" .case").removeClass("active");
	
	// Fade content 1 in en voeg een class active toe
	$(containerExpression+" .item:eq(0)").fadeIn(400);
	$(containerExpression+" .item:eq(0)").addClass("active");
	$(containerExpression+" .case:eq(0)").addClass("active");
	
	// Voeg hover event handlers toe aan de navigaties
	$(containerExpression+" .case").each(function()
	{
		$(this).hover(function()
		{
			// Controleer of de betreffende content al is ingefade, zo niet ga verder
			if (!$(this).next(".item:eq(0)").hasClass("active"))
			{
				// Breng alle lopende animaties op de content elementen instant naar hun eindpositie
				$(containerExpression+" .item").stop(true,true);
				
				// Fade alle contentgebieden uit en verwijder alle active classes
				$(containerExpression+" .item").fadeOut(400);
				$(containerExpression+" .item").removeClass("active");
				$(containerExpression+" .case").removeClass("active");
				
				// Fade de betreffende content in en voeg een class active toe
				$(this).next(".item:eq(0)").fadeIn(400);
				$(this).next(".item:eq(0)").addClass("active");
				$(this).addClass("active");
			}
		});
	});
}

$(document).ready(function() {
	$("#voorbeeld_bericht, #voorbeeld_naam, #voorbeeld_naam_ontvanger, .top, .bottom").hide();	
	$('.formbuilder_formpanel input, .formbuilder_formpanel textarea').bind('blur keyup',function() {
	
		//naam ontvanger
		if($('#Formulier__yezsp7eaap____formbuilder_textbox_yezsp7eaap_').val()) {
			$("#voorbeeld_naam_ontvanger").show();
			$(".top").show();
			$(".bottom").show();
			$('#voorbeeld_naam_ontvanger').html('Hallo ' + $('#Formulier__yezsp7eaap____formbuilder_textbox_yezsp7eaap_').val() + '.<br/>');
		} else {
			$("#voorbeeld_naam_ontvanger").hide();	
		}
		
		//naam
		if($('#Formulier__jevgjgl4oi____formbuilder_textbox_jevgjgl4oi_').val()) {
			$("#voorbeeld_naam").show();
			$(".top").show();
			$(".bottom").show();
			$('#voorbeeld_naam').html($('#Formulier__jevgjgl4oi____formbuilder_textbox_jevgjgl4oi_').val() + ' is nu echt iets leuks tegengekomen: een site waarop een Quiz staat met leuke sportvragen. Op deze site vind je allerlei informatie over het worden van scheidsrechter.<br/><br/>Kijk dus snel even op de site, <a href="http://www.scheidsrechterworden.nl" target="_blank">http://www.scheidsrechterworden.nl</a><br/><br/>Ook heeft ' + $('#Formulier__jevgjgl4oi____formbuilder_textbox_jevgjgl4oi_').val() + ' het volgende bericht achter gelaten:<br/>');
		} else {
			$("#voorbeeld_naam").hide();	
		}
		
		// bericht
		if($('#Formulier__eh91onhh73____formbuilder_textarea_eh91onhh73_').val()) {
			$("#voorbeeld_bericht").show();
			$(".top").show();
			$(".bottom").show();
			$('#voorbeeld_bericht').html($('#Formulier__eh91onhh73____formbuilder_textarea_eh91onhh73_').val() + '<br/><br/>Met vriendelijke groet:<br/><br/>' + $('#Formulier__jevgjgl4oi____formbuilder_textbox_jevgjgl4oi_').val() + '<br/>' + $('#Formulier__avlj9x0rp4____formbuilder_textbox_avlj9x0rp4_').val() + '<br/><br/>en, Scheidsrechterworden.nl');
		} else {
			$("#voorbeeld_bericht").hide();	
		}
		
		if ($("#voorbeeld_naam_ontvanger:hidden").length && $("#voorbeeld_naam:hidden").length && $("#voorbeeld_bericht:hidden").length){
			$(".top").hide();
		} else {
			$(".top").show();
		}


	});
});


var getQueryVariable = function(variable)
{
	var query = window.location.search.substring(1);
	var vars = query.split("&");

	for (var i = 0; i < vars.length; i++)
	{
		var pair = vars[i].split("=");
		if (pair[0] == variable)
		{
			return pair[1];
		}
	}
	return;
}