// UWEBSHOP EXAMPLE SCRIPTS

$(document).ready(function () {

    $.fn.GetJSONForCategory = function (shopAlias, CategoryId) {
        SuperSimpleWebshop.GetJSONForCategory(shopAlias, CategoryId,
      function (data) {
          alert(data.Title);
      },
      function (data) {
          alert('Error' + data.status);
      });
    };

    $.fn.GetJSONForProduct = function (shopAlias, ProductId) {
        SuperSimpleWebshop.GetJSONForProduct(shopAlias, ProductId,
      function (data) {
          alert(data.Title);
      },
      function (data) {
          alert('Error' + data.status);
      });
    };

    $.fn.GetJSONForPricing = function (shopAlias, PricingId) {
        SuperSimpleWebshop.GetJSONForPricing(shopAlias, PricingId,
      function (data) {
          alert(data.Title);
      },
      function (data) {
          alert('Error' + data.status);
      });
    };

    $.fn.AddUpdateOrderline = function (shopAlias, id, action, quantity, variants) {
        SuperSimpleWebshop.addUpdateOrderLine(shopAlias, id, action, quantity, variants,
      function (data) {
          $('#minibasket dl dd').text(data.Order.TotalAmount);
          $('#minibasket dl dd').effect("bounce", { times: 3 }, 300);
      },
      function (data) {
          alert('Error during order creation: ' + data.status);
      });
    };

    // shopdirect links
    $('.shopdirect a').click(function (event) {
        // stop href from firing
        event.preventDefault();
        var shopAlias = $('body').attr('id');
        var pricingID = $(this).attr('id');
        $.fn.AddUpdateOrderline(shopAlias, pricingID, 'add', 1, '');
        $(this).effect("pulsate", { times: 1 }, 200);
    });

    // productpage to basket links
    $('.pricingblock > form > input[type=submit]').click(function (event) {
        // stop href from firing
        event.preventDefault();
        var items = '';
        $(this).parent().find('select[name*=variant] option:selected').each(function (i) {
            if (!$(this).attr("disabled")) {
                items += $(this).val() + ',';
            }
        });
        var shopAlias = $('body').attr('id');
        var pricingID = $(this).parent().find('input[name=product]').val();
        var action = $(this).parent().find('input[name=action]').val();
        var quantity = $(this).parent().find('input[name=quantity]').val();
        var variants = items.substring(0, items.length - 1);

        $.fn.AddUpdateOrderline(shopAlias, pricingID, action, quantity, variants);
        $(this).effect("pulsate", { times: 1 }, 400);
    });

  $('.quantityselect').change(function() {
      $(this).closest('form').submit()
    });
  
  
    $('.shippingselect1').change(function() {
          $('#shippingproviderform1').submit();
    });
  
    $('.shippingselect2').change(function() {
          $('#shippingproviderform2').submit();
    });

  $('#homeProductSlider').flexslider({
    animation: "slide",
    controlNav: true,
    directionNav: true
  });
  
  $("a[rel^='prettyPhoto']").prettyPhoto({
      animation_speed: 'fast', /* fast/slow/normal */
    });
  
  $('#mybook').booklet({
    width: 752,
    height: 450,
    arrows: true,
    pageNumbers: false,
    pagePadding: 0,
  });

  // $(".newssubscribeform").validate();
 
  
});
