$(function (){
	var row3price = 100,
		row5price = 300,
		row6price = 500,
		row7price = 500,
		row8price = 500,
		row9price = 1000;
	
	$('tr.row2 input, tr.row10 input').keyup(function() {
		$(this).val( $(this).val().replace(/,/gi,'.') );
	});

	//formiruem spisok faktur na osnove tablic s cenami
	//$('tr.row1 select option').remove();
	//$('tr.row1 select').html('<option>Выбрать</option>');

	//$('#cdTexture tr').each(function () {
	//	var trcount = $(this).index();
	//	if ( trcount != 0 )  {
	//		var factura = $(this).find('td').eq(0).text();
	//		$('tr.row1 select option:last').after('<option>' + factura + '</option>');
	//	}
	//});	
	
	var row2 = '0', 
		row3 = '0', 
		row4 = '0', 
		row5 = '0', 
		row6 = '0', 
		row7 = '0', 
		row8 = '0', 
		row9 = '0', 
		row10 = '0';
	
	$('.calc-me').bind('click', function(){

		$('.fillme').removeClass('fillme');
		
		if ( $('tr.row2 input').val().length ) {	row2 = parseInt($('tr.row2 input').val())	}
		if ( $('tr.row3 input').val().length ) {	row3 = parseInt($('tr.row3 input').val()); 	}
													row4 = parseInt($('tr.row4 select option:selected').attr('class'));	
		if ( $('tr.row5 input').val().length ) {	row5 = parseInt($('tr.row5 input').val()); 	}
		if ( $('tr.row6 input').val().length ) {	row6 = parseInt($('tr.row6 input').val()); 	}
		if ( $('tr.row7 input').val().length ) {	row7 = parseInt($('tr.row7 input').val()); 	}
		if ( $('tr.row8 input').val().length ) {	row8 = parseInt($('tr.row8 input').val()); 	}
		if ( $('tr.row9 input').val().length ) {	row9 = parseInt($('tr.row9 input').val()); 	}
		if ( $('tr.row10 input').val().length ) {	row10 = parseInt($('tr.row10 input').val()); 	}


		var factselected = $('.row1 select').val().length;
		var factname = $('.row1 select').val();
		var r2val = $('.row2 input').val().length; 
		var r3val = $('.row3 input').val().length; 
		var r10val = $('.row3 input').val().length; 

		if ( factselected < '1' || r2val < '1' || r3val < '1' ) {			
			if ( factselected < '1' ) $('.row1 td').eq(1).addClass('fillme');
			if ( r2val < '1' ) $('.row2 td').eq(1).addClass('fillme');
			if ( r3val < '1' ) $('.row3 td').eq(1).addClass('fillme');
		} else {
			
			if ( row2 < 5 ) { var priceeq = 1; }
			if ( row2 >= 5 && row2 < 10 ) { var priceeq = 2; }
			if ( row2 >= 10 && row2 < 15 ) { var priceeq = 3; }
			if ( row2 >= 15 && row2 < 18 ) { var priceeq = 4; }
			if ( row2 >= 18 && row2 < 20 ) { var priceeq = 5; }
			if ( row2 >= 20 ) { var priceeq = 6; }

			var pricetd = $('tr.row1 select option:selected').index();
			var goodprice = $('#cdTexture').find('tr').eq(pricetd).find('td').eq(priceeq).html();

			var actualprice = (goodprice * row2) + (row3 * row3price) + (row4 * row10) + row5 * row5price + (row6 * row6price) + (row7 * row7price) + (row8 * row8price) + (row9 * row9price);
			ajax_calc(goodprice,row2,row3,row3price,row4,row10,row5,row5price,row6,row6price,row7,row7price,row8,row8price,row9,row9price,factname);
			/* row3=⢮ 㣫, row4 - ⠭ ⨢ ᪨஢筮 , row10 - ਬ, row5 - ⢮ , 
				 row6 - ⠭   , row7 - ⠭   ⮫ ९, row8 - ⠭ ⨯ ᢥ⨫쭨, row9 - ⢥⨥  ⨫ */
		}

		return false;
	});

	$('.row10').hide();
	var hp = function() {
		var row4val = $('.row4 select').val();
		if ( row4val == '1' )	$('.row10').show();
		else					$('.row10').hide();		
	};
	hp();
	$('.row4 select').change(function() {
		hp();
	});





	//RIGHT ACTION SLIDER
	if ( $('#arInner .arSlide').size() > 1 ) {
		var speed2 = 4000;
		var run2 = setInterval('rotate3()', speed2);		

		var item_width2 = $('.arSlide').outerWidth(); 
		var left_value2 = item_width2 * (-1); 		
		$('.arSlide:first').before($('.arSlide:last'));
		$('#arInner').css({'marginLeft' : left_value2});

		$('#arPrev').click(function() {           
			var left_indent2 = parseInt($('#arInner').css('marginLeft')) + item_width2;         
			$('#arInner:not(:animated)').animate({'marginLeft' : left_indent2}, 400,function(){          	
				$('.arSlide:first').before($('.arSlide:last'));
				$('#arInner').css({'marginLeft' : left_value2});		
			});
		   
			return false;			
		});
	 
		$('#arNext').click(function() {
			var left_indent2 = parseInt($('#arInner').css('marginLeft')) - item_width2;
			$('#arInner:not(:animated)').animate({'marginLeft' : left_indent2}, 400, function () {
				$('.arSlide:last').after($('.arSlide:first'));
				$('#arInner').css({'marginLeft' : left_value2});		
			});				 

			return false;		
		});        
		
		$('#actionsRight').hover(function() {
			clearInterval(run2);
			$('#arPrev, #arNext').show();
		}, function() {
			run2 = setInterval('rotate3()', speed2);
			$('#arPrev, #arNext').hide();
		}); 
	}
});	

function rotate3() {
	$('#arPrev').click();
}
