var my_cart={refresh_timer:false,pd_timer:false,logged_in:false,items_in_cart:0,json_url:"/cart-items/minicart",cart:false,init:function(){my_cart.refresh_timer!==false?setInterval(my_cart.update_cart_items,my_cart.refresh_timer):my_cart.update_cart_items()},update_cart_items:function(){$.ajax({type:"get",url:my_cart.json_url,dataType:"json",success:function(c){if(typeof c.count!="undefined"){my_cart.logged_in=true;my_cart.items_in_cart=c.count!=null?c.count:0}else my_cart.logged_in=false;my_cart.render_cart()}})},
render_cart:function(){if(my_cart.items_in_cart>0&&$("#checkout_link").hasClass("hidden"))$("#checkout_link").removeClass("hidden");else my_cart.items_in_cart==0&&!$("#checkout_link").hasClass("hidden")&&$("#checkout_link").addClass("hidden");if(my_cart.logged_in===false)$("#head_cart").addClass("hidden");else my_cart.items_in_cart==0?$("#items_in_cart").text("(0)"):$("#items_in_cart").text("("+my_cart.items_in_cart+")");$("#checkout_link").mouseover(function(){$("#checkout_link img").attr("src",
"/images/cart_checkout_over.png")});$("#checkout_link").mouseout(function(){$("#checkout_link img").attr("src","/images/cart_checkout.png")})},show_full_cart:function(c,d){if(typeof product_details!="undefined")my_cart.pd_timer=product_details.viewed_ts;if(typeof my_cart.cart!="object"){my_cart.cart=new messaging({base_url:"my-cart"});setTimeout(function(){my_cart.show_full_cart(c,d)},100)}else $("#popup_cartdetails tbody").size()==0?setTimeout(function(){my_cart.show_full_cart(c,d)},100):$.getJSON("/cart-items/productpage",
function(e){$("#popup_cartdetails tbody tr").remove();$.each(e.items,function(b,a){b="<tr id='item_"+a.cart_id+"'><td class='success_item' valign='top'><table cellspacing='0' cellpadding='0' border='0' width='290'><tr><td valign='top' width='55'><img src='"+a.thumb+"' alt='"+a.title+"' align='left' /></td><td valign='top' width='235'><b>"+a.eventTitle+"</b><br /><a href='"+a.titleLink+"'>"+a.title+"</a><br />Size: "+a.size+"<br />Color: "+a.color+"</td></tr></table></td><td class='success_quantity' valign='top'><b>"+
a.amount+"</b><br /><a href='#' onClick='my_cart.remove_item("+a.cart_id+")'>Remove</a></td><td class='success_subtotal' valign='top'><b>$"+a.price+"</b><div class='cart_item_timer'></div></td></tr>";$("#popup_cartdetails tbody#success_tbody").append(b);navigator.appVersion.indexOf("Mac")!=-1&&$("#item_"+a.cart_id+" td .cart_item_timer").css("font-size","11px");$("#item_"+a.cart_id+" td .cart_item_timer").countdown({until:a.timeLeft,format:"MS",layout:"Time Remaining: {m<}{mnn}:{m>}{s<}{snn}{s>}",
onExpiry:function(){$(this).text("Item Has Expired")},onTick:function(f){f[5]<1&&$(this).css("color","#dd0000")}});b=""});$("#checkout_img").css("display","inline");$("#checkout_img").unbind("click").click(function(){my_cart.cart.close();checkLogin("checkout","billing","/checkout/billing")});$(".order").css("display","block");my_cart.items_in_cart==0&&$("#checkout_img, .order").css("display","none");if(c)$("#popup_content_product_details_success p.popup_copy").html(c);else my_cart.items_in_cart==
0?$("#popup_content_product_details_success p.popup_copy").html("There are no items in your cart."):$("#popup_content_product_details_success p.popup_copy").html("&nbsp;");$("#popup_content_product_details_success").css("visibility","visible");my_cart.cart.display(null,function(){typeof d!="undefined"&&d===true&&Halo.setAjaxStatus(false);if(typeof product_details!="undefined"&&$("#pd_return_to_sale").size()==0)if(styleCount!=1){createEl($("#continue_link"),"a",{id:"pd_return_to_sale","class":"event_url",
href:"/event/"+product_details.event_id+"#product_"+product_details.item_id,rel:"Continue Shopping"},"Continue Shopping");var b=window.location.hash||false;if(b){b=b.replace(/#/g,"");var a=$("#continue_link a").attr("href");$("#continue_link a").attr("href",a+b)}}else createEl($("#continue_link"),"a",{id:"pd_return_to_sale","class":"event_url",href:"/events/all",rel:"Continue Shopping"},"Continue Shopping");else $("#pd_return_to_sale").size()==0&&createEl($("#continue_link"),"a",{id:"pd_return_to_sale",
"class":"event_url",href:"/events/all"},"Continue Shopping");my_cart.cart.resize();typeof product_details!="undefined"&&$(document).bind("cbox_closed",function(){product_details.reset_viewed()})})})},remove_item:function(c){params={cart_id:c};cartitem=$.param(params);$.ajax({url:"/cart-items/deactivate",type:"POST",data:cartitem,dataType:"json",haloHandleAjaxResponse:true,haloSuccess:function(d){if(d.code>0){var e=d.data.cart_id,b=Number($("#item_"+e+" .success_quantity b").text());if(my_cart.items_in_cart==
b){$("#item_"+e).remove();$("#popup_content_product_details_success p.popup_copy").html("There are no items in your cart.");$("#checkout_img, .order").css("display","none")}else{my_cart.items_in_cart>b&&$("#item_"+e).remove();$("#popup_content_product_details_success p.popup_copy").html(d.message)}my_cart.cart.resize();my_cart.update_cart_items()}else typeof product_details!="undefined"?product_details.set_error(d.message):$("#popup_content_product_details_success p.popup_copy").html(d.message)}});
return false}};$(function(){my_cart.init()});
