﻿(function($) {
    $.fn.WebShop = function() {
        var outer = this;
        $('.addtocart', this).each(function(i) {
            var productid = $(this).attr('productid');
            $(this).unbind('click').click(function(e) {
                $.mvc_getJSON($(this).attr('basket'), { productid: productid }, function(response) {
                    if (response) {
                        $('.shoppingcart').mvc_load('/sv/Product.Mvc/ShoppingCart', {});
                    }
                });
            });
        });
        $('.shoppingcart-delete', this).each(function(i) {
            var productid = $(this).attr('productid');
            $(this).unbind('click').click(function(e) {
                $.mvc_getJSON($(this).attr('trash'), { productid: productid }, function(response) {
                    if (response) {
                        $('.shoppingcart').mvc_load('/sv/Product.Mvc/ShoppingCart', {});
                    }
                });
            });
        });
        $('.shoppingcart-checkout', this).each(function(i) {
            $(this).unbind('click').click(function(e) {
                document.location = $(this).attr('checkout');
            });
        });
        return this;
    };
})(jQuery);
