var moving = false;
$.mover = function () {
return true;
       if (moving === false) {
       moving = true;
       var m = $(".arrivalsmiddle").css("margin-left").replace("px"," ")*1;
       if ((m == "undefined") || (m == "NaN") || (m == NaN)) {
               var n = 0;
       } else {
               var n = m;
       }

       if (n < 0) {
               n=n+137;
               $(".arrivalsmiddle").animate({marginLeft:n+"px"},250);
               $(".arrivalscr").removeClass("arrivalscroff");

               if (n==0) {
                       $(".arrivalscl").addClass("arrivalscloff");
               }
       }
       setTimeout(function () {moving = false;},500);
}
};

$.movel = function () {
return true;
       if (moving === false) {
       moving = true;
       var m = $(".arrivalsmiddle").css("margin-left").replace("px"," ")*1;
       if ((m == "undefined") || (m == "NaN") || (m == NaN)) {
               var n = 0;
       } else {
               var n = m;
       }
       if (n > -411) {
               n=n-137;
               $(".arrivalsmiddle").animate({marginLeft:n+"px"},250);
               $(".arrivalscl").removeClass("arrivalscloff");
               if (n==-411) {
                       $(".arrivalscr").addClass("arrivalscroff");
               }
       }
       setTimeout(function () {moving = false;},500);
}
};

$("div.arrivalscm").ready(function () {
       $(".arrivalscl").click(function () {
               $.mover();
       });

       $(".arrivalscr").click(function () {
               $.movel();
       });
});

