
/*
 * -------------------------------------------------------------------------
 * @file 		dom.js
 * @version 	1.0.0
 * @date 		2010-08-24 12:39:52 +0200 (Tue, 24 Aug 2010)
 * @author 		Matthias Mertiens <mail@mertiens.biz>
 * --------------------------------------------------------------------------
 * Copyright (c) 2010 mertiens. ideas for communication <http://mertiens.biz>
 * -------------------------------------------------------------------------- 
 */
 

$(function() {


	$('li', 'menu').hover(
		function() { $(this).addClass('hover'); },
		function() { $(this).removeClass('hover'); }
		);

	$('.external_link').attr('target','_blank');
						
	$('.galerie > li > a').css({ opacity: 0.7 })
			.hover(
				function() { $(this).stop().animate({ opacity: 1 }); },
				function() { $(this).stop().animate({ opacity: 0.7 }); }
				)
			.fancybox();				
					
					
						
/* 	Easy Form Validation   -------------------------------------------------------------					 */
						
						
$.fn.bindForm = function(link) {

	$(this).bind('submit', function(event) {
	 

			var submitButton = $('#submitButton');

			event.preventDefault();
	 	
 			var goSubmit = true;
			var cf = this;
	 			
	 		$('.required',cf).each(function(){
	 				
	 				
	 			var elid = $(this).attr('id');	
	 				
	 				 						 			
	 			if( $(this).val()=="" || ( $(this).attr('type')=='checkbox' && !$(this).attr('checked') ) ) {
	 				
	 				var parentP = $(this).parent('p');
	 				var errorMsg = $('<span class="errormsg">Bitte ausfüllen</span>');
	 				
	 				parentP.addClass('error').append(errorMsg);
	 					
/* 	 				$('label[for="' + elid + '"]').addClass("error"); */

/* 	 				$(this).addClass("error") */
	 				$(this).change(function() { 
/* 	 							$(this).removeClass("error").parent('p') */
								if( $(this).val()!="" || ( $(this).attr('type')=='checkbox' && $(this).attr('checked') ) )
	 							parentP.removeClass("error");
	 							errorMsg.remove();
/* 	 							$('label[for="' + elid + '"]').removeClass("error"); */
	 						});
	 				
	 				goSubmit = false;
	 					
	 				} // /if	
	 			});
	 			
	 			
	 		
	 		
	 		// Formular senden ---------------------		
	 		if( goSubmit ) {	

	 			submitButton.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">Die E-Mail wurde versendet.</p>'); $('fieldset,#hinweis',cf).not('.buttonbox').animate({ opacity: 0.2 }); $(link).unbind().click(function(){return false;}).css({ opacity: 0.3 }); };
	 			
	 			
	 			$.ajax({ 	
	 					type: 'POST',
	 					url: url, 
	 					data: formdata, 
	 					success: on_success 
	 					});
	 			}
	 				
			});

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


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