$(document).ready(function(){
	
	/*
	 * Formular:
	 * --> Sobald Zeichen in Input-Feld => Labels ausblenden
	 * --> onFocus oder onBlur: Fekd entsprechend des Status füllen oder leeren 
	 */
	
	/* Alle Formular-Elemente durchlaufen und Label als Default-Value anzeigen */
	$('.inhalte_kontaktform div').each(function() {
		/* INPUT Feld überprüfen */
		if( $(this).find('input').val() ) {
			$(this).find('label').hide();
		}
		
		/* TEXTAREA Feld überprfüen */
		if( $(this).find('textarea').val() ) {
			$(this).find('label').hide();
		}
		
		$(this).find('label').addClass('dynamic');
	});
	
	
	/* Formularfelder hervorheben / LABEL ausblenden*/
	$('.inhalte_kontaktform div input').focus(function() {
		$(this).addClass('highlight');
		$(this).parent().find('label').addClass('quiet_text');
		if( $(this).val() != "") {
			$(this).parent().find('label').hide();
		}
	});
	
	$('.inhalte_kontaktform div textarea').focus(function() {
		$(this).addClass('highlight');
		$(this).parent().find('label').addClass('quiet_text');
		if( $(this).val() != "") {
			$(this).parent().find('label').hide();
		}
	});
	
	
	
	/* LABEL ausblenden wenn etwas eingetippt wird */
	$('.inhalte_kontaktform div input').keyup(function() {
		if( $(this).val() != "") {
			$(this).parent().find('label').hide();
		}
	});
	
	$('.inhalte_kontaktform div textarea').keyup(function() {
		if( $(this).val() != "") {
			$(this).parent().find('label').hide();
		}
	});
	
	
	
	/* LABEL ggf. einblenden wenn Formularfeld verlassen wird */
	$('.inhalte_kontaktform div input').blur(function() {
		if( $(this).val() == "") {
			$(this).parent().find('label').show();	
		}
		
		$(this).removeClass('highlight');
		$(this).parent().find('label').removeClass('quiet_text');
	});
	
	$('.inhalte_kontaktform div textarea').blur(function() {
		if( $(this).val() == "") {
			$(this).parent().find('label').show();
		}
		
		$(this).removeClass('highlight');
		$(this).parent().find('label').removeClass('quiet_text');
	});
	
	
	
	$('.content .servicebox .inhalte .formblock label').click(function() {
		if ($(this).prev('input').is(':checked')) {
			$(this).prev('input').attr('checked', false);
		} else {
			$(this).prev('input').attr('checked', true);
		}
	});
	
	
	/*
	 *  --> Klick auf Open/Close Grafik lässt ServiceBox-Bereich sliden und Button austauschen
	 */	
	$('.servicebox h3').not('.no-toggle').click(function() {
		$(this).next('div').slideToggle(250, function() {
			$(this).closest('.servicebox').toggleClass('closed');
		}); // CLOSEST		
		
		return false;
	});
	
	
	$('.btn_objekteanzeigen a').click(function() {
		if ( $(this).parent().hasClass('active') ) {
			$(this).closest('.item').find('div.sub_icon').slideToggle(250, function() {});
			$(this).closest('.item').find('div.sub_container').slideToggle(250, function() {});
		}
		else {
			$(this).closest('.item').find('div.sub_icon').slideToggle(250, function() {});
			$(this).closest('.item').find('div.sub_container').slideToggle(250, function() {});
		}
		
		$(this).parent().toggleClass('active');
		
		return false;
	});
	
	
	$('.servicebox .formblock label').click(function() {
		if ($(this).prev('input').is(':checked')) {
			$(this).prev('input').attr('checked', false);
		} else {
			$(this).prev('input').attr('checked', true);
		}
	});
	
	/**
	 * CONTACTFORM
	 **/
	$('form#contactform').find('input[type="submit"]').replaceWith('<div class="btn right btn_senden"><a href="">Senden</a></div>');
	$('form#contactform').find('.btn_senden a').click(function(){
		$('form#contactform').submit();
		return false;
	});
	
	/**
	 * FILTERFORM;
	 **/
	$('form#filterform').find('input[type="submit"]').replaceWith('<div class="btn right btn_ergebnissefiltern"><a href="">Ergebnisse filtern</a></div>');
	$('form#filterform').find('.btn_ergebnissefiltern a').click(function(){
		$('form#filterform').submit();
		return false;
	});
});
