function colorboxFences(rel) {
    $(".product-gallery a[rel='" + rel + "']").colorbox({
        scale: true,
        maxHeight: '90%',
        title: function() {
            var title = $(this).attr('title'),
                hash = getModelId(title);
            if (hash[hash.length - 1] == '-') {
                hash = hash.substring(0, hash.length - 1);
            }
            
            return title + ' - <a href="/preturi#' + hash + '">Pret model</a>';
        }
    });
}

/**
 * Should transform the title attributes of colorbox links to an id
 * used on the prices page."
 * - Gard Arizona cu Pergola" => arizona
 * - Gard New York => new-york
 */
function getModelId(title) {
    if (! title.match(/^Gard /)) {
        return '';
    }
    
    title = title.replace(/^Gard /, '').match(/^([0-9]?[A-Z][a-z]*( |$))+/);
    if (! title.length) {
        return '';
    }
    
    return title[0].replace(/ /, '-').toLowerCase();
}

function sameHeight(elems) {
    var maxH = 0;
    elems.each(function() {
        var h = $(this).height();
        if (h > maxH) {
            maxH = h;
        }
    }).height(maxH);
}

function highlightModel() {
    var model = window.location.hash;
    if (model) {
        if (model.substring(0, 1) == '#') {
            model = model.substring(1);
        }
        $('.' + model).addClass('selected');
    }
}