$(document).ready(function () {
       $('a').focus(function() { this.blur(); });
       /*$('.sitemap ul > li > a').click(function(event) {
               event.preventDefault();
               $(this).next('ul:visible').slideUp('fast');
               $(this).next('ul:hidden').slideDown('fast');
       });*/
       $("li.shop").mouseenter(function () {
               $(this).find("a").css("background-position","right -37px");
               $(this).find("span.l").css("background-position","left -37px");
               $(this).find("span.m").css("background-position","left -37px");
       }).mouseleave(function () {
               $(this).find("a").css("background-position","right 1px");
               $(this).find("span.l").css("background-position","left 1px");
               $(this).find("span.m").css("background-position","left 1px");
       });

if ($("table.cart")) {
$("table.cart input.remove").each(function (i) {
$(this).click(function () {
       var dt = new Date();
       var k = "_" + $(this).next("input").eq(0).val();
       var thisq = $(this).parent("td").parent("tr").find("input.qty").val()*1;
       var em = $(this).parent("td").parent("tr");
       //get the price for this product as going to change the cart total for this line

       var itempricewotax = $(this).parent('td').parent('tr').find('input.pricewotax').eq(0).val()*1;
       var itempricewtax = $(this).parent('td').parent('tr').find('input.pricewtax').eq(0).val()*1;

       $.post('/index.php?spart&route=module/cart/callback',{d:dt.getTime(),remove:k,removingajax:"true"},function (data) {
			 					$.get('index.php?route=module/cart/checkquantity', function(data) {
						if(data == 0) {
							window.location.reload();
							return false;
						}
					});
               if (data !== "false") {

/*
                       if (itempricewotax !== itempricewtax) {
                                       var vatstr = $('div.vat').text();
                                       var vat = '';
                                       for (i = 1;i<= vatstr.length;i++) {
                                           vat += vatstr[i];
                                       }
                                       //vat is the vat in the system so need to remove the vat of this item!
                                       if (((vat*1 - (itempricewtax  - itempricewotax)*thisq) < 0) || ((vat*1 - (itempricewtax  - itempricewotax)*thisq) == "NaN") || ((vat*1 - (itempricewtax  - itempricewotax)*thisq) == NaN)) {
                                              $('div.vat').html(vatstr[0] + "0.00");
                                       } else {
                                               $('div.vat').html(vatstr[0] + (vat*1 - (itempricewtax  - itempricewotax)*thisq).toFixed(2));
                                       }
                       }*/

                       em.find("input.qty").removeClass("qty");
                       em.remove();
                       //$.removeElement(em);
                       var s = 0;
                       $("input.qty").each(function (u) {
                               s += $(this).val()*1;
                       });

                       $("span.cartnumm").html(s);

                       var str = data.split("<>");

                        $('span.cartnumm').next("span").html(" Total &#163;" + str[str.length-1]);

                       $("div.subtotal").html("&#163;" + str[0]);
                               if (str.length > 2) {
                               $("div.vat").html("&#163;" + str[1]);
                               $("div.totalfinal").html("&#163;" + str[2]);
                               $("div.cartmiddle span.items").html("items &#163;" + trim(str[2]));
                       } else {
                               $("div.totalfinal").html("&#163;" + str[1]);
                               $("div.vat").html("&#163;0.00");
                               $("div.cartmiddle span.items").html("items &#163;" + trim(str[1]));
                       }
                       if (CartnumOrTotals === true) {

               var w = 120 - $("span.cartnumm").width()*1;
               w = (w <= 90)?w:90;

               $("span.cartnumm").next("span").css("width",w+"px");
           }

               }
       });

       return false;
});
});

$("table.cart input.minus").each(function (i) {
$(this).click(function () {
       var q = $(this).next("input").val()*1 - 1;
       var em = $(this).parent("td").parent("tr");

       var dt = new Date();
       var thisq = $(this).parent("td").find("input.qty").val()*1;
       var pid = em.find("td").eq(0).find("input.key").val();

  //get the price for this product as going to change the cart total for this line

   var itempricewotax = ($(this).parent('td').find('input.pricewotax').eq(0).val()*1).toFixed(2);
   var itempricewtax = ($(this).parent('td').find('input.pricewtax').eq(0).val()*1).toFixed(2);

   var td = $(this).parent('td');

       $.post('/index.php?spart&route=module/cart/callback',{d:dt.getTime(),quantity:q,product_id:pid,minusq:true},function (data) {
               if (data !== "false") {

                       if (parseInt(q) == 0) {
                               em.find("input.qty").removeClass("qty");em.remove();
                       } else {
                               em.find("input.qty").val(q);
                       }
                       var str = data.split("<>");


                       var s = 0;
                       $("input.qty").each(function (u) {
                               s += $(this).val()*1;
                       });
                       $("span.cartnumm").html(s);


                       td.next('td').html(td.next('td').text().substring(0,1) + (itempricewotax*q).toFixed(2)).next('td').html(td.next('td').text().substring(0,1) + (itempricewtax*q).toFixed(2));
						
						$("span.total").html("Total &#163;" + str[(str.length-1)]);
                       $("div.subtotal").html("&#163;" + str[0]);
                       if (str.length > 2) {
                               $("div.vat").html("&#163;" + str[1]);
                               $("div.totalfinal").html("&#163;" + str[2]);
                               $("div.cartmiddle span.items").html("items &#163;" + trim(str[2]));
                       } else {
                               $("div.totalfinal").html("&#163;" + str[1]);
                               $("div.cartmiddle span.items").html("items &#163;" + trim(str[1]));
                               /* check that the VAT is not still displayed! */
                               if (itempricewotax !== itempricewtax) {
                                       if (q == 0) {
                                               var vatstr = $('div.vat').text();
                                               var vat = '';
                                               for (i = 1;i<= vatstr.length;i++) {
                                                   vat += vatstr[i];
                                               }

                                               //vat is the vat in the system so need to remove the vat of this item!
                                               $('div.vat').html(vatstr[0] + (parseFloat(vat) - parseFloat(itempricewtax*1 - itempricewotax*1)).toFixed(2));

                                     }


                              }

                       }

                       if (CartnumOrTotals === true) {

               var w = 120 - $("span.cartnumm").width()*1;
               w = (w <= 90)?w:90;

               $("span.cartnumm").next("span").css("width",w+"px");
           }           }
       });
       return false;});
});

$("table.cart input.plus").each(function (i) {
       $(this).click(function () {
               var q = $(this).prev("input").val()*1 + 1;
               var em = $(this).parent("td").parent("tr");

               var dt = new Date();
               var pid = em.find("td").eq(0).find("input.key").val();

       //get the price for this product as going to change the cart total for this line

       var itempricewotax = ($(this).parent('td').find('input.pricewotax').eq(0).val()*1).toFixed(2);
       var itempricewtax = ($(this).parent('td').find('input.pricewtax').eq(0).val()*1).toFixed(2);

       var thisq = $(this).parent("td").find("input.qty").val()*1;

       var td = $(this).parent('td');

               $.post('/index.php?spart&route=module/cart/callback',{d:dt.getTime(),product_id:pid,justone:true},function (data) {
                       if (data !== "false") {
                               var str = data.split("<>");

                               em.find("input.qty").eq(0).val(q);

                       var s = 0;
                       $("input.qty").each(function (u) {
                               s += $(this).val()*1;
                       });
                               $("span.cartnumm").html(s);
						$("span.total").html("Total &#163;" + str[(str.length-1)]);
                       $("div.subtotal").html("&#163;" + str[0]);
                               if (str.length > 2) {
                  $("div.vat").html("&#163;" + str[1]);
                                  $("div.totalfinal").html("&#163;" + str[2]);
                      $("div.cartmiddle span.items").html("items &#163;" + trim(str[2]));
                       } else {
                                  $("div.totalfinal").html("&#163;" + str[1]);
                      $("div.cartmiddle span.items").html("items &#163;" + trim(str[1]));
                               }

                       if (CartnumOrTotals === true) {

               var w = 120 - $("span.cartnumm").width()*1;
               w = (w <= 90)?w:90;

               $("span.cartnumm").next("span").css("width",w+"px");
           }
               td.next('td').html(td.next('td').text().substring(0,1) + (itempricewotax*q).toFixed(2)).next('td').html(td.next('td').text().substring(0,1) + (itempricewtax*q).toFixed(2));

                       }
               });

               return false;
});     });}});

function IsNumeric(strString) { var strValidChars = "0123456789";       var strChar;    var blnResult = true;   if (strString.length == 0) {return false;}      for (var i = 0; i < strString.length && blnResult == true; i++) {               strChar = strString.charAt(i);          if (strValidChars.indexOf(strChar) == -1) {                     blnResult = false;              }       }       return blnResult;}$.removeElement = function (em) {             em.animate({opacity:"0"},250);          setTimeout(function () {if ($("table.cart tbody tr").length >1) {em.prev("tr").find("td").each(function (i) {$(this).css("border-bottom","0px");});} em.remove();},400);                setTimeout(function () {if ($("table.cart tbody tr").length == 0) {$("table.cart tbody").append("<tr><td style='padding:5px;color:#666666' colspan='6'>No items in your cart</td><tr>");}},600);}

