function change_legs(price, type, word1)
{
	$('#product_price').html(price)
	$('div.colors > ul li > span.legs').html(type)
  $('div.cost > p.word1').html(word1)
}

function addToCart(product_id, btn)
{
  $(btn).attr('disabled','disabled').val('Подождите...')
  // типы ног
  var price_type = 0;
  if($("ul#legs").length) {
    price_type = $("ul#legs").find("input:checked").val()
  }

  // фурнитура и цвет ног
  var furniture = 0;
  if($("ul#furniture li.active").length) {
    furniture = $("ul#furniture").find("li.active a").attr('rel')
  }

  // цвет столешницы
  var table = 0;
  if($("ul#table li.active").length) {
    table = $("ul#table").find("li.active a").attr('rel')
  }

  // цвет обивки
  var obivka = 0;
  if($("ul#obivka li.active").length) {
    obivka = $("ul#obivka").find("li.active a").attr('rel')
  }

	$.ajax({
	  type: "GET",
	  url: $("base").attr("href") + "order/json_add_to_cart/" + product_id + "/" + price_type + "/" + furniture + "/" + table + "/" + obivka,
	  dataType: "json",
	  success: function(data, textStatus) {
			cart_full(data.count, data.cost, data.word, data.word2)
			$(btn).val('Еще?').attr('disabled','')
	  }
	});

  //json_add_to_cart($product_id, $price_type = 0, $furniture = null, $table = null, $obivka = null)
}

function selectMe(o)
{
	var ul = $(o).parent().parent();
	if($(o).parent().hasClass('active')) {
		$(o).parent().removeClass('active')
		$('div.colors > ul > li span.'+ul.attr('id')).html('не важно')
	} else {
		ul.find("li").removeClass('active')
		$(o).parent().addClass('active')
		$('div.colors > ul > li span.'+ul.attr('id')).html($(o).find('img').attr('alt'))
	}
}

function cart_full(count, cost, word, word2)
{
	$('#cart').removeClass('empty').addClass('full')
	$('div#cart p.title').css('display', 'none')
	$('div#cart p.text').css('display', 'none')
  $('#cart p.link').css('display', 'block')
  $('#cart p.big').html('В корзине '+count+' '+word+'<br /> на сумму '+cost+' '+word2).css('display', 'block')
}

function cart_empty()
{
	$('#cart').removeClass('full').addClass('empty')
	$('div#cart p.title').css('display', 'block')
	$('div#cart p.text').css('display', 'block')
	$('#cart p.link').css('display', 'none')
	$('#cart p.big').css('display', 'none')
}

function rm_product(id, o)
{
	$.ajax({
	  type: "GET",
	  url: $("base").attr("href") + "order/json_rm_from_cart/" + id,
	  dataType: "json",
	  success: function(data, textStatus) {
			$(o).parent().parent().fadeOut('slow')
			if(data.count > 0) {
				$('p.total').html('Итого ' + data.cost +' '+data.word2)
				cart_full(data.count, data.cost, data.word, data.word2)
			} else {
				cart_empty()
				$('div#cart_content').fadeOut('slow', function() {
					$(this).html('Ваша корзина пуста, потому что вы еще ничего не заказали.').fadeIn('slow')
				});
			}
	  }
	});
}

function change_cnt(id, o)
{
	var val = $(o).val()
	if(Number(val) > 0) {
		$.ajax({
			type: "GET",
			url: $("base").attr("href") + "order/json_change_cnt/" + val + "/" + id,
			dataType: "json",
			success: function(data, textStatus) {
				$(o).parent().parent().find('td.value > p').eq(0).html(data.prod.cost);
				if(data.count > 0) {
					$('p.total').html('Итого ' + data.cost +' '+data.word2)
					cart_full(data.count, data.cost, data.word, data.word2)
				} else {
					cart_empty()
				}
			}
		});
	}
}
