$(document).ready(function() {
  $("label img").bind("click", function() {
    $(this).parent().click();
  });
});

/* A TARGET */
(function($) {
  $.fn.target = function() {
    return this.each(function(index, elm) {
      if (substr($(this).attr("class"), 0, 7) == 'target-') {
        $(this).attr("target", substr($(this).attr("class"), 7));
      }
    });
  }
})(jQuery);

$(document).ready(function() {
  $("a").target();

  $("img.button_order_product").bind("click", function() {
    var wp_id_tmp = $(this).attr("id").replace('order_product_', '');

    if ($(":input[type='radio'][id^='variant_']").length > 0) {
      wp_id_tmp = $(":input[type='radio'][id^='variant_']:checked").val();
    }

    var wp_id = new Array();
    var wci_amount = new Array();

    wp_id.push(wp_id_tmp);
    wci_amount.push(1);

    var list = {
      insert : true,
      wp_id: wp_id,
      wci_amount: wci_amount
    }

    insertIntoCart(list);
  });


  $("img.button_order_all_product").bind("click", function() {
    var wp_id_tmp = $(this).attr("id").replace('order_all_product_', '');

    if ($(":input[type='radio'][id^='variant_']").length > 0) {
      wp_id_tmp = $(":input[type='radio'][id^='variant_']:checked").val();
    }

    var wp_id = new Array();
    var wci_amount = new Array();

    wp_id.push(wp_id_tmp);
    wci_amount.push(1);

    $(":input[id^='ger_']:checked").each(function() {
      wp_id.push($(this).val());
      wci_amount.push(1);
    });

    var list = {
      insert : true,
      wp_id: wp_id,
      wci_amount: wci_amount
    }

    insertIntoCart(list);
  });


});

function insertIntoCart(values) {
  $.POST('/webshop/cart/', values);
}