/* Cufon */
Cufon.replace('#navigation-main li a', {
	hover: true
});
Cufon.replace('h2', {
	textShadow: '1px 1px rgba(255, 255, 255, 1)'
});
Cufon.replace('#teaser h2', {
	textShadow: '1px 1px rgba(16, 39, 41, 1)'
});
Cufon.replace('#sidebar h3');
Cufon.replace('#sidebar h4');
Cufon.replace('#content-main 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");
	
	*/
	
	/*$("#navigation-main li").mouseenter(function(){
		if (!$(this).hasClass('dropped')) {
			$(this).addClass('hover');
		}
	}).mouseleave(function(){
		$(this).removeClass('hover');
	});
	
	$("#navigation-main li a").mouseenter(function(){
		if (!$(this).parent().hasClass('dropped')) $(this).addClass('hover');
	}).mouseleave(function(){
		$(this).removeClass('hover');
	});*/
	
	var g_speed = 500;
	$(".drop-trigger").click(function(event){
		$(".dropped > ul").slideUp(g_speed, function(){
			$(this).parent().removeClass("dropped");
			Cufon.refresh('#navigation-main li a', {
				hover: true
			});
		});
		if (!$(this).parent().hasClass("dropped")) {
			$(this).parent().toggleClass("dropped");
			$(this).next().slideDown(g_speed);
		}
		event.preventDefault();
	});
	
	// 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;
	}
}
