
function startaddcart()
{
            $("#LayoutColumn2").find(".ProductActionAdd").find("a").each(function(){
                var temp = $(this).attr("href");
                $(this).attr("href", "JavaScript:void(0);");
                var funky = "addcartoverride('" + temp + "', this)";
                $(this).attr("onclick", funky);
            });
        
              if($("#SideCartContents").length == 0)
        {
        $("#LayoutColumn3").children().eq(0).before(carthtm);
        }
}


        var carthtm = "<div style='display:; ' id='SideCartContents' class='Block Moveable Panel SideCart'><h2>Your Shopping Cart</h2><div class='BlockContent'><p>You have <strong>0</strong> item in your cart.Your sub total is <strong>$0</strong>.</p><ul class='ProductList'></ul><p style='padding-top: 10px;' class='Clear'><a class='ViewCartLink' href='http://agavesoftware.mybigcommerce.com/cart.php'>View Cart</a> | <a class='CheckoutLink' onclick='' href='https://store-a836c.mybigcommerce.com/checkout.php?tk=e0bf3ee9c909105f76319243d6c9fb5f'>Checkout</a></p><p style='padding-top: 10px;' class='Clear'></p></div></div>";
        
var fire = 0;

var foundele;


        function addcartoverride(x, y)
        {


var tes = getPosition(y.parentNode.parentNode);

$("body").append($(y).parent().parent().clone().attr("id", "nazi").addClass("flowbox").removeClass("Odd Even"));

$("#nazi").html("");
$("#nazi").css("position", "absolute");
$("#nazi").css("top", tes.y);
$("#nazi").css("left", tes.x);
$("#nazi").css("border-style", "solid");
$("#nazi").css("border-width", "2px");
$("#nazi").css("border-color", "red");
$("#nazi").css("padding", "8px");


$("body").append("<iframe id='addtocarthack' style='display:none;' src='" + x + "'></iframe>");

fire = 0;
foundele = null;

$("#SideCartContents").find(".ProductList").find("li").each(function(){

if($(y).parent().parent().find(".ProductDetails").find("strong").find("a").html() == $(this).find("a").html())
{
fire = 1;
foundele = $(this);
}

});

if(fire == 1)
{
twos(foundele, tes, x, y);
}
if(fire == 0)
{
three(tes, x, y);
}





        $("#addtocarthack").load(function (){

        
    $("#addtocarthack").remove();

});
   
         
 }



function twos(xcx, tes, x, y)
{


var ddd = xcx.find("a").clone();
var sss = xcx.find("em").clone();

xcx.find("a").remove();
xcx.find("em").remove();

var ttt = (parseInt(xcx.html().replace("x", "").trim()) + 1);

xcx.html(ttt + " x ");

xcx.append(ddd);

xcx.append(sss);

var hhh = parseFloat(xcx.find("em").html().replace("$", "").trim().replace(",", "")) + parseFloat($(y).parent().parent().find(".ProductPriceRating").find("em").html().replace("$", "").replace(",", ""));

xcx.find("em").html("$" + hhh);

 var newprice = parseFloat($(y).parent().parent().find(".ProductPriceRating").find("em").html().replace("$", "").replace(",", ""));

 var newpcount = parseFloat($("#SideCartContents").find(".BlockContent").find("p:eq(0)").find("strong:eq(0)").html());

 var newptotal = parseFloat($("#SideCartContents").find(".BlockContent").find("p:eq(0)").find("strong:eq(1)").html().replace("$", "").replace(",", ""));




   $("#SideCartContents").find(".BlockContent").find("p:eq(0)").find("strong:eq(0)").html((newpcount + 1));

  $("#SideCartContents").find(".BlockContent").find("p:eq(0)").find("strong:eq(1)").html("$" + (newptotal + newprice));


var tos = getPosition(xcx.get(0));

var his = xcx.css("height");

var wis = xcx.css("width");

  
   $('#nazi').animate({
    top: tos.y,
    left: tos.x,
    height: his,
    width: wis
  }, 500, function() {
    $('#nazi').remove();
  });

}


String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}






function three(tes, x, y)
{


 var newprice = parseFloat($(y).parent().parent().find(".ProductPriceRating").find("em").html().replace("$", "").replace(",", ""));

 var newname = $(y).parent().parent().find(".ProductDetails").find("strong").find("a").html();

 var newpcount = parseFloat($("#SideCartContents").find(".BlockContent").find("p:eq(0)").find("strong:eq(0)").html());

 var newptotal = parseFloat($("#SideCartContents").find(".BlockContent").find("p:eq(0)").find("strong:eq(1)").html().replace("$", "").replace(",", ""));

        var addproduct = "<li>1 x <a href='http://agavesoftware.mybigcommerce.com/products/Small-Flagstaff.html'>" + newname + "</a><em class='ProductPrice'>$" + newprice + "</em></li>";

if($("#SideCartContents").find(".ProductList").children().size() > 0)
{
   $("#SideCartContents").find(".ProductList").children(":last-child").after(addproduct);
}
else
{
 $("#SideCartContents").find(".ProductList").append(addproduct);
}

   $("#SideCartContents").find(".BlockContent").find("p:eq(0)").find("strong:eq(0)").html((newpcount + 1));


  $("#SideCartContents").find(".BlockContent").find("p:eq(0)").find("strong:eq(1)").html("$" + (newptotal + newprice));

 
var tos = getPosition($("#SideCartContents").find(".ProductList").children(":last-child").get(0));

var his = $("#SideCartContents").find(".ProductList").children(":last-child").css("height");

var wis = $("#SideCartContents").find(".ProductList").children(":last-child").css("width");

  
   $('#nazi').animate({
    top: tos.y,
    left: tos.x,
    height: his,
    width: wis
  }, 500, function() {
    $('#nazi').remove();
  });
}



function getPosition(e){
	var left = 0;
	var top  = 0;

	while (e.offsetParent){
		left += e.offsetLeft;
		top  += e.offsetTop;
                e = document.body;
		//e     = e.offsetParent;
	}

	left += e.offsetLeft;
	top  += e.offsetTop;


	return {x:left, y:top};
}
