/**
 * All functions for the uses flaps (not accordion)
 *
 * Dependencies: jquery-1.3.2.min.js,jquery-ui-1.7.2.core.min.js,jquery-ui-1.7.2.effects.min.js
 */

$(document).ready(function(){
	$('.flapHead').svoFlap();

	function countChecked() {
		var n5 = $("ul.c5 input:checked").length;
		if ($("input#p5_2_A_QualifizierungBereich_Text").val() != '') {
			var n5 = n5 +1;
		}
		if (n5 > 0) {
			$("span.c5").text("(" + n5 + " ausgewählt)");
		} else {
			$("span.c5").text(" ");
		}
		var n6 = $("ul.c6 input:checked").length;
		if (n6 > 0) {
			$("span.c6").text("(" + n6 + " ausgewählt)");
		} else {
			$("span.c6").text(" ");
		}
	}
	countChecked();
	$(":checkbox").click(countChecked);
	$("input#p5_2_A_QualifizierungBereich_Text").keydown(countChecked);
	$("input#p5_2_A_QualifizierungBereich_Text").blur(countChecked);

	function uncheckAll(){
		$(":checkbox").each(function() {
			$(this).attr('checked',false);
		});
	}
	$(".newSearch").click(uncheckAll);
	$("a.showSearch").click(function () {
		$('form.flapSearch').slideDown(500);
		return false;
	});


});


/**
 * Plugin for Flap functionality
 *
 * Hints: Don't put margin-top to content items, that will release in jumping contents
 */

(function($) {
	$.fn.svoFlap = function(settings) {
		var flapIsMoving = false;

		return this.each(function () {
				if($(this).hasClass('hideContent')) {
					$(this).next().addClass('displayNone'); // Hiding all invisible Elements on startup
				}
				else{
					$(this).addClass('flapHeadOpen');
				}
				
			})
			.click(function () {
				if(flapIsMoving == false) {
					flapIsMoving = true;
					$(this).toggleClass('flapHeadOpen');
					var head = $(this);
					$(this).toggleClass('hideContent').next().toggle('blind', {}, 'slow', function() {
						flapIsMoving = false;
					}); // toggle visibility
				}
				return false;
			});
	}

})(jQuery);
