var moving = false;
$.mover = function () {
	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 () {
	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 () {
	var a = [".cartmiddle a","ul.menuc ul a","div.centralleft p a","div.centralrightbottom a","div.footer a","div.bread a","table.cart a",".centralleft a"];		var aone = ["div.item","div.centralright p.cl","div.centralright p.r"];		for (x in a) {			$(a[x]).each(function (i) {$(this).mouseenter(function () {					$(this).animate({opacity:"0.8"},125).animate({opacity:"1"},125);					});			});		}		for (x in aone) {			$(aone[x]).each(function (i) {$(this).find("a").eq(0).mouseenter(function () {					$(this).animate({opacity:"0.8"},125).animate({opacity:"1"},125);			});});		}		if ($("div.list")) {				$("div.proditem").each(function (q) {					$(this).find("a").eq(0).mouseenter(function () {						$(this).animate({opacity:"0.8"},125).animate({opacity:"1"},125);					});					$(this).find("a").eq(1).mouseenter(function () {						$(this).animate({opacity:"0.8"},125).animate({opacity:"1"},125);					});				});		}


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) {
		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("<>");

			$("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()[0] + (itempricewotax*q).toFixed(2)).next('td').html(td.next('td').text()[0] + (itempricewtax*q).toFixed(2));


			$("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);

			$("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()[0] + (itempricewotax*q).toFixed(2)).next('td').html(td.next('td').text()[0] + (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);}

