﻿/*
 * Click event handlers for the read-more/read-less buttons in the News, Alerts, and Announcements web parts
 */

$(document).ready(function () {

    // handlers for the Alerts web part...

    // define click behavior for Read More buttons
    $('table#EventsTable tr td a.ReadMoreButton').click(function () {
        $(this).parent().parent().siblings('tr').find('div[id$="SummaryLabel"]').hide();
        $(this).parent().parent().siblings('tr').find('div[id$="BodyLabel"]').fadeIn("slow");
        $(this).siblings('a.ReadLessButton').show();
        $(this).hide();
        return false;
    });

    // define click behavior for Read Less buttons
    $('table#EventsTable tr td a.ReadLessButton').click(function () {
        $(this).parent().parent().siblings('tr').find('div[id$="BodyLabel"]').hide();
        $(this).parent().parent().siblings('tr').find('div[id$="SummaryLabel"]').fadeIn("slow");
        $(this).siblings('a.ReadMoreButton').show();
        $(this).hide();
        return false;
    });

    // hide all Read More buttons that are not needed
    $('table#EventsTable tr td div[id$="BodyLabel"]:empty').parent().parent().siblings('tr').find('a.ReadMoreButton').hide();


    // handlers for the Announcements web part...

    // define click behavior for Read More buttons
    $('table#AnnouncementsTable tbody tr td a.ReadMoreButton').click(function () {
        $(this).parent().parent().parent().find('div[id$="SummaryLabel"]').hide();
        $(this).parent().parent().parent().find('div[id$="BodyLabel"]').fadeIn("slow");
        $(this).siblings('a.ReadLessButton').show();
        $(this).hide();
        return false;
    });

    // define click behavior for Read Less buttons
    $('table#AnnouncementsTable tbody tr td a.ReadLessButton').click(function () {
        $(this).parent().parent().parent().find('div[id$="BodyLabel"]').hide();
        $(this).parent().parent().parent().find('div[id$="SummaryLabel"]').fadeIn("slow");
        $(this).siblings('a.ReadMoreButton').show();
        $(this).hide();
        return false;
    });

    // hide all Read More buttons that are not needed
    $('table#AnnouncementsTable tbody tr td div[id$="BodyLabel"]:empty').parent().parent().siblings().find('a.ReadMoreButton').hide();



    // handlers for the News web part...

    // define click behavior for Read More buttons
    $('table#NewsTable tbody tr td a.ReadMoreButton').click(function () {
        $(this).parent().parent().parent().find('div[id$="SummaryLabel"]').hide();
        $(this).parent().parent().parent().find('div[id$="BodyLabel"]').fadeIn("slow");
        $(this).siblings('a.ReadLessButton').show();
        $(this).hide();
        return false;
    });

    // define click behavior for Read Less buttons
    $('table#NewsTable tbody tr td a.ReadLessButton').click(function () {
        $(this).parent().parent().parent().find('div[id$="BodyLabel"]').hide();
        $(this).parent().parent().parent().find('div[id$="SummaryLabel"]').fadeIn("slow");
        $(this).siblings('a.ReadMoreButton').show();
        $(this).hide();
        return false;
    });

    // show all the Summary elements, and show all the ReadMore elements whose neighbor Body element is non-blank
    $('table#NewsTable tbody tr td div[id$="SummaryLabel"]').show();
    $('table#NewsTable tbody tr td div[id$="BodyLabel"]:parent').parent().parent().siblings().find('a.ReadMoreButton').show();
});

