$(document).ready(function(){
	jQuery.fx.off = false;
	
	// paste in dom-inits here
	
	// cms lightbox to fancybox
	$("a[rel*='lightbox[']").each(function(){
		var rel = $(this).attr("rel").split('[');
		$(this).attr("rel", rel[0]);
		var rev = rel[1].split(']');
		$(this).attr("rev", rev[0]);
	});
	
	// fancybox
	$("a[rel=lightbox]").fancybox({'type': 'image', titlePosition: 'over'});
	$("a[rel=lightbox_iframe]").fancybox({
		'width'				: '75%',
		'height'			: '75%',
		'autoScale'			: false,
		'transitionIn'		: 'none',
		'transitionOut'		: 'none',
		'type'				: 'iframe'
	});
    
	// contact form
	$(".close-message").click(function(event){
		$(this).parent().parent().slideUp();
		event.preventDefault();
	});
	
	// inputfill
    $(".inputfill").focus(function(){if ($(this).val() == $(this).attr("alt")) $(this).val("");
    }).blur(function(){if ($(this).val() == '') $(this).val($(this).attr("alt"));});
	
    // noSpam
	$("a.escape").each(function(){
		var el = $(this);
		var p = el.text().split('∂');
		if (el.attr('rel') != '') el.attr('href', 'mailto:'+p[0]+'@'+el.attr('rel'));
		else el.attr('href', 'mailto:'+p[0]+'@'+p[1]);
		el.html(p[0]+'@'+p[1]);
	});
});

function form_validation(form){
	var errors_occured = 0;
	$(form).find("label.required").each(function(){
		if (
				// regular text inputs
				$(this).next().val() == '' ||
				// email address inputs
				$(this).hasClass("mail") && !$(this).next().val().match(/^[\w\.\-]+@([\w\-]+\.)+[a-zA-Z]+$/) ||
				// numeric inputs
				$(this).hasClass("number") && isNaN(parseInt($(this).next().val())) ||
				// name inputs
				$(this).hasClass("name") && $(this).next().val() == 'Ihr Name' ||
				// textarea inputs
				$(this).hasClass("message") && $(this).next().val() == 'Ihre Nachricht'
		) {
			$(this).addClass("error");
			$(this).next().addClass("error");
			errors_occured = 1;
		}
		else {
			$(this).removeClass("error");
			$(this).next().removeClass("error");
		}
	});
	if (errors_occured === 0) {
		return true;
	}
	else {
		$("#fehlermeldung").slideDown(function(){
			window.location.href = "#fehlermeldung";
		});
		//$("#fehlermeldung").fadeIn();
		return false;
	}
}
