function highlightCategoryLink(id) {
    $('#productcategories a').css('background', 'none');
    $('#productcategories a[name=' + id + ']').css('background', 'yellow');
}

function showCategory(id) {
    $('.productcategory').css('display', 'none');
    $('.productcategory[name=' + id + ']').css('display', 'block');
}

function highlightItemLink(id) {
    $('.productcategory a').css('background', 'none');
    $('.productcategory a[name=' + id + ']').css('background', 'yellow');
}

function selectItem(id) {
    $('#product img').attr('src', '/nutritionitemdata/image/' + id);
    $('#product a').attr('href', '/nutritionitemdata/download/' + id);
    highlightItemLink(id);
}

function productCategoryClick(e) {
    highlightCategoryLink(this.name);
    showCategory(this.name);
    selectItem($('.productcategory[name=' + this.name + '] a:first').attr('name'));
    var categoryname = $('#productcategories a[name=' + this.name + ']').html();
    $('#productcategoryheader').html(categoryname);
    e.preventDefault();
}

function productItemClick(e) {
    selectItem(this.name);
    e.preventDefault();
}

$(document).ready(function() {
    $('#productcategories a').click(productCategoryClick);
    $('.productcategory a').click(productItemClick);
    highlightCategoryLink($('#productcategories:first a:first').attr('name'));
    $('.productcategory:first').css('display', 'block');
    selectItem($('.productcategory:first a:first').attr('name'));
});


