﻿$(document).ready(function () {

    $(document).pngFix();

    // Make parts table scrollable if there is more than 5 rows
    $('.parts').each(function () {
        if ($(this).find('tbody tr').length > 5) {
            $(this).addClass('scrollable');
        }
    });

    // Product images large version
    $('.product .right img').mouseover(function (e) {
        $('body').append('<div id="detail"><img src="' + $(this).attr('data-zoom') + '" /></div>');
        //$('#detail').css('left',e.pageX - $('#detail').width() - 10 + 'px').css('top',e.pageY - $('#detail').height() - 10 + 'px').show();
        $(this).mousemove(function (e) {
            $('#detail').css('left', e.pageX - $('#detail').width() - 20 + 'px').css('top', e.pageY + 10 + 'px').show();
        });
        $(this).mouseout(function () {
            $('#detail').remove();
        });
    });

    // Contact form validation and storing data
    $('.submit').click(function () {
        if ($(this).parents('form').find('.mandatory').length > 0) {
            $('.mandatory').each(function () {
                if (this.value == '') {
                    $(this).addClass('error');
                }
            });
            if ($('.error').length > 0) {
                alert('Please complete all fields marked with an asterisk.');
                return false;
            }
        }
    });

    $('.mandatory').blur(function () {
        if (this.value != '') {
            $(this).removeClass('error');
        }
    });

});
