$(document).ready(function(){
    $('.qty').keyup(function(){
        var qty = $(this).val();
        var product = $('input[name=productname]').val();
        var variation = $('#variation option:selected').val();
        $.get("/shop/line-total/", { 'product': product, 'qty': qty, 'variation': variation }, function(data){
            if(data != "error"){
                $('.price').val('€ ' + data);
                $('.error').hide();
            } else {
                if($('.error').length == 0){
                    $('form').before('<span class="error">Out of stock</span>');
                } else {
                    $('.error').show();
                }
                $('.qty').val('1');
            }
        });
    });

    $('#country').change(function(){
        var country = $('#country option:selected').val();
        if(country != "0"){
            $.getJSON("/shop/shippingcost/", {'country': country }, function(data){
                    $('.shipping').html(data.shipping);
                    $('.total').html(data.total);
                });
        }
    });

    $('#variation').change(function(){
        $('.error').hide();
        var variation = $('#variation option:selected').val();
        var product = $('input[name=productname]').val();

        $.get("/shop/variation/", { 'product': product, 'variation': variation }, function(data){
            $('.price').val('€ ' + data);
            $('span.price').html('€ ' + data);
            $('.qty').val('1');
        });
    });

    var options = {
	    zoomWidth: 640,
	    zoomHeight: 400,
        xOffset: 10,
        yOffset: 0,
        showEffect:'show',
        hideEffect:'fadeout',
        fadeoutSpeed: 'slow',
        title :false,
        position: "right" //and MORE OPTIONS
    };
	$('.zoom').jqzoom(options);

});