$(document).ready(function() {

	var input = $('.input-text input, .textarea textarea');
	
	input.focus(function () {
	
		var $this = $(this),
			parent = $this.parent().parent();
		
		if ($this.attr('rel') === $this.val()) {
			$this.val('');
			parent.addClass('focus');
		} else {
			parent.addClass('focus');
		}
	});
	
	input.blur(function () {
		var $this = $(this),
			parent = $this.parent().parent();
		
		if ($.trim($this.val()).length === 0) {
			$this.val($this.attr('rel'));
			parent.removeClass('focus');
		} else {
			parent.removeClass('focus');
		}
	});

	/* Automatically resize the textarea */
	$('.textarea textarea').autoResize({
		
		//give height to parent each time the field is animated. This is an IE6 fix.
		animateCallback : function () { 
			var $this = $(this), height = parseInt($this.height(), 10);
			$this.parent().height(height + 'px');
		},
		animateDuration : 0, //we do not want any fancy animation
		extraSpace: 0
	});
	
	/* setup the validation */
	jQuery.validator.setDefaults({ 
		highlight: function(element) {
			$(element).parent().parent().addClass('error');
		},
		unhighlight: function(element) {
			$(element).parent().parent().removeClass('error');
		} 
	});

	jQuery.validator.addMethod(
    	"NLdate",
	    function(value, element) {
	        return value.match(/^\d\d?\-\d\d?\-\d\d\d\d$/);
	    },
	    "Vul een geldige datum in. (dd-mm-jjjj)"
	);
	
	
	/* Simple Search */
	$('#simple_search').validate();
	
	/* Fancybox */
	$('.imageviewer a').fancybox({
		'zoomSpeedIn': 300,
		'zoomSpeedOut': 300
	});
	
	
	/* Make extgernal links open in a new window */
 	$('a').filter(function() {
		return this.hostname && this.hostname !== location.hostname; //is external?
	}).addClass("external").attr("target", "_blank");	
});
