﻿$(function() {

    if ($('.mathAnswer').length > 0 && $('.mathAnswer').val() != "" ) {
        $('#commentArea').show();
        window.location = window.location + "#commentform";
    }

    $('.viewer input').click(function(e) { return false; });

    $('.comments input').click(function(e) {
        $('#commentArea').slideDown();
    });

    var haveCommentSubmit = $('.haveCommentSubmit');

    if (haveCommentSubmit.length == 1) {
        window.location = window.location + "#commentform";
    }

    $('.viewer span').filter(function() {
        return this.id.match(/_body/);
    }).addClass('sectionBody');

    $('.viewer span').filter(function() {
        return this.id.match(/section/) && !this.id.match(/_body/);
    }).addClass('section').each(function() {
        var section = this.id;

        $('#' + section + ' tr:first').addClass('sectionHead').each(function() {
            $(this).children('td:first').addClass('arrow');
            $(this).click(function() {
                $('#' + section + '_body').slideToggle('slow');
                $('#' + section).toggleClass('collapsed')
            });
        });

        if (!$(this).hasClass('expanded')) {
            $(this).addClass('collapsed');
        }
    });

});