$(document).ready(function(){
	jQuery.fx.off = false;
	/*
	// slideshow
	$('.cycles').cycle({fx: 'fade'});
	
    // bind date picker
    $('.date').datepick();
    
    // init smoothAnchors
    $.smoothAnchors(1000, "easeInOut", false);
    
    // inputfill
    $(".inputfill").focus(function(){
        if ($(this).val() == $(this).attr("alt")) $(this).val("");
    }).blur(function(){
        if ($(this).val() == '') $(this).val($(this).attr("alt"));
    });
	*/
	//ajax	
	$("#nm-leistungen ul").load("Leistungen.b7f02.php #navigationAdditional li", function(){
		$("#nm-leistungen ul").css('opacity','0.92');
		$("#nm-leistungen a").click(function(event){
			$("#nm-leistungen ul").toggle();
			event.preventDefault();
		});
		$("#nm-leistungen ul li a").unbind('click');
	});
	$("#footer-partner").load("cms-partner.php #carousel", function(){
		$("#carousel").customCarousel({
			viewportSize: 960,
			itemsPerSlide: 8,
			autoPlay: true,
			displayTime: 3000,
			infinite: false, 
			autoPlayBehaviour: 'step',
			itemByItem: false
		});
	});
		
	// contact form
	$(".close-message").click(function(event){
		$(this).parent().parent().slideUp();
		event.preventDefault();
	});
		
	// shadowbox
	Shadowbox.init();
	
	//$("#close-message").click(function(event){$("#fehlermeldung").fadeOut(); event.preventDefault(); });
	
	// accordion (if bound to classes make sure initialization happens before cufon-init)
	// doesn't work too well with classes anyway (no defaultid) so use try to use always IDs
	$(".accordion").msAccordion({defaultid: 0, vertical: true});
    
    // noSpam
    noSpam();
});

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() == 'Vor- und Nachname' ||
				// 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;
	}
}
