jQuery(document).ready(function($) {
		var FreePoints = parseInt($('#freest').children('b').html());
		var Distr = parseInt($('#distr').children('b').html());  
	
		function FreePoint(){
			var FreePoint;

			FreePoint = FreePoints;
			FreePoint -= parseInt($('#str').val());
			FreePoint -= parseInt($('#agi').val());
			FreePoint -= parseInt($('#vit').val());
			FreePoint -= parseInt($('#ene').val());
			if ($("#com").length > 0){
				FreePoint -= parseInt($('#com').val());
			}
			return FreePoint;
		}
		function LeftPoint(){
			var LeftPoint;
			LeftPoint = Distr + parseInt($('#str').val());
			LeftPoint = LeftPoint + parseInt($('#agi').val());
			LeftPoint = LeftPoint + parseInt($('#vit').val());
			LeftPoint = LeftPoint + parseInt($('#ene').val());
			if ($("#com").length > 0){
				LeftPoint = LeftPoint + parseInt($('#com').val());	
			}
			return LeftPoint;
		}
		
		var maxStats = $('#max-stats').html(maxStats);
		
		$('.raspred-stats').change(function(event) {

		if(isNaN(parseInt($('#str').val()))){$('#str').val('0');}
		if(isNaN(parseInt($('#agi').val()))){$('#agi').val('0');}
		if(isNaN(parseInt($('#vit').val()))){$('#vit').val('0');}
		if(isNaN(parseInt($('#ene').val()))){$('#ene').val('0');}
		if ($("#com").length > 0){
			if(isNaN(parseInt($('#com').val()))){$('#com').val('0');}
		}

		if($(this).val() > parseInt($('#freest').html()))
		{
			$(this).val(parseInt($('#freest').html()));
		}
		
		var addStat = parseInt($(this).parent().parent().children('.add-stat').children('.adding-stat').html());
		var ResultStats = parseInt($(this).val()) + addStat;
		//alert($(this).parent().parent().children('.add-stat').children('.adding-stat').html());
		//alert($(this).parent().children('.result-point').html());
		if((parseInt($(this).parent().children('.result-point').html()) + parseInt($(this).val())) > maxStats)
		{
			$(this).parent().children('.result-point').html(maxStats + '!');
			$(this).val(maxStats - parseInt($(this).parent().parent().children('.adding-stat').html()));
		}
		else
		{
			$(this).parent().children('.result-point').html(ResultStats);
		}
		
		$('#distr').html(LeftPoint());
		$('#freest').html(FreePoint());
		
	});
});