$(document).ready(function() {
	
	//choix du forfait
	
	$("#main div.forfaits div.list p").hover(function() {
		
		$(this).siblings("p").removeClass("active");
		$(this).addClass("active");
		
	});

	$("#main div.forfaits div.list p").click(function() {
	
		$(location).attr("href", $(this).children("a.subscribe").attr("href"));
	
	});
	
	
	// à la carte : nb d'appel : + et -
	
	$("#nb_decr").click(function() {
		
		var current = parseInt($("#nb_calls").val());

		$("#nb_calls").val(current-1);
		
		checkMaxValue();
		changePrice();
		
	});
	
	$("#nb_incr").click(function() {
		
		var current = parseInt($("#nb_calls").val());

		$("#nb_calls").val(current+1);
		
		checkMaxValue();
		changePrice();
		
	});
	
	
	//calcul du prix
	
	$("#nb_calls").keyup(function() {
		
		checkMaxValue();
		changePrice();
		
		
	});
	
	function changePrice() {
		
		var newPrice = $("#nb_calls").val()*0.9;
		
		$("#lacarte_amount").text(newPrice.toFixed(2) + "€")
		
	}
	
	function checkMaxValue() {
		
		var qte = parseInt($("#nb_calls").val());
		if(qte > 200) {
			$("#nb_calls").val(200+"");
		}
		
	}
	
	changePrice();
	
	// switch bloc : nouveau compte et compte existant
	
	
	$("#block_existing_account").hide();
	
	$("p#existing_account").html("Vous avez déjà un compte <strong>3665 Forfait</strong>? <span class=\"bt\">Connectez-vous.</span>")
	
	$("p#existing_account").toggle(function() {
		
		$("p#existing_account").html("Vous n'avez pas encore de compte <strong>3665 Forfait</strong>? <span class=\"bt\">Créez un compte.</span>")
		
		$("#block_create_account").fadeOut("fast", function() {
			
			$("#block_existing_account").fadeIn("fast");
			
		});
		
	}, function() {
		
		$("p#existing_account").html("Vous avez déjà un compte <strong>3665 Forfait</strong>? <span class=\"bt\">Connectez-vous.</span>")
		
		$("#block_existing_account").fadeOut("fast", function() {
			
			$("#block_create_account").fadeIn("fast");
			
		});
		
	})
	
})
