var formStatus = "schrittEins";
var art = 'mensch';
var indi = 0;
var globalTarget = "";

$(document).ready(function(){
	
	anfrage();
	
	$('.info').hover(
	  function () { $(this).find('.infopanel').addClass("hover"); },
	  function () { $(this).find('.infopanel').removeClass("hover"); }
	);

});

function anfrage(){

	art = 'mensch';
	indi=0;
	
	if($('form#anfrageForm input[name="shooting"]').val() == 'menschenshooting') {
		$('.nurTier').fadeOut();
		art = 'mensch';
	} 
	else if($('form#anfrageForm input[name="shooting"]').val() == 'tiershooting') {
		$('.nurTier').fadeIn();
		art = 'tier';
	}
	
	
	$('form#anfrageForm input[name="shooting"]').change(function() {
		var $nextButton = $("form#anfrageForm input#nextButton");
		
		if($(this).val() == 'menschenshooting') {
			$nextButton.attr("onclick", "moveForm(\'schrittZweiMensch\')");
			$('.nurTier').fadeOut();
			art = 'mensch';
		} 
		else if($(this).val() == 'tiershooting') {
			$nextButton.attr('onclick', 'moveForm(\'schrittZweiTier\')');
			$('.nurTier').fadeIn();
			art = 'tier';
		}
			
		console.log(art);
	});
	
	if( $('form#anfrageForm input[name="paket"]').val() == 'individuell' ) {
		console.log("indi");
		indi = 1;
		if(globalTarget == ".schrittZweiMensch" || globalTarget == ".schrittZweiTier"){
			$("form#anfrageForm input#nextButton").attr('onclick', 'moveForm(\'schrittDreiIndividuell\')');
		}
	}
	else{
		indi = 0;
		if(globalTarget == ".schrittZweiMensch" || globalTarget == ".schrittZweiTier"){
				$("form#anfrageForm input#nextButton").attr('onclick', 'moveForm(\'schrittDrei\')');
			}
	}
	
	$('form#anfrageForm input[name="paket"]').change(function() {
		console.log("klick");
		if($(this).val() == 'individuell') {
			console.log("indi");
			indi = 1;
			console.log(globalTarget);
			
			if(art == "tier"){
				$('label[for="anzahl"]').html('Anzahl der Tiere');
			}
			else if(art == "mensch"){
				$('label[for="anzahl"]').html('Anzahl der Menschen');
			}
			
			if(globalTarget == ".schrittZweiMensch" || globalTarget == ".schrittZweiTier"){
				console.log("true");
				$("form#anfrageForm input#nextButton").attr('onclick', 'moveForm(\'schrittDreiIndividuell\')');
			}
		} 
		else{
			indi = 0;
			if(globalTarget == ".schrittZweiMensch" || globalTarget == ".schrittZweiTier"){
				$("form#anfrageForm input#nextButton").attr('onclick', 'moveForm(\'schrittDrei\')');
			}
		}

	});
	
	
}





function moveForm(target){
	target = "." + target;
	globalTarget = target;
	var $toHide = $("form#anfrageForm > fieldset > div:not(.keep)").not(target);
	var $nextButton = $("form#anfrageForm input#nextButton");
	var $prevButton = $("form#anfrageForm input#prevButton");
	
	$(target).show();
	$toHide.hide();
	
	console.log(target);
	
	//Schritt Eins
	if(target == ".schrittEins"){
		$(".anfrageSchritte div").removeClass("active")
		$(".anfrageSchritte div.eins").addClass("active");
		if(art == "mensch"){
			$nextButton.attr("onclick", "moveForm(\'schrittZweiMensch\')");
			$prevButton.hide();
		}
		else if(art == "tier"){
			$nextButton.attr('onclick', 'moveForm(\'schrittZweiTier\')');
			$prevButton.hide();
		}
	}	
	
	//Schritt Zwei Mensch
	else if(target == ".schrittZweiMensch"){
		$(".anfrageSchritte div").removeClass("active");
		$(".anfrageSchritte div.zwei").addClass("active");
		
		$("form#anfrageForm input#submitButton").hide();
		$nextButton = $("form#anfrageForm input#nextButton");
		$nextButton.show();
		$prevButton.show();
		
		if(indi == 0){
			$nextButton.attr('onclick', 'moveForm(\'schrittDrei\')');
		}
		else{
			$nextButton.attr('onclick', 'moveForm(\'schrittDreiIndividuell\')');
		}
		$prevButton.attr('onclick', 'moveForm(\'schrittEins\')');
	}
	
	//Schritt Zwei Tier
	else if(target == ".schrittZweiTier"){
		$(".anfrageSchritte div").removeClass("active");
		$(".anfrageSchritte div.zwei").addClass("active");
		
		$("form#anfrageForm input#submitButton").hide();
		$nextButton = $("form#anfrageForm input#nextButton");
		$nextButton.show();
		$prevButton.show();
		
		if(indi == 0){
			$nextButton.attr('onclick', 'moveForm(\'schrittDrei\')');
		}
		else{
			$nextButton.attr('onclick', 'moveForm(\'schrittDreiIndividuell\')');
		}
		$prevButton.attr('onclick', 'moveForm(\'schrittEins\')');
	}
	
	//Schritt Drei Individuell
	else if(target == ".schrittDreiIndividuell"){
		$(".anfrageSchritte div").removeClass("active");
		$(".anfrageSchritte div.zwei").addClass("active");
		$("input#submitButton").hide();
		$nextButton.attr('onclick', 'moveForm(\'schrittDrei\')');
		$nextButton.show();
		
		
		if(art == "mensch"){
			$prevButton.attr('onclick', 'moveForm(\'schrittZweiMensch\')');
		}
		else if(art == "tier"){
			$prevButton.attr('onclick', 'moveForm(\'schrittZweiTier\')');
		}
	}
	
		//Schritt Drei
	else if(target == ".schrittDrei"){
		$(".anfrageSchritte div").removeClass("active");
		$(".anfrageSchritte div.drei").addClass("active");
		
		$nextButton.hide();
		$("form#anfrageForm input#submitButton").show();
		
		
		if(indi == 0){
			if(art == "mensch"){
				$prevButton.attr('onclick', 'moveForm(\'schrittZweiMensch\')');
			}
			else if(art == "tier"){
				$prevButton.attr('onclick', 'moveForm(\'schrittZweiTier\')');
			}
		}
		else{
			$prevButton.attr('onclick', 'moveForm(\'schrittDreiIndividuell\')');
		}
	}
	
	//Schritt Vier
	else if(target == ".schrittVier"){
		$(".anfrageSchritte div").removeClass("active");
		$prevButton.hide();
		$nextButton.hide();
	}
	

}

