var LiteCartInterface = {};

LiteCartInterface.req_interface_URL = "litecart/JSInterface.cfm";
LiteCartInterface.req_contentinterface_URL = "litecart/JScontentinterface.cfm";


LiteCartInterface.lorefkey = "";

/* ADD PRODUCT */
LiteCartInterface.AddProduct=function(productid, qty){	
	$.post(LiteCartInterface.req_interface_URL, { action: "Add", "lorefkey":LiteCartInterface.lorefkey, "productid":productid,  "qty" : qty }, LiteCartInterface.UpdateCartContent);
}

LiteCartInterface.RemoveLiteOrderItem = function(refkey){
	$.post(LiteCartInterface.req_interface_URL, { action: "Remove", "lorefkey":LiteCartInterface.lorefkey,  "refkey":refkey }, LiteCartInterface.UpdateCartContent);
}

LiteCartInterface.SetQuantity = function(refkey, value){
	$.post(LiteCartInterface.req_interface_URL, { action: "SetQuantity", "lorefkey":LiteCartInterface.lorefkey, "refkey":refkey, "value":value }, LiteCartInterface.UpdateCartContent);
}

/* FEEDBACK  */
LiteCartInterface.UpdateCartContent = function(jsonstring){

	try 
	{ 
		var  data = $.parseJSON( jsonstring );
		
		if(data.success){
		
			if(data.notificationmessage) $("#notification").html(data.notificationmessage).show().fadeOut(5000);
		
			if(data.itemcount > 1) $("#cart_itemcount").html( data.itemcount + " items");
			else if(data.itemcount == 1) $("#cart_itemcount").html( data.itemcount + " item");
			else $("#cart_itemcount").html(" No items");
			
			$("#cart_itemcount").effect("highlight", {}, 175);
			
			if($('#cartbox').hasClass("hidden") == false) LiteCartInterface.RefreshCartBox();
		}
	
	
	}catch(e){
	
	}

}



/* RefreshCartBox */
LiteCartInterface.RefreshCartBox = function(){	
	$.post(LiteCartInterface.req_contentinterface_URL, { type: "cartbox", "lorefkey":LiteCartInterface.lorefkey }, function(data){
		$("#cartbox").html(data);
	});
}

