$(document).ready(function(){

 $(".product_make_order a span").click(function() {
	var productIDValSplitter 	= (this.id).split("_");
	var productIDVal 			= productIDValSplitter[1];

   $("#featuredProduct_" + productIDVal).stop(true,false).empty().html('добавляем в заказ').animate({ opacity: 0 }, 300).animate({ opacity: 1 }, 300);

	$.ajax({
	type: "GET",
	url: "add_prod.php",
	data: { BUYproducts_id: productIDVal, action: "buy_now_ajax", products_qty: 1},
	success: function(theResponse) {

       $(".total_sum .summ_total").stop(true,false);

	  if ($(".order_block_all").length > 0 && $(".order_footer").length < 1) {

		if( $(".order_item_" + productIDVal).length > 0){
			$(".order_item_" + productIDVal).animate({ opacity: 0 }, 500, function() {
				$(".order_item_" + productIDVal).before(theResponse).remove();
			});
			$(".order_item_" + productIDVal).animate({ opacity: 0 }, 500);
			$(".order_item_" + productIDVal).animate({ opacity: 1 }, 500);

		} else {
			$(".items_in_cart").before(theResponse);
			$(".order_item_" + productIDVal).hide();
			$(".order_item_" + productIDVal).show("slow");
		}



	    $.ajax({
	      type: "GET",
	      url: "add_prod.php",
	      data: { action: "buy_now_ajax_summ"},
	      success: function(theResponse) {

	          $(".total_sum .summ_total").stop(true,false).animate({ opacity: 0 }, 500).html(theResponse).animate({ opacity: 1 }, 500);

	      }
	    });


      } else {
            $(".order_block_all").remove();
 			$(".menu_block").after(theResponse);
			$(".order_block_all").hide();
			$(".order_block_all").show("slow");


      }

	  $("#featuredProduct_" + productIDVal).empty().html('добавить в заказ').animate({ opacity: 0 }, 300).animate({ opacity: 1 }, 300);


	}
	});



});

           $(".resetCart a span").live("click", function() {

	         $.ajax({
	           type: "GET",
	           url: "add_prod.php",
	           data: { action: "reset"},
	           success: function(theResponse) {

                     $(".order_block_all").animate({ opacity: 0 }, 500, '' ,  function(){$(".order_block_all").hide("slow", function(){$(".order_block_all").remove();});} );

	           }
	         });

          });



		 $(".order_minus a").live("click", function() {

	        var productNinusIdSplitter = (this.id).split("_");
	        var productMinusId = productNinusIdSplitter[1];


			$(".total_sum .summ_total").stop(true,false);
			$("#qnty_" + productMinusId).stop(true,false);

	         $.ajax({
	           type: "GET",
	           url: "add_prod.php",
	           data: {action: "minus_ajax", id: productMinusId},
	           success: function(theResponse) {


			if (theResponse=="no") {

                     $(".order_block_all").animate({ opacity: 0 }, 500, '' ,  function(){$(".order_block_all").hide("slow", function(){$(".order_block_all").remove();});} );

			} else {


				if(theResponse!="") {

                  $("#qnty_" + productMinusId).animate({ opacity: 0 }, 300, function() {
				    $("#qnty_" + productMinusId).html(theResponse);
			      });
			      $("#qnty_" + productMinusId).animate({ opacity: 0 }, 300);
			      $("#qnty_" + productMinusId).animate({ opacity: 1 }, 300);

	              $.ajax({
	                  type: "GET",
	                  url: "add_prod.php",
	                  data: { action: "buy_now_ajax_summ"},
	                  success: function(theResponse) {

	                   $(".total_sum .summ_total").stop().animate({ opacity: 0 }, 500).html(theResponse).animate({ opacity: 1 }, 500);

	                  }
	               });


				 $.ajax({
	                  type: "GET",
	                  url: "add_prod.php",
	                  data: { action: "buy_now_ajax_price",  id: productMinusId},
	                  success: function(theResponse) {

	                   $("#order_price_" + productMinusId).stop().animate({ opacity: 0 }, 500).html(theResponse).animate({ opacity: 1 }, 500);

	                  }
	               });



				 } else {

					$(".order_item_" + productMinusId).hide("slow", function() { $(".order_item_" + productMinusId).remove()});

				 }

			   }

	           }
	         });

          });


   $(".order_plus a").live("click", function() {

	        var productNinusIdSplitter = (this.id).split("_");
	        var productMinusId = productNinusIdSplitter[1];


			$(".total_sum .summ_total").stop(true,false);
			$("#qnty_" + productMinusId).stop(true,false);

	         $.ajax({
	           type: "GET",
	           url: "add_prod.php",
	           data: {action: "plus_ajax", id: productMinusId},
	           success: function(theResponse) {


                  $("#qnty_" + productMinusId).animate({ opacity: 0 }, 300, function() {
				    $("#qnty_" + productMinusId).html(theResponse);
			      });
			      $("#qnty_" + productMinusId).animate({ opacity: 0 }, 300);
			      $("#qnty_" + productMinusId).animate({ opacity: 1 }, 300);

	              $.ajax({
	                  type: "GET",
	                  url: "add_prod.php",
	                  data: { action: "buy_now_ajax_summ"},
	                  success: function(theResponse) {

	                   $(".total_sum .summ_total").stop().animate({ opacity: 0 }, 500).html(theResponse).animate({ opacity: 1 }, 500);

	                  }
	               });

				  $.ajax({
	                  type: "GET",
	                  url: "add_prod.php",
	                  data: { action: "buy_now_ajax_price",  id: productMinusId},
	                  success: function(theResponse) {

	                   $("#order_price_" + productMinusId).stop().animate({ opacity: 0 }, 500).html(theResponse).animate({ opacity: 1 }, 500);

	                  }
	               });





	           }
	         });

          });




});

