var store = function () {
    store.adjustRows();
    store.lightBox();
};

store.adjustRows = function () {
    var container = $('#products-list'),
        list = $('#products-list li'),
        columns = Math.floor(container.width() / list.width()),
        rows = [],
        row = -1,
        i = -1;

    list.each(function (index, elm) {
        var size;

        i += 1;

        if (i % columns === 0 || i === 0) {
            row += 1;
            rows[row] = {maxHeight: 0, elements: []};
        }

        size = $(elm).height();

        rows[row].maxHeight = (rows[row].maxHeight < size) ? size : rows[row].maxHeight;
        rows[row].elements.push($(elm));
    });

    $.each(rows, function (index, obj) {
        $.each(obj.elements, function (i, elm) {
            elm.height(obj.maxHeight);
        });
    });
};

store.lightBox = function () {
    $('#product-images a').fancybox();
};

$(document).ready(function () {
    store();
});
