/* Cufon*/
Cufon.replace('h2');
Cufon.replace('h2:first-line');
Cufon.replace('h3');


$(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	
	$("#ajax-content").load("aktuelle-angebote.php #aktuelle-angebote");
	*/
	
	// contact form
	$(".close-message").click(function(event){
		$(this).parent().parent().slideUp();
		event.preventDefault();
	});
		
	// 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'
	});
	
	var flexSpeed = 300;
	$("ul.flex li").mouseenter(function(){
		$("ul.flex li").stop();
		$(this).addClass("active");
		$(this).animate({width: '300px'}, flexSpeed);
		$("p", $(this)).fadeIn();
		$("ul.flex li").each(function(){
			if (!$(this).hasClass("active")) $(this).animate({width: '165px'}, flexSpeed);
		});
	}).mouseleave(function(){
		$("ul.flex li").stop();
		$(this).removeClass("active");
		$("ul.flex li").animate({width: '191px'}, flexSpeed);
		$("p", $(this)).fadeOut();
	});
	
	//$("#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, #accordion2").msAccordion({defaultid: 100, 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;
	}
}
