$(document).ready(function() {
	// Handle default value searchbar
	$("input#s").click(function() {
		if( $("input#s").attr("value") == "Zoeken..." ) {
			$("input#s").attr("value", "");
		}
	});
	$("input#s").blur(function() {
		if( $("input#s").attr("value") == "" ) {
			$("input#s").attr("value", "Zoeken...");
		}
	});

	$("span.buttons a.font").click(function(){
		var content = $("section.post_content p");
		var font = parseFloat(content.css("font-size"));
		if($(this).hasClass('up') && font <= 17) {
			$("section.post_content p").css("font-size", (font+1)+'px');
		} else if($(this).hasClass('down') && font >= 11) {
			$("section.post_content p").css("font-size", (font-1)+'px');
		}
	});

	$("span.buttons a.width").click(function(){
		if($(this).hasClass('small')) {
			$("section.post_content").css("margin", "0 320px");
		} else if($(this).hasClass('normal')) {
			$("section.post_content").css("margin", "0 160px");
		} else if($(this).hasClass('max')) {
			$("section.post_content").css("margin", "0");
		}
	});

    $('textarea#comment').keyup(function() { 
		word_count();
	});

	$('#commentform').submit(function(){
		word_count();
		if($("span.charCount").hasClass('warning')) {
			alert('Uw reactie bevat meer dan 350 woorden. Wijzig s.v.p. uw reactie.');
			return false;
		}
	});
});

function word_count() {
	var charCount = $('span.charCount');
	var number = 0;
	var matches = $('textarea#comment').val().match(/\b/g);
	if(matches) { number = matches.length/2; }
	charCount.text( number + ' / 350 woorden');
	if (number > 350) {
		charCount.addClass('warning');
	} else if(charCount.hasClass('warning')) { 
		charCount.removeClass('warning');
	}
}
