/* Cufon
Cufon.replace('#navigation-main li a', {
	hover: true
});
Cufon.replace('#sidebar h2', {
	textShadow: '1px 1px rgba(255, 255, 255, 1)'
});
*/

$(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'
	});

	
	//$("#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: 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;
	}
}