/**
 * Some onload stuff
 */
jQuery(document).ready(function() {

	// all links with rel='external' to blank target
	jQuery("a[rel='external']").attr("target", "_blank");
	
	//JQuery coda slider
	jQuery('#slider').codaSlider();
	
	//submit
	jQuery("input#search").watermark("Zoekterm..");
	
	// Contactform validation
	jQuery("form#contactform").validate({
		rules: {
			name: { required: true },
			email: { required: true, email: true },
			remarks: { required: true }
		},
		messages: {
			name: " ",
			email: " ",
			remarks: " "
		},
		unhighlight: validateUnhighlight,
		errorPlacement: validateErrorPlacement
	});
	// jobform validation
	jQuery("form#jobform").validate({
		rules: {
			name: { required: true },
			email: { required: true, email: true },
			remarks: { required: true }
		},
		messages: {
			name: " ",
			email: " ",
			remarks: " "
		},
		unhighlight: validateUnhighlight,
		errorPlacement: validateErrorPlacement
	});
	
	// find all a's with a mailto link. Add a tracker to them
	/* 
	jQuery("a[href^=mailto:]").each(function() {
		jQuery(this).click(function() {
			if(typeof(_gaq) != 'undefined') {
				_gaq.push(['_trackPageview', '/' + jQuery(this).attr("href")]);
			}
		});
	});
	*/
});


jQuery(window).load(function() {
	equalHeight(jQuery(".expand"));
	equalHeight(jQuery(".expandtitle"));
	equalHeight(jQuery(".expandnews"));
	equalHeight(jQuery(".expandsm"));
	equalHeight(jQuery(".expandservice"));
});

function equalHeight(group) {
	tallest = 0;
	group.each(function() {
		thisHeight = jQuery(this).height();
		if(thisHeight > tallest) {
			tallest = thisHeight;
		}
	});
	
	group.height(tallest);
}

/**
 * Validate methods to place the errors in the TD behind the TD of the input field
 */
function validateUnhighlight(element, errorClass, validClass) {
	jQuery(element).removeClass(errorClass).addClass(validClass);
	jQuery(element).parent().next().addClass(validClass);
}

function validateErrorPlacement(error, element) {
	// group checks
	if(element.hasClass("group-check")) {
		element.parent("td").next("td").html('');
	}
	
	error.appendTo( element.parent("td").next("td") );
}
