$(document).ready(function(){


$.fn.bindForm = function(link) {
	/* 	Easy Form Validation   ----------------------------------------------------------------	 */
	$(this).bind('submit', function(event) {
	 

			event.preventDefault();
	 	
 			var stopSubmit = true;
			var cf = this;
	 			
	 		$('.required',cf).each(function(){
	 					
	 				
	 			var elid = $(this).attr('id');	
	 				
	 				 						 			
	 			if( $(this).val()=="" || ( $(this).attr('type')=='checkbox' && !$(this).attr('checked') ) ) {
	 					
	 				$('label[for="' + elid + '"]').addClass("error");

	 				$(this).addClass("error")
	 					   .change(function() { 
	 							$(this).removeClass("error");
	 							$('label[for="' + elid + '"]').removeClass("error");
	 						});
	 				
	 				stopSubmit = false;
	 					
	 				} // /if	
	 			});
	 			
	 			
/*
			if( stopSubmit===false ) {
	 				if( $('#errormessage').length==0) {
	 					$('<div class="errors" id="errormessage">Bitte füllen Sie alle rot markierten Felder aus!</div>')
	 						.prependTo(this).css("display","none").slideDown(100);
	 						}
	 				}	
*/
	 		
	 		
	 		// Formular senden ---------------------		
	 		if( stopSubmit ) {	

	 			$('#cfContact').replaceWith('<img id="loading" src="/resources/img/ajax-loader.gif" alt="Loading" >');

	 			var formdata = 	$(cf).serialize(),
	 				url = $(cf).attr('action'),
	 				on_success = function() { $('#loading').replaceWith('<p class="gesendet">Mail versendet.</p>'); $('fieldset,#hinweis_pflichtfeld',cf).animate({ opacity: 0.2 }); /* $.fancybox.close();  */$(link).unbind().click(function(){return false;}).css({ opacity: 0.3 }); };
	 			
	 			
	 			$.ajax({ 	
	 					type: 'POST',
	 					url: url, 
	 					data: formdata, 
	 					success: on_success 
	 					});
	 			}
	 				
			});

	return this;
} /* fct bindForm 	--------------------------------------------------------------------------------------					 */			




	$('.fancyfeedback').each(function(){
		
		var el_link = this;
			
			$(el_link).fancybox({
					'opacity': true,
					'height' : 400,
					'width' : 400,
					'transitionIn'	:	'elastic',
					'transitionOut'	:	'fade',
					'speedIn'		:	50, 
					'speedOut'		:	300, 
					'overlayColor'	:	'#333', //b77e96
					'overlayOpacity':	'0.3',
					'titleShow'		:	false,
					'hideOnContentClick' : false,
					'onComplete' : function(el_link) { 
										$('.button_return').unbind().bind('click', function() { $.fancybox.close(); } ); 
										$('form', '.ajax-box').unbind().bindForm(el_link); //('submit', function(event) { event.preventDefault(); $(this).submit(); $.fancybox.close(); } )
										//$('#vhpoem_box').append( '<div id="vhpoemhtml">' + $('.overview','#content').html() + '</div>');
										//$('#vhpoem').val( $('.overview','#content').html() );
										$.fancybox.center();
										}
		
					});
	
	});



	$('#ContactForm').bindForm(null);



 });





