$(document).ready(function(){
    jQuery.fx.off = false;
	g_speed = 300;
    /*
    // slideshow
    $('.cycles').cycle({fx: 'fade'});
	
	// carousel
	$("#carousel").infiniteCarousel({
		transitionSpeed: 2000,
		displayTime: 4000,
		imgWidth: 128,
		imgHeight: 122
	});
                        
    // bind date picker
    $('.date').datepick();
    */
    // init smoothAnchors
    //$.smoothAnchors(2000, "easeInOut", true);
	//$(".link").animate({opacity: 0.12}, 2500);
    
	
    // inputfill
    $(".inputfill").focus(function(){
        if ($(this).val() == $(this).attr("alt")) $(this).val("");
    }).blur(function(){
        if ($(this).val() == '') $(this).val($(this).attr("alt"));
    });
	
	/*
	//ajax	
	$("#ajax-content").load("aktuelle-angebote.php #aktuelle-angebote");
	
    */
    // shadowbox
    //Shadowbox.init();
	
	$(".close-message").click(function(event){
		$(this).parent().parent().fadeOut();
		event.preventDefault();
	});
    
    // noSpam
    noSpam();
	
	// direct redirect
	$("#container").animate({top: 0}, 1000, function(){
		$(this).fadeIn(2000, function(){
			current_url = window.location.href;
			if(current_url.indexOf("#") != -1){
				var url_part = current_url.split("#",2);
				$("a[href=#"+url_part[1]+"]").eq(0).click();
				//window.location.href = '#'+url_part[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) {
		if ($(form).attr("id") == 'Meinungsformular') {
			$.post("formmail/formmail.php", $(form).serialize());
			$("#dankemeldung").fadeIn();
		}
		return true;
	}
	else {
		$("#fehler-meldung").fadeIn();
		return false;
	}
}
