$(document).ready(function(){
	
$(".navi_main")
     .mouseover(function(){
       $(this).fadeTo("fast", 0.75);
     })
     .mouseout(function(){
       $(this).fadeTo("fast", 1);
     }) 
   .end()

		$(".artikel_galerie").fancybox({
			'zoomSpeedIn':		300, 
			'zoomSpeedOut':		300, 
			'overlayShow':		false,
			'easingIn' :	'easeInOutCirc',
			'easingOut' :	'easeOutSine'
		}); 
		
$("#kontaktformular").submit(function(){
			
			var fehler=checkMandatories(this);

			if(!fehler){
				var inhalte = $(this).find("input, textarea").serialize();
			 	$.ajax({
			   type: "POST",
			   url: "/lib/js_functions.php",
			   async: false,
			   data: "function=sendMessage&"+inhalte,
			   success: function(data_str){
			   	 var data = eval('('+data_str+')');
			   	 if(data.hinweis != "")show_hinweis(data.hinweis);
			   	 if(data.fehler != "")show_hinweis(data.fehler);
			   	 //else $("#kontaktformular").find("input, textarea").val("");
			   	 if(!data.fehler) $("#kontaktformular").find("div input, div textarea").val("");
			   }
			 });	
	
			}
			return false;
	});
		   
});

function reload_form(){
	document.formular.update.value=2; 
	document.formular.submit();
}


function checkMandatories(formular){
		var fehler=false;
		$(formular).find(".mandatory").each(function(i){
			if($(this).attr("type")=="checkbox"){
				if($(this).attr("checked")== false && $(this).attr("disabled")==false){
					fehler=true;
					$(this).next().animate( { backgroundColor:"#ffffff", color:"black" }, { queue:true, duration:250 } );
					$(this).next().animate( { backgroundColor:"#009de0", color:"white" }, { queue:true, duration:250 } );
					$(this).next().animate( { backgroundColor:"#ffffff", color:"black" }, { queue:true, duration:250 } );
					$(this).next().animate( { backgroundColor:"#009de0", color:"white" }, { queue:true, duration:300 } );
					show_hinweis("Bitte überprüfe die Pflichtfelder.");
				} else {
					$(this).next().animate( { backgroundColor:"#ffffff", color:"black" }, { queue:true, duration:250 } );
				}
			} else {
				if($(this).val()=="" && $(this).attr("disabled")==false){
					fehler=true;
					$(this).animate( { backgroundColor:"#ffffff", color:"black" }, { queue:true, duration:250 } );
					$(this).animate( { backgroundColor:"#009de0", color:"white" }, { queue:true, duration:250 } );
					$(this).animate( { backgroundColor:"#ffffff", color:"black" }, { queue:true, duration:250 } );
					$(this).animate( { backgroundColor:"#009de0", color:"white" }, { queue:true, duration:300 } );
					show_hinweis("Bitte überprüfe die Pflichtfelder.");
				} else {
					$(this).animate( { backgroundColor:"#ffffff", color:"black" }, { queue:true, duration:500 } );
				}
			}
		});
		return fehler;
}


function show_hinweis(hinweis){
	$("#hinweis_text").html(hinweis);
	
	$(".hinweis").css("visibility","visible");
}


function hinweis_aus() {
	$(".hinweis").css("visibility","hidden");
  
}
