
  // Light Box Gallery

  $(document).ready(function() {
    var $lightbox = $('#lightbox');
    
    $('[data-target="#lightbox"]').on('click', function(event) {
        var $img = $(this).find('img'), 
            src = $img.attr('src'),
            alt = $img.attr('alt'),
            css = {
                'maxWidth': $(window).width() - 100,
                'maxHeight': $(window).height() - 100
            };
    
        $lightbox.find('.close').addClass('hidden');
        $lightbox.find('img').attr('src', src);
        $lightbox.find('img').attr('alt', alt);
        $lightbox.find('img').css(css);
    });
    
    $lightbox.on('shown.bs.modal', function (e) {
        var $img = $lightbox.find('img');
            
        $lightbox.find('.modal-dialog').css({'width': $img.width()});
        $lightbox.find('.close').removeClass('hidden');
    });
});


    $(document).ready(function() {
        $('#jq-review-submit').click(function(e) {       
            e.preventDefault();  
            submitReviewForm();        
        });

        $('#jq-show-login').click(function(e) {       
            e.preventDefault();        
            $('#LoginModal').modal('show');       
        });
    });
    var submitReviewForm = function(){
        var review = $('#reviewForm').find('textarea[name="review"]').prop('value');
        var rating = $('#reviewForm').find('select[name="rating"]').prop('value');
        console.log(review);
        console.log(rating);
        var error = false;
        var message = '';
        review = $.trim(review);
        rating = $.trim(rating);

        if (review == '' || review.length == 0) {
            $('#reviewForm').find('textarea[name^="review"]').addClass('error');
            message = '<small>Required field missing</small>';
            error = true;
        }
        if (rating == '' || rating.length == 0) {
            $('#reviewForm').find('select[name^="rating"]').addClass('error');
            message = '<small>Required field missing</small>';
            error = true;
        }
        if (error) {        
            $('.ncs-review-alert').html(message).show();
            return false;
        }

        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN':  "{{ csrf_token() }}"
            }
        })
        var formData = $('#reviewForm').serialize();
        $.ajax({
            type: 'POST',
            url: "{{route('review.save')}}",
            data: formData,
            dataType: 'json',
            beforeSend: function(xhr) {

            },
            success: function(data) {
                $('.ncs-review-success').html(data.response).show();
                $('textarea[name^="review"]').val('');
                $("#rating").val($("#rating option:first").val());
                $('.ncs-review-alert').html('').hide();
            },
            error: function(data) {
                console.log('Error:', data);
            }
        });
    }

