jQuery(".cart-preview").html("<div class=\'cart-hover-padding\'><\/div>\n<div class=\'empty-cart\'>\nOstoskorisi on tällä hetkellä tyhjä\n<\/div>\n");

function closeCartPreviewWindows(){
  jQuery('#header .quick-cart .cart-preview').delay(300).hide(0);
  jQuery('body').css("overflow-y", "");
}

jQuery(function() {
  jQuery('.cart-preview .close_shopping_cart').click(function () {
    closeCartPreviewWindows()
  })
  jQuery('#header .quick-cart .cart-preview .cart-background').click(function () {
    closeCartPreviewWindows()
  })

  jQuery('.cart-preview .cart-products-wrapper .edit_product > a.edit').click(function () {
    var id = jQuery(this).parent().attr("id");
    jQuery('#header .quick-cart .cartContent[data-id="' + id + '"]').toggle();
    if (jQuery('#header .quick-cart .cartContent[data-id="' + id + '"]').is(':visible')) {
      document.getElementsByClassName('cart-products-wrapper')[0].scrollBy(0,100);
      jQuery('.cart-preview .cart-products-wrapper .edit_product#'+ id + ' > a.edit').html("Close");
    } else {
      jQuery('.cart-preview .cart-products-wrapper .edit_product#'+ id + ' > a.edit').html("Edit");
    }
  })

  jQuery('.cart-preview .cart-checkout .summary-cart-preview .form_coupon_title').click(function () {
    var height_summary_cart = jQuery('.cart-preview .cart-checkout .summary-cart-preview').css("height");
    jQuery('.cart-preview .cart-checkout .summary-cart-preview .form_coupon').toggle();
    var new_text_coupon = jQuery('.summary-wrapper .coupon_span').text().replace(/\s/g,'');
    var height = window.document.documentElement.clientHeight;
    if (jQuery('.cart-preview .cart-checkout .summary-cart-preview .form_coupon').is(':visible')) {
      if (new_text_coupon.length > 0) {
        var new_height_summary_cart = parseInt(height_summary_cart) + 65
        var height_wrapper = height - new_height_summary_cart - 70
      } else {
        var new_height_summary_cart = parseInt(height_summary_cart) + 100
        var height_wrapper = height - new_height_summary_cart - 85
      }
      jQuery(".cart-preview .cart-checkout .summary-cart-preview").css( { height: new_height_summary_cart + "px" } );
      jQuery('.cart-preview .cart-checkout .summary-cart-preview .form_coupon_title span').html('<i class="fa fa-angle-down"></i>')
      var height_wrapper = height - new_height_summary_cart - 70
      jQuery('#header .quick-cart .cart-products-wrapper').css( { height: height_wrapper } );
    } else {
      if (new_text_coupon.length > 0) {
        var old_height_summary_cart = parseInt(height_summary_cart) - 65
        var height_wrapper = height - old_height_summary_cart - 70
      } else {
        var old_height_summary_cart = parseInt(height_summary_cart) - 100
        var height_wrapper = height - old_height_summary_cart - 85
      }
      jQuery(".cart-preview .cart-checkout .summary-cart-preview").css( { height: old_height_summary_cart + "px" } );
      jQuery('.cart-preview .cart-checkout .summary-cart-preview .form_coupon_title span').html('<i class="fa fa-angle-right"></i>')

      jQuery('#header .quick-cart .cart-products-wrapper').css( { height: height_wrapper } );
    }

  })

});