WebshopAPI = {
    AddToBasket : function(iPID)
    {
        // Grab variants, if any
        var arrVariants = [];
        $("select[name=\'variant[]\']").each( function() { arrVariants.push( $(this).val() ); } );
    
        iAmount = parseInt($("input[name=amount]").val(), 10);
    
        oData = {
            action: "addToBasket",
            pid: iPID,
            amount: iAmount,
            "variants[]": arrVariants
        }
    
        // Define callback delegate
        oCallback = function()
        {
            oDialogOptions = {
                width: 400,
                modal: true,
                resizable: false,
                buttons: {
                    "Ok" : function() {
                        $(this).dialog("close");
                    }
                }
            }
            $("#ConfirmDialog").dialog(oDialogOptions);
        }
    
        // Check if we have a basket container. If we do, update it.
        oBasket = $("#Basket");
    
        if(oBasket.length > 0)
        {
            oBasket.load("/modules/webshop/ajax-handler.php", oData, oCallback);
        }
        else
        {
            $.post("/modules/webshop/ajax-handler.php", oData, oCallback);
        }
    }
}
