$().ready(function(){$('.add_to_cart').click(function(e){e.preventDefault();var link=$(this);$.getJSON(link.attr('href'),function(data){if(data.status!=0)
{var mess='';for(i in data.messages)
{mess+=data.messages[i].message;}
alert(mess);return;}
if(data.data.item)
{showPopup(data.data.item);}
if(data.data.cart)
{$('#cart-items').html(data.data.cart);}});});$('.cart_items .icon-del').click(function(e){e.preventDefault();var link=$(this);$.getJSON(link.attr('href'),function(data){if(data.status!=0)
{var mess='';for(i in data.messages)
{mess+=data.messages[i].message;}
alert(mess);return;}
if(data.data.cart)
{$('#cart-items').html(data.data.cart);}
if(data.data.total)
{$('#cart_total_sum').html(data.data.total);}
var count=link.closest('table').find('.item_row').size()-1;if(!count)
{window.location.reload();}
else
{link.closest('tr').remove();}});});});function showPopup(html)
{var popup=$('#popup');popup.find('.popup-content').html(html);popup.show();var overlay=$('#overlay');var win=$(window);win.bind('resize.overlay scroll.overlay',function(){overlay.hide().width(win.width()).height(win.height()).css({'top':win.scrollTop(),'left':win.scrollLeft()}).show();var winHeight=$.browser.opera?window.innerHeight:$(window).height();var winWidth=$.browser.opera?window.innerWidth:$(window).width();var posX=Math.round(winWidth/2)+win.scrollLeft()-Math.round(popup.width()/2);popup.css('left',posX+'px');var posY=Math.round(winHeight/2.5)+win.scrollTop()-Math.round(popup.height()/2);popup.css('top',posY+'px');}).trigger('resize.overlay');popup.find('.close_popup').bind('click',function(e){e.preventDefault();popup.hide();overlay.hide();win.unbind('resize.overlay scroll.overlay');$(this).unbind('click');});} 
