﻿$(document).ready(function() {
    //    $('#variantcontainer .variant .bulk').animate({ height: '0px' });

    $('#variantcontainer .variant').mouseover(function() {
        var expand = $(this).find('.show-hide');
        slide(expand);
    });

    $('#variantcontainer .variant .show-hide').click(function(e) {
        e.preventDefault();
        var expand = this;
        $(expand).toggleClass('show-hide-plus')
                 .toggleClass('show-hide-minus');
        slide(expand);
    });

    $('#variantcontainer .variant input[type=text]').change(function() {
        if ($(this).val() > 0) {
            var expand = $(this).parents('#variantcontainer .variant').find('.show-hide');
            slide(expand);
        } else {
            $(this).parents('.variant').find('.bulk').animate({ height: '0px' }, 'slow');
        }
    });

    $('#expandbtn').click(function(e) {
        e.preventDefault();
        $('#variantcontainer .variant .show-hide').each(function() {
            var bulkLines = $(this).parents('div.bulk').find('.values').children().length;
            $(this).parents('div.bulk').stop().animate({ height: (bulkLines * 15) + 25 + 'px' }, 'slow');
        });
    });

    $('#collapsebtn').click(function(e) {
        e.preventDefault();
        $('#variantcontainer .variant .bulk').animate({ height: '0px' });
    });
});

function slide(expand) {
    if ($(expand).hasClass('show-hide-plus')) {
        $(expand).parents('div.bulk').stop().animate({ height: '23px' }, 'slow');
    } else {
        var bulkLines = $(expand).parents('div.bulk').find('.values').children().length;
        $(expand).parents('div.bulk').stop().animate({ height: (bulkLines * 15) + 25 + 'px' }, 'slow');
    }
}
