var cart_items=0;var remove_data;var cart_ready=false;var products_ready=false;var carousel=null;var initialize=true;var remove_item=null;var current_class=null;var cart_object_index=null;var cart_objects=new Array();var cart_items_array=new Array();var shopping_items_array=new Array();var unq_count=0;var current_item;var cart_item_container;var cart_total=0;$(function(){var cart_item_container=document.createElement("div");var timestamp=new Date().getTime();$(cart_item_container).load("/shop/checkout?"+timestamp+" table.productcart",function(){getCart($(cart_item_container));cart_item_container=null});$("div.carousel-vertical").append('<ul class="carousel"></ul>');if($("#maincontent").hasClass("shopping-page")){$("div.carousel-wrapper").append('<ul class="carousel"></ul>');$("#shopping-cart").append('<div id="cart-total">Total: $<span class="amount">--.--</span></div><a href="https://bourbonbarrelfoods.com/shop/checkout" id="checkout-btn" class="button"><span>Check Out</span></a><img src="/wp-content/themes/bbf/images/loading.gif" class="loading" /><span id="drag-message" style="display: none">drag items<br /> into cart</span>')}else{$("#shopping-cart").append('<div id="cart-total">Total: $<span class="amount">--.--</span></div><a href="https://bourbonbarrelfoods.com/shop/checkout" id="checkout-btn" class="button"><span>Check Out</span></a><img src="/wp-content/themes/bbf/images/loading.gif" class="loading" /><span id="drag-message" style="display: none">no items<br /> in cart</span>')}});function getCart(cart_object){cart_items_array.length=0;$("div.carousel-vertical ul.carousel").html("");$("#shopping-cart img.loading").fadeIn();for(i=0;i<$(cart_object).find("tr.product_row").size();i++){cart_items_array.push({product:$(cart_object).find("tr.product_row:eq("+i+") td.firstcol a").text(),product_page:$(cart_object).find("tr.product_row:eq("+i+") td.firstcol a.prod-link").attr("href"),thumbnail:'<img src="'+$(cart_object).find("tr.product_row:eq("+i+") td.firstcol img").attr("src")+'" alt="" />',quantity:$(cart_object).find("tr.product_row:eq("+i+") input.quantity").val(),price:($(cart_object).find("tr.product_row:eq("+i+") span.pricedisplay span.pricedisplay").text().replace(/\$/,"")/$(cart_object).find("tr.product_row:eq("+i+") input.quantity").val()).toFixed(2),class_name:"cart-item-"+$(cart_object).find("tr.product_row:eq("+i+") span.key_matchup").text(),product_key:$(cart_object).find("tr.product_row:eq("+i+") input.product_key").val(),form_action:$(cart_object).find("tr.product_row:eq("+i+") form.remove").attr("action")});$("div.carousel-vertical ul.carousel").append('<li class="'+cart_items_array[i].class_name+'"></li>');$("li."+cart_items_array[i].class_name).append('<h4 class="description"><a href="'+cart_items_array[i].product_page+'" title="View this product">'+cart_items_array[i].product+'</a></h4><h4 class="price"><span class="quantity">'+cart_items_array[i].quantity+" x</span> $"+cart_items_array[i].price+"</h4>");$("li."+cart_items_array[i].class_name).append('<span class="item-wrapper">'+cart_items_array[i].thumbnail+'<a href="'+cart_items_array[i].product_page+'" class="view tooltip" title="Click for more info">view this product</a><a href="#" class="remove" title="Remove from cart">remove from cart</a>');$("div.carousel-vertical ul.carousel li:eq("+i+")").append('<form action="'+cart_items_array[i].form_action+'" method="post" style="display:none"><input type="hidden" name="quantity" value="0" /><input type="hidden" name="key" value="'+cart_items_array[i].product_key+'" /><input type="hidden" name="wpsc_update_quantity" value="true" /></form>')}cart_ready=true;$("#shopping-cart img.loading").hide();cart_items=cart_items_array.length;if(cart_items>=3){buildCarousel()}cart_items>0?$("#drag-message").hide():$("#drag-message").show();activateCart();cart_total=0;for(i=0;i<cart_items_array.length;i++){cart_total+=cart_items_array[i].quantity*cart_items_array[i].price}$("#cart-total span.amount").text(cart_total.toFixed(2));cart_total.toFixed(2)>0?$("a#checkout-btn").show():$("a#checkout-btn").hide()}function setupProducts(){if(products_ready==false){var products_container=document.createElement("div");$(products_container).load("/shop div#products_page_container",function(){getProducts($(products_container));products_container=null});products_ready=true}}function getProducts(product_object){var i=0;$(product_object).find("div.product-wrapper").each(function(){shopping_items_array.push({product:$(this).find("h4.description a").text(),product_page:$(this).find("h4.description a").attr("href"),thumbnail:'<img src="'+$(this).find("img").attr("src")+'" alt="" />',class_name:"cart-item-"+$(this).find("input[name=product_id]").val(),price:$(this).find("h4.price span.price").text(),product_id:$(this).find("input[name=product_id]").val(),form_action:$(this).find("form").attr("action")});$("div.product-selector ul.carousel").append('<li><div class="'+shopping_items_array[i].class_name+'"><h4 class="description"><a href="'+shopping_items_array[i].product_page+'" title="View this product">'+shopping_items_array[i].product+'</a></h4><h4 class="price"><span class="quantity">0 x</span> '+shopping_items_array[i].price+'</h4><span class="item-wrapper">'+shopping_items_array[i].thumbnail+'<a href="'+shopping_items_array[i].product_page+'" class="view tooltip" title="Click for more info">view this product</a><a href="#" class="add" title="Add to cart">add to cart</a></span></div></li>');$("div.product-selector ul.carousel li:eq("+i+") div").append('<form class="product_form" enctype="multipart/form-data" action="'+shopping_items_array[i].form_action+'" method="post" name="product_'+shopping_items_array[i].product_id+'" id="product_'+shopping_items_array[i].product_id+'"><input value="add_to_cart" name="wpsc_ajax_action" type="hidden"><input value="'+shopping_items_array[i].product_id+'" name="product_id" type="hidden"></form>');for(j=0;j<cart_items_array.length;j++){if(cart_items_array[j].class_name==shopping_items_array[i].class_name){$("div.product-selector ul.carousel li:eq("+i+") a.add").addClass("clicked")}}i++});var cart_length=$("div.product-selector div.carousel-wrapper ul li").size();$(".down").bind("click",function(){return false});$(".up").bind("click",function(){return false});$(".right-btn").bind("click",function(){return false});$(".left-btn").bind("click",function(){return false});$("div.product-selector div").each(function(){cart_objects.push({class_name:$(this).attr("class"),quantity:0})});if(cart_length>3){$("div.product-selector div.carousel-wrapper").jCarouselLite({btnNext:".right-btn",btnPrev:".left-btn"})}$("div.product-selector div.carousel-wrapper").css("margin","0 auto");$("div.product-selector div .item-wrapper").each(function(){if(!$(this).find("a.add").hasClass("clicked")){$(this).draggable({zIndex:2700,revert:true,helper:"clone",appendTo:"body",start:function(event,ui){current_item=$(this).closest("div").html();current_class=$(this).closest("div").attr("class")}})}});$("#shopping-cart").droppable({accept:".item-wrapper",hoverClass:"drophover",drop:function(event,ui){current_item=current_item.replace("add to cart","remove from cart");current_item=current_item.replace("Add to cart","Remove from cart");cart_items++;$("div.product-selector div."+current_class+" .item-wrapper").draggable("option","revert",false);$("div.product-selector div."+current_class+" a.add").addClass("clicked");$("div.product-selector div."+current_class+" .item-wrapper").draggable("disable");addCartItem(current_class)}});$("div.product-selector div .item-wrapper a.add").live("click",function(){if(!$(this).hasClass("clicked")){current_class=$(this).closest("div").attr("class");addCartItem(current_class)}return false})}function activateCart(){$("#shopping-cart a.remove").click(function(e){remove_item=$(this).closest("li").attr("class");removeCartItems(remove_item);return false});setupProducts()}function buildCarousel(){$(".carousel-vertical").jCarouselLite({btnNext:".down",btnPrev:".up",vertical:true})}function addCartItem(class_name){$("#shopping-cart img.loading").show();var clicked_item=$("div.product-selector div."+class_name).html();clicked_item=clicked_item.replace("add to cart","remove from cart");clicked_item=clicked_item.replace("Add to cart","Remove from cart");cart_items++;$("div.product-selector div."+current_class+" a.add").addClass("clicked");$("div.product-selector div."+current_class+" .item-wrapper").draggable("disable");var i=$("div.product-selector div").size();$("div.product-selector div").each(function(){this.className==class_name?cart_object_index=i:"";i--});cart_objects[cart_object_index].quantity++;var add_data=$("div.product-selector div."+class_name+" form").serialize();$.ajax({type:"POST",url:"/shop",data:add_data,success:function(){if(ACTIVE_PAGE==("/shop/checkout"||"/shop")){window.location=ACTIVE_PAGE}$("div.carousel-vertical").remove();$("div.carousel-wrapper-vertical").append('<div class="carousel-vertical"><ul class="carousel"></ul></div>');unq_count++;var cart_item_container=null;cart_item_container=document.createElement("div");$(cart_item_container).load("/shop/checkout?cnt="+unq_count+"&&rnd="+String((new Date()).getTime()).replace(/\D/gi,"")+" table.productcart",function(){getCart($(cart_item_container))})}})}function removeCartItems(remove_item){$("#shopping-cart img.loading").show();$("#shopping-cart li."+remove_item).fadeTo("slow",0.5);cart_items--;$("div.product-selector div."+remove_item+" a.add").removeClass("clicked");$("div.product-selector div."+remove_item+" .item-wrapper").draggable("enable");$("div.product-selector div."+remove_item+" .item-wrapper").draggable({zIndex:2700,revert:true,helper:"clone",appendTo:"body",start:function(event,ui){current_item=$(this).closest("div").html();current_class=$(this).closest("div").attr("class");$("div.product-selector li").css("overflow","visible")},stop:function(event,ui){$("div.product-selector li").css("overflow","hidden")}});var i=$("div.product-selector div").size();$("div.product-selector div").each(function(){this.className==remove_item?cart_object_index=i:"";i--});if(cart_objects&&cart_objects[cart_object_index]){cart_objects[cart_object_index].quantity=0;$("div.product-selector ."+remove_item+" span.quantity").text(cart_objects[cart_object_index].quantity+" x")}remove_data=null;remove_data=$("li."+remove_item+":first").find("form").serialize();$.ajax({type:"POST",url:$("li."+remove_item).find("form").attr("action"),data:remove_data,success:function(){remove_data=null;var cart_item_container=null;cart_item_container=document.createElement("div");$("div.carousel-vertical").remove();$("div.carousel-wrapper-vertical").append('<div class="carousel-vertical"><ul class="carousel"></ul></div>');var timestamp=new Date().getTime();$(cart_item_container).load("/shop/checkout?"+timestamp+" table.productcart",function(){getCart($(cart_item_container));cart_item_container=null});if(ACTIVE_PAGE==("/shop/checkout"||"/shop/checkout#")){window.location=ACTIVE_PAGE}}})};
