var CartnumOrTotals = true;
/* set to true if not using totals on the top */
$(document).ready(function () {
       $(".proditem").each(function (j) {
               $(this).find("a.prodbutton").eq(0).click(function () {
                       var pr = $(this).parent("div.proditem").find("img").eq(0);
                       $.post('/index.php?spart&route=module/cart/callback',{product_id:$(this).next("input").eq(0).val(),quantity:'1',justone:'true',quantityonly:CartnumOrTotals},function (html) {

                               var image = $(pr).offset();
                               var cart  = $('span.cartnumm').offset();
                               var l = image.left;
                               $("div.outer").before('<img src="' + $(pr).attr('src') + '" id="temp" style="position: absolute; top: ' + image.top + 'px; left: ' + image.left + 'px;z-index:2000" />');
                               var params = {top : cart.top + 'px',left : cart.left + 'px',opacity: 0.0,width : $('span.cartnumm').width(),height : $('span.cartnumm').height()};
                               $('#temp').animate(params, 'slow',false,function () {$("#temp").remove();});
                               if (CartnumOrTotals === true) {
                                      var str = html.split("<>");
                                      var s = $('span.cartnumm').html()*1 + 1;
                                       $('span.cartnumm').html(s).next("span").html("items &#163;" + trim(str[1]));
                                       var w = 120 - $('span.cartnumm').width()*1;
                                       w = (w <= 90)?w:90;
                                       $('span.cartnumm').next('span').css("width",w+"px");
                               } else {
                                       $('span.cartnumm').html(html);
                               }
                       });
               });
       });
});
$(".centralright").ready(function () {
       $(this).find("a.add").each(function (k) {
               $(this).click(function () {
                       //var pr = $(this).parent("div").parent("td").parent("tr").parent("tbody").find("img").eq(0);
					   var pr = $(this).parent('p').parent('.specialright').parent('.special');
					   if (pr.length==0) pr = $(this).parent('div').parent('.latest');
					   if (pr.length==0) pr = $(this).parent('div').parent('.proditem');
						 if (pr.length==0) pr = $(this).parent('div').parent('.feature');
					   if (pr.length==0) { alert('An Error occured, pleae try again later'); return false }
					   var prod_id = $(this).next('input').eq(0).val();
					   if (!prod_id) prod_id = $(this).attr('id');
                       $.post('/index.php?spart&route=module/cart/callback',{product_id:prod_id,quantity:'1',justone:'true',quantityonly:CartnumOrTotals},function (html) {
                               if (CartnumOrTotals === true) {
                                       var str = html.split("<>");
									   var num = str.length - 1;
                                       var s = $('span.cartnumm').html()*1 + 1;
                                       $('span.cartnumm').html(s).next("span").html("Total &#163;" + trim(str[num]));
                                       var w = 120 - $('span.cartnumm').width()*1;
                                       w = (w <= 90)?w:90;
                                       $('span.cartnumm').next('span').css("width",w+"px");
                               } else {
                                       $('span.cartnumm').html(html);
                               }
							   var img = pr.find('img');
								$.post('/index.php?route=module/cart/updateprice', {product_id:prod_id}, function(data) {
									displayProductAddedOverlay($('#image').attr('src'), title, desc, data);
								});
                       });
               return false;
               });
       });
});
function displayProductAddedOverlay(prod_img, prod_title, description, price) {
				$("body").prepend('<div id="rvoverlay1" onclick="$(this).next(\'div\').remove();$(this).remove();"></div>' +
														'<div id="addreview"><h1 class="popupbanner">Shopping Cart Updated<span class="fr" onclick="$.close()" style="margin-right: 20px;cursor: pointer;">X</span></h1>' + 
														'<div class="addreviewinner"><div class="reviewcontent" style="width: 440px;">' + 
														'<div class="popupleft"><img class="popup_prod_img" src="'+prod_img+'" alt="'+prod_title+'" /></div>'+
														'<div class="popupright"><span class="popup_prod_title">'+prod_title+'</span><div class="popup_price">Price: '+price+'</div>												</div></div>'+
														'<div class="popup_buttons"><a class="popup_go_cart" href="index.php?route=checkout/cart"></a><a  style="float: left;" class="popup_continue" href="javascript:void(0);" onclick="$.close();"></a></div>'+
														'</div><div class="popupbottom"></div>');
			
$.close = function () {
$("div#rvoverlay1").remove();$("div#addreview").remove();
}
}
