﻿$(document).ready( function() {
	var wizard=$(".wizard");
	userstep=0;
	stepImg=0;
	wizard.find("fieldset:first").show();
	steps = (wizard.find("legend").length)-1;
	//wizard.find(".wsteps").html('<p>Adım:</p><ul></ul>')
	for(i=steps;i>=0;i--) {
		wizard.find(".wsteps ul").append('<li class="step'+i+'">'+i+'</li>')
	}
	wizard.find("label").click( function() {
	    inputID = $(this).attr("for");
	    //$("p").append(" for"+clickID);
	    wizard.find("#"+inputID).attr("checked","checked");
	});
	wizard.find("a.btnStart").click( function() {
	    wizardGo("step0");
	});
	wizard.find("select").change( function() {
	    currentID = $(this).attr("id");
		current = wizard.find("fieldset:has(#"+currentID+")").attr("class");
        wizardGo(current);
	});
	wizard.find("input[type='radio']").click( function() {
	    currentID = $(this).attr("id");
	    if($(this).parent().attr("class")=="finish") current="step"+steps;
	    else current = wizard.find("fieldset:has(#"+currentID+")").attr("class");
	    wizardGo(current);
	});
	function wizardGo(current) {
		wizard.find("fieldset:visible").fadeOut("fast",function callback() {
            wizard.find("fieldset."+current).next().fadeIn("fast");    
        });
		wizard.find("ul li").removeClass("active");
		wizard.find("ul li."+current).addClass("answered");
		wizard.find("ul li."+current).prev().addClass("next");
		wizard.find("ul li."+current).prev().addClass("active");
		userstep++;
		if(userstep%4==2 || userstep%4==0) {
		    wizard.find(".wright").removeClass("wsaglik"+stepImg);
		    stepImg++;
		    if(stepImg==4) stepImg=0;
		    $("h2").append(stepImg);
		    wizard.find(".wright").addClass("wsaglik"+stepImg);
		}
		if(current=="step0") wizard.find(".wsteps").fadeIn();
		if(current=="step"+(steps)) wizard.find(".wsteps").fadeOut();
	}
	wizard.find(".wsteps ul li").click( function() {
		if($(this).hasClass("answered") || $(this).hasClass("next")) {
			$(this).siblings().removeClass("active");
			$(this).addClass("active");
			target = $(this).attr("class").split(' ');
			wizard.find(".wleft fieldset").hide();
			wizard.find(".wleft ."+target).show();
			//$("#a").append("cevaplanmıştı"+test[0]);
		}
		//else { //nothing }
	}); 



});