function credit_calculate() {
	
	
	setTimeout(function(){ 

		var price = parseInt($('#f_price').val());price = ((price)?price:0);
		var firstpay = parseInt($('#f_pay').val()); firstpay = ((firstpay)?firstpay:0);
		var amount_month = parseInt($('#f_mount option:selected').val()); amount_month = ((amount_month)?amount_month:36);
		var percente = $('#f_percent').val(); percente = ((percente)?percente:14.5);
		//var f_strah = parseInt($('#f_strah').val()); f_strah = ((f_strah)?f_strah:0);
		var credit_sum = price - firstpay;
		var credit_monthly = (credit_sum*((percente/12)/100)+(credit_sum/amount_month)*2)/2;


var credit_monthly =credit_sum* (percente/12/100/(1-1/Math.pow(1+percente/12/100,amount_month)));

		var credit_monthlyincome = credit_monthly*2.5;
		
//if($('#f_strah_ch').is(':checked')==true) {
//	credit_sum = credit_sum+f_strah;
//	$('#credit_strah').val(parseInt(credit_sum/100*f_strah));
//} else $('#credit_strah').val('');


if(price>0){
$('#credit_sum').val(Math.round(credit_sum));
$('#credit_monthly').val(Math.round(credit_monthly));
$('#credit_monthlyincome').val(Math.round(credit_monthlyincome));


$('#credit_overpay').val(Math.round(amount_month*credit_monthly-credit_sum));


	}
	}, 500);
	return false;
}
function credit(sum) {
	var form = $('credit_calc');
	form.price.value = sum;
	if(slideCredit.open == false) {
		slideCredit.slideIn();
	}
	credit_calculate.delay(500);
}

var MenuSecondClass = new Class({
	initialize: function() {
		this.items = new Array();
    this.images = new Array();
	},
	add: function(key, object) {
		if($type(object) == 'object') {
			this.items.push($merge({'id': key}, object));
		}
	}, // end function add
	build2: function(key, value) {
		var block_width = 214;
		var block_height = 204;
		var elements = $A($$('.menu_second a'));
		var items = this.items;
		elements.each(function(el){
			var cars = items.filter(function(item, index) {
				return (el.id == item.id);
			});
			var div = new Element('div', {
				'id':'carsmenu_' + el.id,
				'styles': {
					'position': 'absolute',
					'display': 'none',
					'top': 0,
					'left': 0,
					'width': (block_width*cars.length) +'px',
					'height': block_height + 'px'
					},
				'class': 'cars'
			});
			div.setOpacity(0);
			
			cars.each(function(value){
				var car = new Element('div', {
					'styles': {
						'width': block_width + 'px',
						'height': block_height + 'px',
						'float': 'left'
					},
					'class': 'item'
				});
				if($defined(value.image)) {
					car.setStyles({'background-image': 'url('+value.image+')', 'background-repeat': 'no-repeat', 'background-position': 'bottom center'});
          var image = new Image();
          image.src = value.image;
          this.images.push(image);
        }
				new Element('div', {'class':'name'}).setHTML('<span class="model">'+value.model+'</span> <span class="vers">'+value.version+'</span>').injectInside(car);
				new Element('div', {'class':'price'}).setText(value.price).injectInside(car);
				new Element('div', {'class':'navi'}).setHTML('<div class="nav"><a href="'+value.url+'price/">Комплектиция и цены</a></div><div class="nav"><a href="'+value.url+'features/" class="nav">Технические характеристики</a></div><div class="nav"><a href="'+value.url+'color/" class="nav">Цветовая гамма</a></div><div class="nav"><a href="'+value.url+'photo/" class="nav">Фотогалерея</a></div>').injectInside(car);
					
				car.injectInside(div);
			}, this);

			div.injectInside(el.getParent());
			
			el.getParent().addEvent('mouseenter', function(e){
				var coord = this.getCoordinates();
				var c_left = coord.left - block_width/2;
				div.setStyles({
					'top': coord.bottom+'px',
					'left': c_left + 'px',
					'display': ''
				});
				div.effect('opacity', {wait: true}).start('0', '0.92');
			});
			el.getParent().addEvent('mouseleave', function(e){
				div.setStyle('display','none');
				div.setOpacity(0);
			});
			
		}, this);
	} // end function build
});

