﻿// Javascript Document

function productDetail() {
    var imgVal = '<img src="/images/btn_cart.gif" alt="Add To Cart" />';
    $('div.bnaAddProductToCart').html('<a href="/AddToCart.aspx?id=' + $('#ddlItems').val() + '">' + imgVal + '</a>');
    $('#ddlItems').change(function() {
        $('div.bnaAddProductToCart').html('<a href="/AddToCart.aspx?id=' + $(this).val() + '">' + imgVal + '</a>');
    });
}

$(document).ready(function () {
    //$('#navbar ul li:last').addClass('last'); //NO LONGER NEEDED
    $('ul.productCategoryList:last li:last-child').css('border-bottom', 'none');

    // If the select dropdown exists on the product detail page, run the productDetail function
    if ($('.bnaProductDropdownList').find('select').html()) {
        productDetail();
    }

    if ($('ul.authorsList').html()) {
        $('ul.authorsList li a').click(function () {
            if ($(this).attr('id') == "All") {
                $('div#authors div').css('display', 'block');
                $('ul.authorsList li a.activeItem').removeClass('activeItem');
                $(this).addClass('activeItem');
            }
            else {
                $('div#authors div:not(div#' + $(this).attr('id') + ')').css('display', 'none');
                $('div#' + $(this).attr('id')).css('display', 'block');
                $('div#' + $(this).attr('id') + ' div').css('display', 'block');
                $('ul.authorsList li a.activeItem').removeClass('activeItem');
                $(this).addClass('activeItem');
                return false;
            }
        });
    }

    if ($('ul.booksList').html()) {
        $('ul.booksList li a').click(function () {
            if ($(this).attr('id') == "All") {
                $('div#books div').css('display', 'block');
                $('ul.booksList li a.activeItem').removeClass('activeItem');
                $(this).addClass('activeItem');
            }
            else {
                $('div#books div:not(div#' + $(this).attr('id') + ')').css('display', 'none');
                $('div#' + $(this).attr('id')).css('display', 'block');
                $('div#' + $(this).attr('id') + ' div').css('display', 'block');
                $('ul.booksList li a.activeItem').removeClass('activeItem');
                $(this).addClass('activeItem');
                return false;
            }
        });
    }

    $('div.contactCategorySelector').click(function () {
        if ($(this).parent().find('ul').html()) {
            if ($(this).hasClass('categoryCatActive')) {
                $(this).removeClass('categoryCatActive');
                $(this).parent().find('ul:first').hide('fast');
                $(this).parent().parent().find('div.contactCatNumActive').removeClass('contactCatNumActive');
            }
            else {
                $(this).addClass('categoryCatActive');
                $(this).parent().find('ul:first').show('fast');
                $(this).parent().parent().find('div.contactCategoryNumber').addClass('contactCatNumActive');

            }
        }
    });

    //if subtopicTable exists, remove bottom border on last table cell
    if ($('table.subtopicTable').html()) {
        $('td.subtopicTable_2:last').css('border-bottom', 'none');
    }

    //if subTopic link divider lines are present, remove the last divider line
    if ($('.subTopicLinkDivider').html()) {
        $('.subTopicLinkDivider:last').css('display', 'none');
    }
});
