/*
	Beetjehulp.nl

	(c) 2010 - TRES internet
	http://www.tres.nl/
*/


/**
  * Alert configuration
**/
$(function() {
	$.alerts.overlayOpacity = 0.75;
	$.alerts.overlayColor = "#ED1C24";
});

$(function() {

	/**
	  * FAQ toggle
	**/
	$(".faqQuestion .question").toggle(
		function() {
			$(this).next().slideDown("normal");
		}, 
		function() { 
			$(this).next().slideUp("normal") 
		}
	);
	$("div.faqQuestion + h2").css({
		"margin": "10px 0 0 0"
	});

	/**
	  * Clear buttons
	**/
	$("a.button").after("<div class=\"clear\"></div>");

	/**
	  * Tabellen met afbeeldingen
	**/
	$("table.houses td:not(:first-child):contains('x')").addClass("checked").text("");
	
	$("table.compare td:not(:first-child):contains('[x]')").each(function() {
		$(this).addClass("no").text($(this).text().replace("[x]", ""));
	});
	$("table.compare td:not(:first-child):contains('[v]')").addClass("yes").text("");

	// Toon laatste tweets
	$(".tweet").tweet({
		join_text: "auto",
		avatar_size: 1,
		count: 2,
		query: "beetjehulp",
		loading_text: "laden..."
	});


	// Toon betalingswijze
	if ($("#payment_1_2:checked").length > 0) {
		$("#payment_machtiging").show();
	} else {
		$("#payment_machtiging").hide();
	}
	
	$("#payment_1_2").change(function() {
		if ($(this).is(":checked")) {
			$("#payment_machtiging").slideDown();
		}
	});
	$("#payment_1_1").change(function() {
		if ($(this).is(":checked")) {
			$("#payment_machtiging").slideUp();
		}
	});

	// Open Twitter-links in nieuw venster
	$("section.twitter a").live("click", function() {
		$(this).attr("target", "_blank")
	});

	// footerBlock aanpassen
	$("footer#sitemap nav.footerBlock:nth-child(4n)").after("<div class=\"clear\"></div>");

	$("div.house div.houseImage a").hover(function() {
		$(this).closest("div.house").find("div.houseDescription a").addClass("hover");
	}, function() {
		$(this).closest("div.house").find("div.houseDescription a").removeClass("hover");
	});

});

// Foutafhandeling voor diverse aanmeldformulieren
$(function() {
	$("#formVerkoop, #formBezichtigen, #formKopen, #formAfhandelen").submit(function() {
		var valid = true;
		$(this).find("input[required], input[required='']").each(function() {
			if ($(this).val() == "") {
				$(this).addClass("invalid");
			} else {
				$(this).removeClass("invalid");
			}
		});
		$(this).find("input[required], input[required='']").each(function() {
			if ($(this).val() == "") {
				jAlert('Je hebt niet alle verplichte velden ingevuld', 'beetjehulp.nl');
				valid = false;
				return false;
			}
		});
		if ($(this).find("input[name='password_repeated']").length > 0) {
			if ($(this).find("input[name='password_repeated']").val() != $(this).find("input[name='password']").val()) {
					jAlert('De ingevulde wachtwoorden komen niet overeen', 'beetjehulp.nl');
					valid = false;
					return false;
			}
		}
		return valid;
	});
});

// Random testimonials
arrTestimonials = new Array();
function testimonial(title, tagline, body) {
	this.title = title;
	this.tagline = tagline;
	this.body = body;
}
$(function() {
	$("section.itemBlock.testimonial").each(function() {
		if (arrTestimonials.length > 0) {
			var myTestimonial = arrTestimonials[Math.floor(Math.random()*arrTestimonials.length)];
			$(this).append("<h2>" + myTestimonial.title + "</h2>")
				.append("<p>" + myTestimonial.tagline + "</p>")
				.append("<div class=\"quote\">" + myTestimonial.body + "</div>");
		}
	});
});

$(function(){
	$("table.standaard").each(function(){
		$(this).after("<div class=\"clear\"></div>");
	});
});
