
$(document).ready(function() {
	
	$(document).pngFix();
	
	$(".error, #lijstnr, #color, .aboutContainer, #radio_4").hide();   

	$("#eigen_slogan").focus(function() {
		value=$(this).val();
		$("#radio_4").attr("value", value);
		//alert($("#radio_4").val());
	});
	$('#eigen_slogan').blur(function() {
		value=$(this).val();
		if (value != ""){
			$("#radio_4").attr("value", value);
		}
		//alert($("#radio_4").val());
	});

	var neer = false;
	$("#about_link").click(function(){
		if (!neer){
			$(".aboutContainer").slideDown("slow");
			neer = true;
		}
		else {
			$(".aboutContainer").slideUp("slow");
			neer = false;
		} 
	});
	
	$("#build_link").click(function(){
		$.scrollTo($("#vraag_1"), 1000);
	});

	$("#opties").load("php/w.php", {'aantal' : 3});

	$(".nummer_veld").mouseover(function () {
		$(this).css({'background-color' : '#ddd', 'border' : '1px dashed #999', 'cursor' : 'hand'});
	}).mouseleave(function () {
		$(this).css({'background-color' : '#fff', 'border' : '1px solid #fff'});    
	}).click(function () {
		$(".nummer_veld").each(function(){
			$(this).css({'color' : '#000', 'border' : '1px solid #fff'});
		}                   );
		$(this).css({'color' : '#f00', 'border' : '1px solid #999'});         
		var lijstnmbr = $(this).text();
		$("#lijstnr").val(lijstnmbr);
	});                           

	$(".kleurvlak").mouseover(function () {
		var rand = ($(this).css('border'));
		var dus = (rand == "#000 3px solid");
		//alert("rand = " + rand + " dus " + dus);
		if ((rand != "3px solid rgb(0, 0, 0)") && (rand != "#000 3px solid")){
			$(this).css({'border' : '3px solid #d0cfcf'});
		}
	}).mouseleave(function () {
		var rand = ($(this).css('border'));
		if ((rand != "3px solid rgb(0, 0, 0)") && (rand != "#000 3px solid")){
			$(this).css({'border' : '3px solid #fff'}); 
		}   
	}).click(function () {
		$(".kleurvlak").each(function(){
			$(this).css({'border' : '3px solid #fff'});
		});
		$(this).css({'border' : '3px solid #000'});         
		var kleur_nr = $(this).text();
		$("#kleur_nr").val(kleur_nr);
	})
	
	$(".kleurvlak").each(function(){
		$(this).css({'border' : '3px solid #fff'});
	});


	$('#generate').mousedown(function(){  
		$(this).attr("src","images/opties_hover.gif");
	}).mouseup(function(){
		$(this).attr("src","images/opties.gif");  
	});  

	$("#generate").click(function(){ 
		$("#opties").load("php/w.php", {'aantal' : 3});
	});

	$('#doemee_link').click(function(){
		$.scrollTo($("#vraag_1"), 1000);
	});

	$('#submitbutton').mousedown(function(){  
		$(this).attr("src","images/instuurbtn_down.gif");
	}).mouseup(function(){
		$(this).attr("src","images/instuurbtn.gif");  
	}).click(function(e) {

		$('.error').hide();

		if ($("input#naam").val() == "") {
			$("label#naam_error").show();
			$.scrollTo($("#vraag_1"), 1000);
			setTimeout(function() { 
				$("input#naam").focus();
			}, 1); 
			return false;
		}
		
		if (($("input[@name='slogan']:checked").val() === undefined) && ($('#eigen_slogan').val() == "")){
			$("label#slogan_error").show();
			$.scrollTo($("#vraag_2"), 1000);
			return false;
		}

		if ($("input#lijstnr").val() == "") {
			$("label#lijstnr_error").show();
			$.scrollTo($("#vraag_3"), 1000);
			$("input#lijstnr").focus();
			return false;
		}
		
		if ($("input#kleur_nr").val() == "") {
			$("label#kleur_error").show();
			$.scrollTo($("#vraag_4"), 1000);
			setTimeout(function() { 
				$("input#kleur_nr").focus();
			}, 1);
			return false;
		}
			
		if ($("input#richting").val() == "") {
			$("label#richting_error").show();
			$.scrollTo($("#vraag_5"), 1000);
			return false;
		}
		
		if ($("input#logo").val() == "") {
			$("label#logo_error").show();
			$.scrollTo($("#vraag_6"), 1000);
			return false;
		}
			/*		var formData = $('#formulier').serialize();

				$.ajax({
					type: "POST",
					url: "php/s.php",
					data: formData,
					success: function(d) {
						$('#content').empty().html(d);
					}
				});
				e.preventDefault();*/
				
		$("form").submit();
				
	});		
		
});