$(document).ready(function(){
$(".productblock").draggable({
opacity: 0.9,
helper: 'clone'
});
$(".grabsize").draggable({
opacity: 0.9,
helper: 'clone'
});
$(".pbimage").draggable({
opacity: 1,
helper: function() {
clone = $(this).clone().css('border', 'none');
clone = clone.css('width', '200px');
clone = clone.css('border', '1px solid #cccccc');
clone = clone.css('font-size', '12px');
clone = clone.css('font-weight', 'bold');
clone = clone.css('padding', '0');
clone = clone.css('float', 'none');
clone = clone.html('
DRAG TO CART->
');
return clone;
}
});
$("#container").css({
width: "890px",
margin: "0 auto",
border: "1px solid #ccc",
padding: "15px"
});
$("#productlisting").css({
float: "left",
width: "655px",
border: "1px solid #ccc"
});
$(".productblock").css({
width: "242px",
margin: "0px",
float: "left"
});
$(".drop").droppable({
accept: ".draggablediv",
activeClass: 'droppable-active',
tolerance: 'touch',
over: function() {
$("#shoppingcarticon").fadeTo("fast", 0.6);
},
out: function() {
$("#shoppingcarticon").fadeTo("fast", 1);
},
drop: function(ev, ui) {
addProduct(ev, ui, 0, '');
}
});
});
function removeProduct(productid) {
//if qty = 1, fade out item
if(parseFloat($("#ddcproduct"+productid).attr("qty"))==1) {
//disable link
$("#ddcproduct"+productid+" > #cell0 > a").attr('onclick', '');
//fade out & remove item entirely
$("#ddcproduct"+productid).fadeOut(500, function() {
$("#ddcproduct"+productid).remove();
});
} else {
//just decrease qty
productname = $("#ddcproduct"+productid).attr("productname");
newprodqty = parseFloat($("#ddcproduct"+productid).attr("qty"))-1;
$("#ddcproduct"+productid).attr("qty", newprodqty);
$("#ddcproduct"+productid+" > #cell2").html(newprodqty);
}
//calculate and update product qty
varcartqty = $("#cartqty").text();
newqty = parseFloat(varcartqty)-1;
//protect against going below zero.
if(newqty < 0) newqty = 0;
$("#cartqty").text(newqty);
//update session item list
$.get("/includes/ajax/updatecart.php", { sid: "", action: "removeproduct", id: productid } );
//update session qty
$.get("/includes/ajax/updatecart.php", { sid: "", action: "decreaseqty" } );
//update price
varcarttotal = $("#carttotal").text();
newtotal = parseFloat(varcarttotal)-parseFloat($("#ddcproduct"+productid).attr("price"));
newtotal = Math.round(newtotal*100)/100;
newtotal = newtotal.toFixed(2);
//protect against going below zero.
if(newtotal < 0) newtotal = 0;
$("#carttotal").text(newtotal);
$.get("/includes/ajax/updatecart.php", { sid: "", newprice: newtotal } );
}
function checkoutUpdateQty(productid, price, qty) {
$.get("/includes/ajax/updatecart.php", { sid: "", action: 'changeqty', id: productid, price: price, qty: qty }, function(data) {
//update price
newprice = price*qty;
newprice = newprice.toFixed(2);
//send to dom
$('#totalprice_'+productid).text("$"+newprice);
//update summary total
$.get("/includes/ajax/updatecart.php", { sid: "", action: 'gettotal' }, function(data) {
$('#summary_carttotal').text("$"+data);
} );
} );
}
function addProduct(ev, ui, clicked, clickparts) {
//if dragged, explode title, gather parts.
if(clicked == 0) {
prodparts = $(ui.draggable.element).attr("product").split("|");
} else {
prodparts = clickparts.split("|");
}
productid = prodparts[0];
productname = prodparts[1];
productprice = prodparts[2];
productoption = prodparts[3];
if(productoption != "Y")
{ var s = document.getElementById("size"+productid);
productoption = s.options[s.selectedIndex].value;
}
productqty = 1;
//calculate & update new cart total
varcarttotal = $("#carttotal").text();
//remove any commas
varcarttotal = varcarttotal.replace(',', '');
newtotal = parseFloat(varcarttotal)+parseFloat(productprice);
newtotal = Math.round(newtotal*100)/100;
newtotal = newtotal.toFixed(2);
$("#carttotal").text(newtotal);
$.get("/includes/ajax/updatecart.php", { sid: "", newprice: newtotal } );
//calculate and update product qty
varcartqty = $("#cartqty").text();
newqty = parseFloat(varcartqty)+1;
$("#cartqty").text(newqty);
$.get("/includes/ajax/updatecart.php", { sid: "", action: "increaseqty" } );
if($("#ddcproduct"+productid+productoption).text()!="") {
//already in list, just increase qty
newprodqty = parseFloat($("#ddcproduct"+productid+productoption).attr("qty"))+1;
$("#ddcproduct"+productid+productoption).attr("qty", newprodqty);
$("#ddcproduct"+productid+productoption+" > #cell2").html(newprodqty);
} else {
if(productoption != "Y") { //add to list with options!
$("#listitems").prepend("");
}
else { //add to list no options!
$("#listitems").prepend("");
}
}
$.get("/includes/ajax/updatecart.php", { sid: "", action: "addproduct", id: productid, option: productoption } );
$("#addhowto").css("display", "none");
$("#parentlist").css("display", "none");
$("#parentlist").fadeIn("fast");
$("#shoppingcarticon").fadeTo("fast", 1);
}
function increaseQty(product) {
prodparts = product.split("|");
productid = prodparts[0];
productprice = prodparts[1];
//calculate & update new cart total
varcarttotal = $("#carttotal").text();
//remove any commas
varcarttotal = varcarttotal.replace(',', '');
newtotal = parseFloat(varcarttotal)+parseFloat(productprice);
newtotal = Math.round(newtotal*100)/100;
newtotal = newtotal.toFixed(2);
$("#carttotal").text(newtotal);
$.get("/includes/ajax/updatecart.php", { sid: "", newprice: newtotal } );
//calculate and update product qty
varcartqty = $("#cartqty").text();
newqty = parseFloat(varcartqty)+1;
$("#cartqty").text(newqty);
$.get("/includes/ajax/updatecart.php", { sid: "", action: "increaseqty" } );
newprodqty = parseFloat($("#ddcproduct"+productid).attr("qty"))+1;
$("#ddcproduct"+productid).attr("qty", newprodqty);
$("#ddcproduct"+productid+" > #cell2").html(newprodqty);
$.get("/includes/ajax/updatecart.php", { sid: "", action: "addproduct", id: productid } );
}